Git conflicts and dirty worktrees with AI coding agents: what Aider, Claude Code, and Codex actually do

Aider 0.86.2 commits dirty changes, Claude Code 2.1.292 snapshots files, and Codex CLI 0.160.1 isolates parallel work in Git worktrees.

Update (2026-10-07): Corrected the current Aider and Claude Code versions, verified Codex CLI 0.160.1, removed an unsourced sample transcript, and tightened the recovery commands.

Aider 0.86.2 commits its own edits and, by default, commits pre-existing dirty changes first. Claude Code 2.1.292 keeps file snapshots for rewind and offers per-session Git worktrees. Codex CLI 0.160.1 uses managed worktrees for parallel work. A shared checkout can still collide on files, Git indexes, runtime state, and later merges.

What are the key Git facts?

  • As of 2026-10-07, the current package releases are Aider 0.86.2, Claude Code 2.1.292, and Codex CLI 0.160.1.
  • Aider defaults --auto-commits and --dirty-commits to True. It also defaults --git-commit-verify to False, so it skips pre-commit hooks unless you enable them.
  • Claude Code keeps file snapshots for the 100 most recent checkpoints in a session. Bash changes, background subagent edits, and external changes are outside that rewind history.
  • claude --worktree <name> creates a separate checkout under .claude/worktrees/. Claude Code locks its managed worktree while the agent runs.
  • Codex managed worktrees give parallel chats separate files and indexes while sharing repository metadata. Git still allows a branch to be checked out in only one worktree at a time.

How does Aider handle dirty worktrees and auto-commits?

Aider uses Git as part of its normal edit loop. Its Git documentation says that it commits each edit, then commits any pre-existing dirty files before applying new edits. The options reference confirms that --auto-commits and --dirty-commits both default to True.

"Aider takes special care before editing files that already have uncommitted changes (dirty files)."

That boundary protects changes Aider sees before it starts, but it does not serialize a second process editing the same file. Inspect the complete staged diff before accepting a commit from a shared checkout.

Aider can append (aider) to the committer metadata for a dirty commit while leaving the author metadata unchanged. The current --attribute-co-authored-by default can change that path, so do not infer attribution from the commit message alone.

Aider's /undo handles its last change, but issue #718 records failure after an external commit. Issue #4074 documents that --no-auto-commits also disables dirty commits. Set --git-commit-verify when the repository depends on pre-commit hooks.

How do Claude Code checkpoints compare with Git worktrees?

Claude Code 2.1.292 separates two kinds of recovery. Checkpoints are file snapshots for /rewind; worktrees are separate Git checkouts for parallel sessions. The documentation says it keeps snapshots for the 100 most recent checkpoints. Press Esc twice with an empty prompt, or run /rewind, to choose Restore code, Restore conversation, or both.

Claude Code does not track Bash changes, background subagent edits, or external changes. Its checkpointing documentation puts the boundary plainly: "Checkpointing does not track files modified by Bash commands." Use Git when the missing change came from a shell command or another process.

For isolation, claude --worktree <name> creates a new branch and checkout under .claude/worktrees/<name>/. Claude Code holds a git worktree lock while the agent runs. The default worktree.baseRef is "fresh"; set it to "head" when the worktree must include local in-progress commits. What changed in Claude Code during September 2026 covers the wider release context.

How does Codex CLI isolate parallel agents and sandboxes?

Codex CLI 0.160.1 uses managed Git worktrees for parallel work. OpenAI's current worktree documentation says each worktree has its own files while all worktrees share Git metadata. Managed worktrees start from the selected branch's HEAD in detached HEAD state.

That is file and index isolation, not merge or runtime isolation. Git worktrees keep agents apart until the merge makes the same point: separate worktrees move collisions to the merge boundary. Ports, databases, Docker volumes, and caches still need their own ownership rules.

Codex issue #19786 records a separate sandbox failure. The reporter tested codex-cli 0.125.0 on Linux and found that workspace-write made a linked worktree's Git directory read-only. The result was:

fatal: Unable to create '/home/user/projects/repo/.git/worktrees/repo-1/index.lock': Read-only file system

That report is about Codex CLI 0.125.0, not the current 0.160.1 release. It shows that a worktree can exist while the sandbox cannot write its linked Git metadata. The September 2026 Codex CLI refresh describes the interface changes; the worktree rule explains the file boundary.

How do you recover from Aider, Claude Code, and Codex CLI Git collisions?

1. An agent committed changes you need to inspect

First inspect the commit, then move HEAD back while keeping its changes staged:

git show --stat --oneline HEAD
git reset --soft HEAD~1
git diff --staged

Inside the same Aider session, /undo is shorter. If another process committed after Aider, use Git directly. For Claude Code, /rewind cannot restore Bash changes.

2. Aider started on a dirty tree

Inspect the last two commits before changing history:

git log -2 --oneline --decorate
git status --short

If those commits are the dirty snapshot and Aider edit, git reset HEAD~2 moves both changes back as unstaged changes. Confirm the two commits belong to the turn you intend to unwind first.

3. Two agents share one checkout

Stop the active Git operation before touching a lock. Confirm that no Git process owns the exact lock path, then create the second agent's checkout on a new branch:

git worktree add -b feature-agent-2 ../wt-agent-2 main
git worktree list --porcelain

Do not attach main to a second worktree. Git rejects a branch already checked out elsewhere. A practical guide updated on 2026-10-05 lists stale locks, branch conflicts, merge failures, and shared build artifacts as separate failure classes.

How do Aider, Claude Code, and Codex CLI compare?

Feature

Aider 0.86.2

Claude Code 2.1.292

Codex CLI 0.160.1

Default edit record

Git commit after edits

File checkpoint for rewind

Changes in a managed worktree

Dirty-tree behavior

Commits dirty files first

Snapshot does not replace Git history

Starts a separate checkout

Undo or recovery

/undo or Git reset

/rewind for tracked edits; Git for shell changes

Git inspection and branch integration

Parallel isolation

Use separate Git worktrees yourself

--worktree <name>

Managed Git worktrees

Main blind spot

Concurrent writes during generation

Bash and external changes outside checkpoints

Shared runtime state and Git metadata permissions

The reliable pattern is one agent, one branch or detached checkout, and one owner for shared runtime resources. Worktrees reduce accidental file overwrites. They do not make concurrent Git operations safe inside one checkout, and they do not resolve the merge for you.

Sources

Last verified: 2026-10-07.

Spotted an outdated or wrong claim? Agents can report it with evidence throughPOST /api/feedback; an editor checks every report. See llms.txt for the agent API.