Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions plugins/codex/scripts/lib/claude-session-transfer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ export function resolveClaudeSessionPath(cwd, options = {}) {
}

let source;
let projects;
try {
source = fs.realpathSync(sourcePath);
projects = fs.realpathSync(CLAUDE_PROJECTS_DIR);
} catch {
throw new Error(`Claude session file not found: ${sourcePath}`);
}

let projects;
try {
projects = fs.realpathSync(CLAUDE_PROJECTS_DIR);
} catch {
throw new Error(`Claude projects directory not found: ${CLAUDE_PROJECTS_DIR}`);
}

const relative = path.relative(projects, source);
if (relative === "" || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
throw new Error(`Codex can import Claude sessions only from ${CLAUDE_PROJECTS_DIR}: ${source}`);
Expand Down
17 changes: 17 additions & 0 deletions tests/runtime.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,23 @@ test("transfer rejects sources outside the Claude projects directory", () => {
assert.match(result.stderr, /only from .*\.claude.*projects/);
});

test("transfer distinguishes a missing Claude projects directory from a missing source", () => {
const home = makeTempDir();
const repo = path.join(home, "repo");
const sourcePath = path.join(home, "session.jsonl");
fs.mkdirSync(repo, { recursive: true });
fs.writeFileSync(sourcePath, "{}\n", "utf8");

const result = run("node", [SCRIPT, "transfer", "--source", sourcePath], {
cwd: repo,
env: { ...process.env, HOME: home }
});

assert.notEqual(result.status, 0);
assert.match(result.stderr, /Claude projects directory not found:/);
assert.doesNotMatch(result.stderr, /Claude session file not found:/);
});

test("task reports the actual Codex auth error when the run is rejected", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
Expand Down