Fix worktree pruning: lock worktrees + disable agent auto-gc#144
Merged
Conversation
Root cause: concurrent agents' git commits trigger gc --auto, which calls git worktree prune, deleting metadata for other agents' worktrees. Fix (belt and suspenders): 1. Lock worktrees immediately after creation — locked worktrees survive gc prune. Unlock before removal. 2. Disable auto-gc in agent environment via GIT_CONFIG env vars — prevents agent git commands from triggering gc entirely. 3. Verify worktree metadata directory (not just .git file) in getDiff. Removes old .git file backup approach (addressed symptom not cause). Closes #136 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
that-github-user
pushed a commit
that referenced
this pull request
Mar 29, 2026
The worktree lock (#144) protects .git/worktrees/NAME/ from gc pruning. But agents with Bash/Write access can still delete the .git POINTER FILE from the worktree directory itself. This backup/restore catches that case. Both protections together: - Lock → prevents gc from pruning metadata directory - Backup → restores pointer file if agent deletes it Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 tasks
that-github-user
added a commit
that referenced
this pull request
Mar 29, 2026
The worktree lock (#144) protects .git/worktrees/NAME/ from gc pruning. But agents with Bash/Write access can still delete the .git POINTER FILE from the worktree directory itself. This backup/restore catches that case. Both protections together: - Lock → prevents gc from pruning metadata directory - Backup → restores pointer file if agent deletes it Co-authored-by: unknown <that-github-user@github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root cause found: concurrent agents'
git committriggersgc --auto→git worktree prune→ deletes other agents' worktree metadata.Fix:
git worktree lockimmediately after creation — locked worktrees survive pruneGIT_CONFIG_COUNT=1 gc.auto=0env vars on agent processes — prevents gc entirelyVerified: worktree lock file appears in
.git/worktrees/NAME/locked, removeWorktree still works.Change type
Related issue
Closes #136
How to test
Breaking changes
🤖 Generated with Claude Code