Skip to content

Fork into new worktree leaves terminal cwd in original checkout #21432

Closed

Description

@maharris77

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

Activity

  1. added
    bug
    app
    session
    on May 6, 2026
  2. github-actions commented on May 6, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  3. maharris77 commented on May 6, 2026

    @maharris77
    Author

    Possibly related to #20725. That issue reports stale runtime CWD when navigating between project chats; this issue reports the same class of runtime/UI mismatch specifically after Fork into worktree on macOS. Reproducing the issue does not require navigating between chats.

  4. maharris77 commented on May 7, 2026

    @maharris77
    Author

    Removing the project and adding it again seems to have resolved the issue. The projects had been added to Codex a long while ago, and before the worktree features were added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    appbugsession

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions