Codex uses apply_patch on main branch even if clear instructions are given to always use git worktree

Resolved 💬 0 comments Opened Jan 10, 2026 by gregjotau Closed Jan 10, 2026

What version of Codex is running?

0.80

What subscription do you have?

Pro

Which model were you using?

gpt-5.2

What platform is your computer?

latest macOS

What issue are you seeing?

So I have this prompt:

# Workflow 

* Never edit files in the reai folder on main branch directly unless explicitly asked for 
If using tools like apply_patch, apply them to the worktree
* Always work on a new git worktree for each new feature or bugfix. Make it in the parent folder, not cwd.
Never work on / change files on the main branch
* Always commit before stopping so that I can compare the branch to main. 
* The name should make it easy to identify the purpose of the branch, not just an issue number. 
* wt-{repo}-{issueNumberIfAny}-{shortDescription}, worktree branch can be the same as the worktree name.

I start Codex from the repo folder, but I want it to work with a git worktree.

A lot of times though, Codex decides to apply the patch to the main branch cwd.

The idea is that I start many codex'es in parallell and that they each work on their own git worktree.

Any tips to getting this working reliably?

It would ideally be built into Codex to have a mode to only work in a separate worktree to not "pollute" main for other agents.

What steps can reproduce the bug?

Give instructions to use worktree, and see it failing.

What is the expected behavior?

That the model follows simple instructions.

Additional information

_No response_

View original on GitHub ↗