codex apply ignores root --cd and can patch the wrong repository
What version of Codex CLI is running?
Current main at 1e85ca0.
What subscription do you have?
N/A — this is a local CLI dispatch bug.
Which model were you using?
N/A.
What platform is your computer?
Darwin 25.5.0 arm64.
What issue are you seeing?
The root -C/--cd option is ignored by codex apply. The downloaded task diff is applied in the process's current directory instead. If both directories are compatible Git checkouts, the command can succeed while modifying the wrong repository.
What steps can reproduce the bug?
- Start in Git repository A.
- Have a task whose diff applies cleanly to both repository A and repository B.
- Run
codex -C /path/to/repository-b apply <task-id>. - Observe that the changed files appear in repository A, while repository B remains untouched.
The call path makes the directory loss explicit:
SharedCliOptions::cwdparses the root option.- The
Subcommand::Applydispatch callsrun_apply_command(apply_cli, None)instead of forwarding that value. apply_difftreatsNoneasstd::env::current_dir()and sends that path to the patch applier.
What is the expected behavior?
codex -C /path/to/repository-b apply <task-id> should apply the diff only in repository B, matching the behavior of the root option for the other command paths.
Additional information
The lower-level apply path already accepts an explicit working directory, and test_apply_command_creates_fibonacci_file covers applying into a supplied temporary repository. A focused fix would pass interactive.shared.cwd.clone() (or its dereferenced equivalent) at the CLI dispatch boundary and add a CLI regression with two temporary repositories to prove that only the selected repository changes.
I searched open and closed issues and PRs for apply --cd, codex -C apply, apply wrong directory, and run_apply_command cwd and did not find a matching report.
Would maintainers be open to a focused PR for this fix and regression test?
1 Comment
I re-made this against
mainat2b5bdcf67547860f2e5c5a605009a70026796b2busing two temporary Git repositories.I launched the command from repository A with
-Cpointing to repository B.Before the fix, the task diff was added to repository A. This confirms that the roots working directory value is lost at the
Subcommand::Applydispatch boundary.The smallest local fix is to change:
run_apply_command(apply_cli, /*cwd*/ None)to:
run_apply_command(apply_cli, interactive.shared.cwd.clone())I also added a CLI integration test that:
codexbinary from repository A,-C,The regression test fails before the one-line correction and it passes afterward.
Local verification:
The proposed change is limited to the single line correction and the regression test. I kept it local and have not opened a pull request because external contributions are invite only.
If this approach matches the maintainers’ intended solution, would you be willing to invite a focused PR?