Worktree cleanup leaves stale git config (repositoryformatversion=1, worktreeConfig=true) that breaks other IDE AI agents
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
- Open a git repository with Claude Code
- Run any task that triggers Claude Code to create a worktree (e.g., a Plan Mode or subagent task)
- After the task completes, close Claude Code
- Check
.git/config—repositoryformatversionremains1and[extensions] worktreeConfig = trueremains - 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:
- Remove the worktree entry (or run
git worktree prune) - Restore
repositoryformatversionback to0 - Remove
extensions.worktreeConfigfrom.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
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗