October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Coding Agent Changes Stay in the Worktree Where It Runs

A task worktree gives a coding agent its own directory and typically its own branch, while remaining linked to the same Git repository. Here’s what that separates—and what it doesn’t.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

With one worktree per task, each coding task gets its own directory and—usually—its own branch, while Git keeps those worktrees attached to the same repository. An agent started in a task’s directory edits that checkout; its files do not appear in another worktree automatically. The separation is useful for concurrent work, but it is not a complete sandbox for services, secrets, databases, or dependencies.

What “one worktree per task” means

A Git worktree is a working directory connected to a repository. The Git project describes the arrangement this way: “A git repository can support multiple working trees, allowing you to check out more than one branch at a time.” A repository has one main worktree and can have additional linked worktrees.

As an Amazon Associate I earn from qualifying purchases.

Linked worktrees share repository data, but each has its own checked-out files and some per-worktree Git state, including its own HEAD and index. A linked worktree is therefore not another independent clone. At its top level, its .git is a file pointing to repository metadata, rather than a complete .git directory. Scripts or containers that use a linked worktree need access to the metadata path that file references. Git’s worktree reference documents the arrangement and commands.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where does a coding agent’s work go?

The agent edits files in the directory where it is running. If it starts in a task-specific worktree, its file changes belong to that worktree’s checkout and, when attached to one, its branch. Other worktrees do not show those edits simply because they share the repository’s Git data.

Once changes are committed, the commit is part of the shared repository data and can be integrated through the normal Git workflow. Until then, uncommitted changes remain in the worktree where they were made. A task-specific branch and directory make it easier to see which workspace owns a set of edits.

Should you use one worktree per coding task?

It is a practical choice when tasks need separate checked-out files—for example, when parallel coding sessions might otherwise modify the same checkout. Use a distinct branch for each task that will produce changes. Worktrees are not a guarantee that everything the task uses is separate: running servers, databases, secrets, package caches, and other services may still be shared, depending on your setup.

Approach Directory and branch Git data Setup and integration
Separate task worktree Separate directory; can use a distinct branch Linked to the same repository; some state is per-worktree Local ignored files may need separate setup. Review and integrate changes using normal Git operations.
Another clone Separate directory and repository checkout Separate clone Setup and integration follow your clone workflow. Disk or performance savings versus worktrees are not established by the cited documentation.
One shared checkout One directory and active checkout One working tree Concurrent tasks operate in the same files, so their edits can collide. There is no separate worktree to integrate.

The comparison describes the basic Git layout, not a measured performance or disk-usage result. A worktree may avoid maintaining another clone’s repository data, but dependencies, build outputs, and other files are determined by your project and setup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a worktree and branch for a task

From the existing repository, run the following command, replacing the names and base branch with those used by your project:

git worktree add -b feature/task-name ../task-name main

Here, feature/task-name is the new branch, ../task-name is the worktree directory, and main is the starting point. Use the repository’s actual base branch or commit if it differs.

  1. Choose a clear task name. Reuse it in the directory and branch names so the mapping is easy to recognize.
  2. Create the worktree. Run git worktree add -b <branch> <path> <start-point> from the repository, substituting the branch, directory, and intended base.
  3. Start the agent in that directory. Verify its working directory before allowing it to edit files.
  4. Check local prerequisites. Identify ignored configuration files and local services the task needs; a new worktree does not guarantee they are present or isolated.
  5. Review and integrate. Inspect the task branch’s status and diff, then use your usual review and merge process.
  6. Clean up when finished. Inspect the worktree list and remove the linked worktree when its work is safe to remove.

Git can also create a worktree without creating a branch, including a detached worktree for testing or an experiment. For a task that needs its own branch, create one explicitly. By default, Git refuses to check out a branch already in use by another worktree; do not try to make two worktrees edit the same branch concurrently.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What is different about Codex app-managed worktrees?

These details apply to worktrees managed by the Codex desktop app, not to every Git worktree. According to OpenAI’s Codex worktree guide, a managed worktree is typically dedicated to one chat, while a permanent worktree is intended for a longer-lived project and can host multiple chats.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

By default, Codex creates managed worktrees under $CODEX_HOME/worktrees. A managed worktree starts from the selected branch’s HEAD and uses detached HEAD. If that selected branch has uncommitted changes, Codex applies them to the worktree. The guide says the worktree root can be changed in Settings.

Ignored local files and handoffs

For local, app-managed worktrees, Codex supports a .worktreeinclude file to specify ignored paths to copy, such as .env or local configuration. Codex copies matching ignored files, skips source symlinks, and does not overwrite files already present. The documented behavior applies to local ChatGPT desktop app-managed worktrees; it does not describe remote worktrees or command-line worktrees created manually.

The guide also describes handing a chat between Local and Worktree, with the app handling the Git operations. Ignored files do not move in a handoff unless copied into a local managed worktree using .worktreeinclude. Because a branch cannot be checked out in two worktrees at once, use the app’s documented handoff flow rather than trying to check out the same branch in both locations.

Managed-worktree retention

OpenAI’s guide describes a default setting to retain the 15 most recent Codex-managed worktrees. This is an adjustable product setting, not a Git limit, and may change. The guide says Codex saves a snapshot before automatic deletion and can offer restoration when the chat is reopened.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inspect, remove, or repair worktrees

Git provides commands to see and maintain linked worktrees:

  • git worktree list shows the worktrees associated with the repository.
  • git worktree remove <path> removes a linked worktree. Git expects it to be clean by default; do not force removal without first understanding what uncommitted or untracked work would be lost.
  • git worktree prune clears stale administrative records after a worktree directory has been manually deleted.
  • git worktree repair can repair worktree links after a manual move when needed.

Prefer Git’s worktree commands over deleting directories casually: Git tracks linked-worktree metadata as well as the files in the directory. The exact options are documented in the Git worktree reference.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.