Skip to content
Merged
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
16 changes: 16 additions & 0 deletions apps/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ async function main(): Promise<number> {
return 2;
}

// -C / --cd <dir>: change the working directory before anything resolves cwd
// (Codex parity). Done here — after --help/--version short-circuit but before
// every subcommand/REPL/headless path that reads process.cwd() — so a single
// chdir covers them all. Validate eagerly so a bad path fails fast (exit 2)
// instead of surfacing as a confusing error deep in the agent.
if (args.cwd !== undefined) {
try {
process.chdir(args.cwd);
} catch (err) {
process.stderr.write(
`Cannot change to --cd directory "${args.cwd}": ${(err as Error).message}\n`,
);
return 2;
}
}

if (args.doctor) {
return doctor();
}
Expand Down
9 changes: 9 additions & 0 deletions apps/cli/src/parse-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ describe('parseArgs', () => {
expect(parseArgs(['upgrade']).upgrade).toBe(true);
});

it('-C / --cd <dir> sets working directory', () => {
expect(parseArgs(['-C', '/work/dir']).cwd).toBe('/work/dir');
expect(parseArgs(['--cd', '/another']).cwd).toBe('/another');
});
it('cwd is undefined without -C/--cd', () => {
expect(parseArgs([]).cwd).toBeUndefined();
expect(parseArgs(['--mode', 'plan']).cwd).toBeUndefined();
});

it('-p "prompt"', () => {
expect(parseArgs(['-p', 'do the thing']).prompt).toBe('do the thing');
expect(parseArgs(['--print', 'foo']).prompt).toBe('foo');
Expand Down
9 changes: 9 additions & 0 deletions apps/cli/src/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export interface ParsedArgs {
maxTurns?: number;
bare: boolean;

/** `-C` / `--cd <dir>`: chdir to this directory before running (Codex parity). */
cwd?: string;

// System prompt overrides
systemPrompt?: string;
appendSystemPrompt?: string;
Expand Down Expand Up @@ -181,6 +184,9 @@ export function parseArgs(argv: string[]): ParsedArgs {
case a === '--bare':
out.bare = true;
break;
case a === '-C' || a === '--cd':
out.cwd = next();
break;
case a === '--system-prompt':
out.systemPrompt = next();
break;
Expand Down Expand Up @@ -287,6 +293,9 @@ MODE
--permission-mode <name> Alias for --mode (Claude Code parity)
--bare No plugins / MCP / skills — just kernel + tools

WORKING DIRECTORY
-C, --cd <dir> Change to <dir> before running (default: current dir)

MODEL & EFFORT
--model <id> deepseek-chat | deepseek-reasoner
--effort <tier> low | medium | high | xhigh | max
Expand Down
Loading