Skip to content

/codex:transfer is broken on Windows: false "did not record an imported thread" error, and no-arg auto-detection always fails #514

Open

Description

@SUN-bef-dev

/codex:transfer is broken on Windows: false "did not record an imported thread" error, and no-arg auto-detection always fails

Summary

On Windows, /codex:transfer never works out of the box, due to two independent bugs:

  1. No-arg auto-detection always fails with Could not identify the current Claude transcript. Retry with --source <path-to-claude-jsonl>. — because Claude Code does not inject CODEX_COMPANION_TRANSCRIPT_PATH and there is no fallback.
  2. Even with --source, it reports a false failure: Codex reported that the Claude import completed, but did not record an imported thread. — even though the import succeeds and a valid record is written to ~/.codex/external_agent_session_imports.json. Users never receive their codex resume <id> line and silently accumulate one orphaned thread per attempt.

Environment

  • Plugin: codex@openai-codex v1.0.6
  • Codex CLI: codex-cli 0.144.2
  • Node: v24.15.0
  • OS: Windows 11 (x64)

Bug 1 — no-arg transcript auto-detection always fails on Windows

scripts/lib/claude-session-transfer.mjs → resolveClaudeSessionPath requires either --source or the CODEX_COMPANION_TRANSCRIPT_PATH env var, and throws otherwise:

const requestedPath = options.source || process.env[TRANSCRIPT_PATH_ENV];
if (!requestedPath) {
  throw new Error("Could not identify the current Claude transcript. Retry with --source <path-to-claude-jsonl>.");
}

In practice the env var is not set for the plugin process, so bare /codex:transfer always fails. There is no fallback to locate the current transcript.

Suggested fix

Fall back to the most-recently-modified .jsonl under ~/.claude/projects (the current session's transcript is being actively appended to, so it is the newest file):

function findLatestTranscript() {
  let projectsRoot;
  try {
    projectsRoot = fs.realpathSync(CLAUDE_PROJECTS_DIR);
  } catch {
    return null;
  }
  let best = null;
  let bestMtime = -Infinity;
  let dirents;
  try {
    dirents = fs.readdirSync(projectsRoot, { withFileTypes: true });
  } catch {
    return null;
  }
  for (const dirent of dirents) {
    if (!dirent.isDirectory()) continue;
    const dir = path.join(projectsRoot, dirent.name);
    let files;
    try {
      files = fs.readdirSync(dir);
    } catch {
      continue;
    }
    for (const file of files) {
      if (!file.endsWith(".jsonl")) continue;
      const full = path.join(dir, file);
      try {
        const stat = fs.statSync(full);
        if (stat.mtimeMs > bestMtime) {
          bestMtime = stat.mtimeMs;
          best = full;
        }
      } catch {
        // ignore unreadable entries
      }
    }
  }
  return best;
}

export function resolveClaudeSessionPath(cwd, options = {}) {
  const requestedPath = options.source || process.env[TRANSCRIPT_PATH_ENV];
  const sourcePath = requestedPath
    ? resolveUserPath(cwd, requestedPath)
    : findLatestTranscript();
  if (!sourcePath) {
    throw new Error("Could not identify the current Claude transcript. Retry with --source <path-to-claude-jsonl>.");
  }
  // …unchanged: .jsonl check, realpathSync, projects-dir containment check…
}

(A more precise variant could prefer the project dir whose name encodes cwd, but "newest transcript overall" reliably resolves to the live session.)


Bug 2 — post-import lookup never matches on Windows (false "did not record" error)

scripts/lib/codex.mjs → importedThreadIdForSource(sourcePath) looks up the record it just wrote using two equality checks that both fail on Windows:

const canonicalSource = fs.realpathSync(sourcePath);
const contentSha256 = sourceContentSha256(canonicalSource);
const match = records
  .filter(
    (record) =>
      record?.source_path === canonicalSource &&      // (a)
      record?.content_sha256 === contentSha256 &&      // (b)
      typeof record?.imported_thread_id === "string"
  )
  .at(-1);

(a) Extended-length path prefix mismatch. The ledger (written by the Codex binary) stores source_path with the Windows \\?\ prefix, but fs.realpathSync() here returns the path without it, so the strings never match:

ledger source_path : \\?\C:\Users\<user>\.claude\projects\<proj>\<id>.jsonl
realpathSync()     :     C:\Users\<user>\.claude\projects\<proj>\<id>.jsonl

(b) Live-file content-hash race. The transcript .jsonl is a live, append-only file. content_sha256 is stored at import time, but this function re-hashes the file after the import — by then the transcript has grown (the transfer turn is written to it), so the hash differs.

Either alone forces a null result → the false error, despite the thread being created and recorded.

Suggested fix

Normalize paths before comparing (strip \\?\; on Windows unify separators + case), and treat the content hash as a preference, not a hard requirement:

const records = Array.isArray(ledger?.records) ? ledger.records : [];

const normalizePath = (p) => {
  if (typeof p !== "string") return "";
  let s = p.replace(/^\\\\\?\\/, "").replace(/^\/\/\?\//, "");
  if (process.platform === "win32") s = s.replace(/\//g, "\\").toLowerCase();
  return s;
};

const target = normalizePath(canonicalSource);
const bySource = records.filter(
  (record) =>
    normalizePath(record?.source_path) === target &&
    typeof record?.imported_thread_id === "string"
);

// Transcript is live/append-only, so its hash can change between import and this
// lookup. Prefer an exact content-hash match, else the newest import.
const exact = bySource.filter((record) => record.content_sha256 === contentSha256).at(-1);
const match = exact ?? bySource.at(-1);
return match?.imported_thread_id ?? null;

Reproduction

  1. On Windows, run bare /codex:transfer from an active Claude Code session → Bug 1 ("Could not identify the current Claude transcript").
  2. Retry with --source <path-to-jsonl> → Bug 2 ("did not record an imported thread").
  3. Inspect ~/.codex/external_agent_session_imports.json: a new record with a valid imported_thread_id is present, and source_path starts with \\?\.
  4. codex resume <that id> works fine — confirming the import itself succeeded and both errors are false negatives.

Result after both fixes

Bare /codex:transfer on Windows auto-detects the current session, imports it, and prints the expected codex resume <id> line — no arguments and no false error.

Activity

  1. AndrewAvery7 commented on Aug 7, 2026

    @AndrewAvery7

    Same root cause as #513 for the false error, and your split into two independent bugs is the right call - they fail at different layers and need separate fixes.

    The false error. Both halves of your analysis hold up against a real Windows ledger, which seems worth putting on the record since it is cheap to check:

    • Every one of the 58 records in ~/.codex/external_agent_session_imports.json on this machine carries the \\?\ extended-length prefix, so the strict comparison against fs.realpathSync() output in importedThreadIdForSource() can never match.
    • The content_sha256 check is just as fragile, for exactly the reason you give: it is a snapshot of a live, append-only file. Of the 22 source transcripts still on disk here, 12 no longer hash to their recorded value.

    Either check alone is enough to return null and report failure for an import that actually succeeded.

    For anyone landing here mid-transfer: run codex resume after a "failed" run. If the thread is in the picker, nothing was lost and only the reporting is broken.

    #469 already covers both halves. It snapshots the ledger before the import and falls back to the records Codex appended during it, normalizing the path and treating the content hash as a preference rather than a hard requirement. It is open, and currently declares Fixes #417. For transparency: I opened #551 for the path half only, and have since closed it, because normalizing the path alone would still have left the hash race in place - so #469 is the one worth watching. The diagnosis holds regardless of which patch lands.

    The no-arg detection is not covered by #469. That failure happens in resolveClaudeSessionPath() in claude-session-transfer.mjs, which throws before any ledger lookup is reached, and #469 only touches codex.mjs. So this issue would not be fully resolved by that PR merging - which is a decent argument for tracking your bug 1 separately, as you suggested.

    Workaround in the meantime, if it is useful: https://github.com/AndrewAvery7/claude-codex-bridge - it detects the imported thread from Codex's state DB rather than trusting the plugin's return value.

  2. BoldFaceType commented on Aug 31, 2026

    @BoldFaceType

    Reproduced Bug 1 verbatim (plugin 1.0.6, Windows 11, Claude Code): bare /codex:transfer fails with the exact Could not identify the current Claude transcript... error.

    One additional wrinkle worth flagging for anyone working around this via --source: manually locating the transcript under ~/.claude/projects/<encoded-cwd>/<session-id>.jsonl and passing it explicitly can also get blocked by Claude Code's own Bash auto-mode permission classifier ("Blocked by classifier") when the companion script tries to read it — independent of Codex/the ledger-hash issue discussed above. So on some Claude Code configurations, the --source workaround itself needs an explicit permission grant to succeed, not just the missing env var fallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions