- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6.1k
Experimental: Introduce git worktrees #3768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
        
          
                codex-rs/core/src/git_worktree.rs
              
                Outdated
          
        
      |  | ||
| impl WorktreeHandle { | ||
| /// Create (or reuse) a worktree rooted at | ||
| /// `<repo_root>/codex/<conversation_id>`. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about <repo_root>/codex-worktree/<conversation_id> or <repo_root>/.codex/worktree/<convseration_id>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
        
          
                codex-rs/core/src/git_worktree.rs
              
                Outdated
          
        
      | let path = codex_dir.join(conversation_id.to_string()); | ||
| let is_registered = worktree_registered(&repo_root, &path).await?; | ||
|  | ||
| if is_registered { | ||
| if let Err(err) = ensure_codex_excluded(&repo_root).await { | ||
| warn!("failed to add codex worktree path to git exclude: {err:#}"); | ||
| } | ||
| info!( | ||
| worktree = %path.display(), | ||
| "reusing existing git worktree for conversation" | ||
| ); | ||
| return Ok(Self { repo_root, path }); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Avoid reusing deleted worktree directories
When worktree_registered returns true the code immediately returns a WorktreeHandle without verifying that the directory at codex/<conversation> actually exists. If a user deletes the worktree directory but forgets to run git worktree prune (which keeps the registration entry), subsequent sessions will reuse a non‑existent path and all commands will fail with No such file or directory. Consider checking path.exists() in the reuse branch and recreating or reporting an error so the session never operates in a missing cwd.
Useful? React with 👍 / 👎.
| } | ||
|  | ||
| async fn ensure_codex_excluded(repo_root: &Path) -> Result<()> { | ||
| const PATTERN: &str = "/codex/"; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe only /codex/worktree/ should be excluded now?
| you can also just write  this avoids messing with files outside codex/ | 
Introduce WorktreeHandle to create/reuse/remove linked checkouts under <cwd>/codex/<conversation>; add config flag enable_git_worktree (and trust logic for worktrees); plumb protocol: RemoveWorktree, WorktreeRemoved, SessionConfigured.worktree_path; update exec/TUI integration; docs: experimental config section. # Conflicts: # codex-rs/core/src/codex.rs # codex-rs/tui/src/chatwidget.rs
…t for new SessionConfiguredEvent field
5818261    to
    d4750bc      
    Compare
  
    
This PR introduces the ability to give agents a git work-tree. Thus, we can have multiple agents working on the same repo at the same time.
This feature is disabled by default behind
enable_git_worktreeconfig.When enabled:
Caveat:
UX:
Lifecycle: