Worktree is better suited as a one-time execution directory.


A common practice recently has been to prepare a worktree first, then open Codex / Claude Code within that directory. Because early models had limited context and memory, if you let it create a worktree directly in the main workspace, it’s easy for the current directory and the created worktree directory to get mixed up after context compression, leading to confusion.
However, this approach also has a side effect: it gradually turns the worktree into a long-term workspace. The problem is, worktrees are inherently tied to branches, and over time, you'll encounter additional hassles like branch switching, synchronization, and cleanup.
Many people also don’t clearly distinguish between worktrees and independent clones. The benefit isn’t just “an extra directory,” but that fundamentally, they are the same repository sharing the git object database, with low copying costs and no need to re-clone over the network. This is especially convenient for large repositories. So if you just want a temporary parallel execution directory, worktree is very suitable. Only when you explicitly need a completely independent object database—for example, mapping to Docker or a virtual machine sandbox—would a local clone be more appropriate.
At least for now with Codex / Claude Code, this issue isn’t as serious anymore. I now prefer to work directly in the main directory, letting it create worktrees as needed, then merge back after changes, and delete the worktree. This aligns better with the original purpose of worktrees: low-cost temporary execution directories, not long-term secondary workspaces.
One step further, I am currently experimenting with maintaining a global workspace where all project Codex instances are opened in this directory, and it manages clones and worktrees according to rules. This makes global memory more continuous, and if a task requires editing multiple projects simultaneously, it knows how to handle each one sequentially and then perform joint testing.
View Original
This page may contain third-party content, which is provided for information purposes only (not representations/warranties) and should not be considered as an endorsement of its views by Gate, nor as financial or professional advice. See Disclaimer for details.
  • Reward
  • Comment
  • Repost
  • Share
Comment
Add a comment
Add a comment
No comments
  • Pin