Allow use of worktrees created outside codex app
Open 💬 6 comments Opened Feb 26, 2026 by sedghi
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of the Codex App are you using (From “About Codex” dialog)?
Version 26.224.1209 (697)
What subscription do you have?
ChatGPT Plus
What platform is your computer?
Darwin 24.6.0 arm64 arm
What issue are you seeing?
If I create a worktree using a standard git command and then try to open a Codex session inside it, the worktree's branch name appears in the bottom-right dropdown menu. However, when I select that branch to start working, I get an error message that says:
Failed to switch branch fatal: branch name is already used by worktree at .....
What steps can reproduce the bug?
- create a local worktree manually (not through codex)
- try to use codex against that worktree by selecting the branch name
- see an error stating:
<img width="1214" height="232" alt="Image" src="https://github.com/user-attachments/assets/83f62621-70c7-439d-9453-a22e6c3d58cf" />
What is the expected behavior?
Should be able to point the codex app to use a worktree created outside of codex
Additional information
_No response_
6 Comments
The app wasn't designed to support this, so we wouldn't consider this a bug. I'm changing this from a bug report to an enhancement request.
It appears to be a bug after all - I created a worktree using codex - yet can't switch my working branch to it with similar error.
I agree it seems to be a bug. I'll have a bunch of of threads going, one of them will be associated with a specific corktree, some how it gets disassociated in the app with that worktree and I can't get codex to move the thread back to it.
Work around is to use the git CLI to "git worktree remove .." and then go back to codex and pick the thread, then pick the branch (now a branch not worktree so codex doesn't puke any more) and tell it to run on a new worktree, converting the branch back to a worktree...
In my project, I have a script to set up the Git worktree, which copies files and creates symlinks. It used to work in Codex by using the command
codex app /path/to/the/worktree, which would add a new project to the Codex app. However, this no longer functions in the latest Codex version26.602.30954, and no project is added.UPDATE: My workaround is to avoid creating the Git worktree and let Codex handle that. I also moved the setup and cleanup scripts to the environment configuration.
Until Codex supports opening existing worktrees natively, I made a small macOS-only skill as a temporary workaround.
It discovers any worktree registered with Git and opens the selected directory as a separate Codex/ChatGPT workspace without switching branches or modifying Git state.
Skill page: codex-open-worktree
I’d appreciate feedback from anyone trying it with worktrees created outside Codex.
I traced a related gap for CLI-created sessions running in externally managed worktrees.
Today these sessions can be discovered by app-server clients (for example, through Recent), but app-server has no persisted association between a thread and a saved project's primary folder. Exact
cwdmatching cannot represent this safely: the real worktree cwd and branch must remain unchanged, and rewritingcwdwould also affect execution, workspace, sandbox, and permission semantics. There is also no supported way to attach or reattach an existing thread after creation.A narrow open-protocol option would be an experimental, advisory
projectRootHint:thread/startcan set it;thread/readandthread/listreturn it;thread/listcan filter by one or more normalized exact hints;thread/metadata/updatecan set or clear it for existing sessions;--project-root-hint;The hint would be an absolute path in the app-server host's path namespace, not a Desktop App project ID. That keeps the contract useful to other app-server clients and avoids coupling the open protocol to a private project registry.
This would not make the Desktop App open arbitrary external worktrees by itself. It would provide the missing session-association layer that an App consumer could map to its saved Local Projects.
I have a locally validated prototype of this shape, including new/existing-session coverage, persistence and reconciliation tests, schema updates, and documentation. I have not opened a PR because the repository accepts external code contributions by invitation only.
Would this API direction align with the intended solution for external worktrees? If so, would a maintainer be open to inviting a focused PR?