Support reusable existing worktrees as project-level workspaces, decoupled from session lifecycle
Title: Support reusable existing worktrees as project-level workspaces, decoupled from session lifecycle
I’d like to suggest a workflow improvement around Codex sessions and git worktrees.
Background
This is especially important for users who keep long-lived frontend/backend worktrees with dependencies, local environment state, and code indexes already prepared.
Codex already has the ability to create a new worktree for a session. That’s useful.
However, in long-running real projects, a worktree is often more than a temporary task folder. It becomes a reusable development workspace with:
- installed dependencies
- built local environment state
- code indexes such as CodeGraph
- IDE/tool caches
- stable frontend/backend setup for a specific development lane
Examples:
- a long-lived frontend worktree
- a long-lived backend worktree
- a long-lived module/special-topic worktree
Current problem
Today, session lifecycle and worktree lifecycle feel too tightly coupled.
There are two related issues:
1. A new session cannot cleanly bind to an already existing reusable worktree while still belonging to the main project
If I launch a new session from the main project root, then tell the agent to work inside another existing worktree path, the actual execution may happen there, but the Codex UI/project context still looks tied to the main tree.
That causes problems because branch / git status / PR info / CodeGraph / workspace context can become visually or logically misaligned.
If I instead launch directly from the worktree, the session becomes attached to that worktree as if it were a separate project, which fragments project history/memory.
What I want is:
- session belongs to the main project
- execution workspace is an already existing worktree
- git/branch/PR/status/indexing context follows that worktree
- project identity remains the main project
2. Archiving/completing a session should not force the associated worktree to become disposable
If a session created a worktree and the task is done, I may want to:
- close the branch
- archive the session
- keep the worktree
because the worktree already has all dependencies, indexes, and local environment prepared.
Right now, the workflow feels like the worktree is treated as a temporary byproduct of the session, instead of a reusable project-level workspace.
That makes it hard to reuse the same prepared worktree for the next task.
Why this matters
For real development workflows, especially multi-branch / multi-module / long-lived projects, reusable worktrees are important for efficiency.
Recreating worktrees repeatedly means redoing or revalidating:
- dependency installation
- local environment prep
- code indexing
- tool caches
- project-specific setup
This becomes especially painful when the worktree is intentionally kept as a stable lane, e.g. “frontend workspace” or “backend workspace”.
Requested behavior
I’d love Codex to support a model like this:
Project
The logical project identity, memory/history grouping, and top-level project context.
Session
A task-specific conversation / execution run.
Workspace / Worktree
The actual execution environment, which can be long-lived and reusable across multiple sessions.
Desired capabilities
- When creating a new session, allow selecting an already existing worktree as the execution workspace.
- Keep the session attached to the main project identity, not split into a separate project just because the worktree lives elsewhere.
- In the UI, show git branch / PR / status / workspace information based on the selected worktree, not the main tree.
- When archiving/completing a session, provide an explicit choice:
- archive session and delete worktree
- archive session but keep worktree
- Allow future sessions to re-bind to that preserved worktree.
Concrete example
Main project:/Users/gpp/project/gitee/jwxt
Reusable long-lived frontend worktree:/Users/gpp/.codex/worktrees/39d7/jwxt
Desired workflow:
- Task A session uses that worktree
- Task A finishes
- branch is merged/closed
- session is archived
- worktree is kept
- Task B starts later
- new session binds again to
/Users/gpp/.codex/worktrees/39d7/jwxt - UI shows the real branch / git status / PR / CodeGraph context of that worktree
- but the session still belongs to the main
jwxtproject
Summary
The main request is:
Please treat worktrees as reusable project-level execution environments, not only as disposable session byproducts.
Filed with help from Codex on behalf of the reporter.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗