Worktree cleanup leaves stale git config (repositoryformatversion=1, worktreeConfig=true) that breaks other IDE AI agents

Resolved 💬 3 comments Opened Apr 9, 2026 by oh001738 Closed Apr 12, 2026

Bug Description

When Claude Code creates a git worktree for a subagent task, it sets repositoryformatversion = 1 and extensions.worktreeConfig = true in .git/config. After the task completes and the worktree directory is deleted, these config values are not restored, and the stale worktree entry in .git/worktrees/ is also not cleaned up.

Steps to Reproduce

  1. Open a git repository with Claude Code
  2. Run any task that triggers Claude Code to create a worktree (e.g., a Plan Mode or subagent task)
  3. After the task completes, close Claude Code
  4. Check .git/configrepositoryformatversion remains 1 and [extensions] worktreeConfig = true remains
  5. Check git worktree list — a stale prunable entry referencing a non-existent .claude/worktrees/<name> path is still listed

Expected Behavior

After Claude Code finishes using a worktree, it should:

  1. Remove the worktree entry (or run git worktree prune)
  2. Restore repositoryformatversion back to 0
  3. Remove extensions.worktreeConfig from .git/config

Actual Behavior

.git/config after the session:

[core]
    repositoryformatversion = 1   ← should be 0
    ...
[extensions]
    worktreeConfig = true          ← should be removed

git worktree list output:

/path/to/repo                                    abc1234 [main]
/path/to/repo/.claude/worktrees/serene-robinson  def5678 [claude/serene-robinson] prunable  ← stale

Impact

repositoryformatversion = 1 is a non-standard git format that requires tools to explicitly declare support for the active extensions. IDEs and tools that use older git libraries encounter a silent failure when reading this repository, causing their AI agents to stop responding entirely in this directory — while working fine in other projects.

Manually fixed by:

rm -rf .git/worktrees/<worktree-name>
git branch -d claude/<worktree-name>
git config core.repositoryformatversion 0
git config --unset extensions.worktreeConfig

Environment

  • OS: macOS 25.4.0
  • Claude Code version: claude-sonnet-4-6

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗