CLI: add --worktree and --tmux flags for one-command isolated sessions
Open 💬 20 comments Opened Feb 26, 2026 by minghinmatthewlam
What feature would you like to see?
Add first-class CLI flags to start Codex in an isolated git worktree and optionally attach it to tmux in one command, similar to workflows many users already script manually.
Proposed flags
codex --worktree [name]codex --tmux(requires--worktree)
Proposed behavior
--worktree [name]- Creates or reuses a worktree for the session.
- If
nameis omitted, generate one automatically. - Uses a predictable default location (for example,
.codex/worktrees/<name>) with a config override for root path. - Creates/checks out a branch for the worktree if needed.
--tmux- Requires
--worktree. - Starts/attaches a tmux session bound to that worktree and launches Codex there.
- All non-custom arguments are forwarded unchanged to Codex.
Example UX
codex --worktreecodex --worktree fix-logincodex --tmux --worktree fix-logincodex --tmux --worktree fix-login "investigate failing CI"
Why this is useful
This removes repetitive shell glue and makes isolated, parallel task execution a first-class CLI workflow. Right now users commonly combine git worktree + tmux manually or via custom wrappers.
Related issues
- #8570 (Use git worktrees to achieve parallel agents)
- #3968 (Background Terminal Sessions)
- #6500 (Interactive session management)
This request is specifically about CLI flag parity for one-command startup in a new/existing worktree with optional tmux attachment.
Additional information
Happy to help test edge cases (existing branch, detached HEAD repos, repos with non-main default branches, tmux unavailable, etc.).
20 Comments
I have already implemented the codex --worktree feature in https://github.com/scharalambous3/codex
Curious to hear your thoughts - I'm open to feedback!
I also plan to implement the background terminal session soon, too
What is the progress on this?
I think this is the right umbrella issue for making git worktrees a first-class CLI workflow.
codex --worktree [name]would already remove a lot of shell glue, but I want to add one closely related pain point: moving between existing worktrees still requires leaving the current Codex session,cd-ing manually, and starting/resuming again.From a user perspective, the ideal direction is:
codex --worktree [name]I am not attached to a specific command shape (
/cwd,/worktree switch, etc.). The important part is making worktree-based isolation feel native in the CLI.Related discussions:
Is there any progress on this feature as the desktop app has already supported it?
bump
Bumping this - important differentiator for Claude Code right now for power users
Exactly! Bump
bump
How many 👍 does this need to enter dev focus?
Also, please don’t forget
.worktreeinclude-- otherwise this lands pre-half-baked. 🙂bump
It can be quite disappointing if OpenAI takes such a common feature so lightly.
bump
lets use those tokens wisely
+1. This is one of the first things I ended up scripting for Codex CLI.
For anyone who wants a shell workaround today, here’s a small zsh helper. I personally alias it as
gwt, but the long name makes the intent clearer: create or reuse a git worktree,cdinto it, then always launch Codex with the remaining args forwarded unchanged.Examples:
This only covers the worktree startup flow, not tmux/session management. Native
codex --worktree [name]would still be cleaner, especially if it standardized the worktree location and branch reuse behavior.bump!
bump
Being an experienced Claude Code TUI user, every time I try to use Codex with work trees the same way it works with
claude -w <foo>, I get frustrated, give up, and go back to Claude Code. This is basically the blocker preventing me from giving Codex a spin for any serious coding work. ChatGPT models might be good, but I can't experience any of that because of how frustrating the experience with Codex and work trees is.And, BTW, if you ever end up implementing this feature, please implement it in a way so that it creates a work tree from the current local branch without copying unstaged/uncommitted changes. Basically, each newly created work tree is supposed to be a clean slate. For some stupid reason, when I tried asking Codex GUI to create a work tree, it copied unstaged/uncommitted changes over to the work tree — that's just so weird.
Bump
Adding a concrete reference: Claude Code documents first-class CLI worktree sessions here: https://code.claude.com/docs/en/worktrees
For Codex CLI, the key UX to match is
--worktree/-w: start a session directly in an isolated worktree, allow an explicit name (--worktree <name>), and auto-generate a useful name when omitted. Codex App already supports worktree-backed sessions; the CLI is missing the equivalent one-command entrypoint.It would also help to make the starting state explicit: create a clean new branch/worktree from a clean base with no staged/unstaged changes copied over, or opt into carrying the current branch context and staged/unstaged changes when desired. Both workflows are valid, and the CLI should make that choice clear.
Let me know when support for work trees lands. Then I might resubscribe to ChatGPT/Codex and give it another chance. For now, I'm stuck with Claude and have unsubscribed from ChatGPT/Codex.
First-class
--worktreeshould probably record ownership, not only create a checkout.The useful contract is: session id, worktree path, branch name, base ref, parent project, cleanup policy, and whether the worktree is reusable or single-turn.
--tmuxcan then attach to the same owned session instead of becoming a parallel source of truth. That also gives the UI/CLI enough data to show which task owns which branch and avoid two agents mutating the same checkout accidentally.I maintain Better Agent (https://github.com/ofekron/better-agent), where isolated worktrees and parent-visible task ownership are core to supervising Claude/Codex/Gemini sessions. If useful, a star helps other coding-agent workflow builders find it.