codex - 💡(How to fix) Fix Fork into new worktree leaves terminal cwd in original checkout [3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#21432Fetched 2026-05-07 03:40:14
View on GitHub
Comments
3
Participants
2
Timeline
7
Reactions
0
Timeline (top)
commented ×3labeled ×3closed ×1

In Codex Desktop, both Fork into new worktree and Handoff to Worktree appear to create Codex-managed worktree directories, but the active thread terminal continues running from the original local checkout. When asked, Codex responds that it is not in a new worktree. This creates a mismatch between the UI/worktree state and the actual command execution context. After the operation, git worktree list shows new worktrees under $HOME/.codex/worktrees/..., but in the affected thread:

pwd
git rev-parse --show-toplevel

still report the original repo path.

Root Cause

This can cause edits intended to be isolated in a Codex worktree to be applied to the user’s main/local checkout instead. The sidebar/worktree UI can therefore appear safe while the terminal and file operations are still targeting the original repo.

Code Example

pwd
git rev-parse --show-toplevel

---

$HOME/.codex/worktrees/<id>/<repo>

---

/path/to/local/repo

---

$ pwd
/path/to/local/repo
$ git rev-parse --show-toplevel
/path/to/local/repo
$ git branch --show-current
codex/<chat_title>
$ git rev-parse HEAD
<head-a>
$ git worktree list
/path/to/local/repo                         <head-a> [codex/<chat_title>]
$HOME/.codex/worktrees/c026/<repo>          <head-b> (detached HEAD)
$HOME/.codex/worktrees/f257/<repo>          <head-a> (detached HEAD)

---

worktree $HOME/.codex/worktrees/c026/<repo>
HEAD <head-b>
detached
worktree $HOME/.codex/worktrees/f257/<repo>
HEAD <head-a>
detached
RAW_BUFFERClick to expand / collapse

260506_1834ET — use this:

Bug: Fork/Handoff to worktree leaves thread terminal in original checkout

Summary

In Codex Desktop, both Fork into new worktree and Handoff to Worktree appear to create Codex-managed worktree directories, but the active thread terminal continues running from the original local checkout. When asked, Codex responds that it is not in a new worktree. This creates a mismatch between the UI/worktree state and the actual command execution context. After the operation, git worktree list shows new worktrees under $HOME/.codex/worktrees/..., but in the affected thread:

pwd
git rev-parse --show-toplevel

still report the original repo path.

Expected behavior

After selecting Fork into new worktree or Handoff to Worktree, the active thread terminal should execute from the newly associated worktree, e.g.:

$HOME/.codex/worktrees/<id>/<repo>

App-level Git actions, file edits, and terminal commands should target that worktree, not the original checkout.

Actual behavior

The thread remained in the original checkout:

/path/to/local/repo

For Fork into new worktree:

  • A new chat was created.
  • A new worktree directory appeared under $HOME/.codex/worktrees/....
  • The new chat’s terminal still ran from /path/to/local/repo.
  • The current branch did not change.

For Handoff to Worktree:

  • A new branch was created/checked out in the original checkout.
  • A Codex worktree existed on disk.
  • The thread terminal still ran from /path/to/local/repo, not from the worktree.

Evidence

Immediately after attempting the fork/handoff, from the supposedly worktree-backed thread:

$ pwd
/path/to/local/repo
$ git rev-parse --show-toplevel
/path/to/local/repo
$ git branch --show-current
codex/<chat_title>
$ git rev-parse HEAD
<head-a>
$ git worktree list
/path/to/local/repo                         <head-a> [codex/<chat_title>]
$HOME/.codex/worktrees/c026/<repo>          <head-b> (detached HEAD)
$HOME/.codex/worktrees/f257/<repo>          <head-a> (detached HEAD)

Additional inspection:

worktree $HOME/.codex/worktrees/c026/<repo>
HEAD <head-b>
detached
worktree $HOME/.codex/worktrees/f257/<repo>
HEAD <head-a>
detached

So at least one Codex-managed worktree was created and pointed at the same commit as the original checkout, but the active thread cwd remained the original checkout.

Why this matters

This can cause edits intended to be isolated in a Codex worktree to be applied to the user’s main/local checkout instead. The sidebar/worktree UI can therefore appear safe while the terminal and file operations are still targeting the original repo.

Environment

  • macOS: 26.4, build 25E5233c
  • Codex app: 26.429.61741
  • CFBundleVersion: 2429

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

After selecting Fork into new worktree or Handoff to Worktree, the active thread terminal should execute from the newly associated worktree, e.g.:

$HOME/.codex/worktrees/<id>/<repo>

App-level Git actions, file edits, and terminal commands should target that worktree, not the original checkout.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Fork into new worktree leaves terminal cwd in original checkout [3 comments, 2 participants]