You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Claude Code subagents (spawned via the Agent tool with isolation: "worktree") delete unrelated files when committing their work. The agent's commits include deletions of files the agent never touched, suggesting broad git staging (git add -A or git add .) despite the system prompt instructing "prefer adding specific files by name."
This has happened 3 times in our project over 2 days, deleting production source code — not just documentation.
Update: Initial report stated commits were "direct on master." Forensic reflog analysis revealed they were worktree branch commits fast-forward merged onto master. This potentially links to #44965. See comments for full correction.
Reproduction
Environment
Claude Code CLI v2.1.92
Claude Opus 4.6 (1M context)
Linux (Proxmox LXC)
Git repository with .planning/phases/ directories containing per-phase artifacts
Subagents spawned with isolation: "worktree" (via GSD framework default)
Steps
Have a repository with multiple "phase" directories containing planning docs and source code
Use Claude Code to spawn an executor subagent (via Agent tool with isolation: "worktree") to work on Phase N+2
The subagent makes commits for its assigned work (e.g., adding test files)
Observe: The subagent's commits also delete files from Phase N and Phase N+1 directories, plus production source code created by those phases
What happens
The subagent's commits include:
The intended changes (test files, implementation)
Unintended deletions of 20-30+ files from other phases
Unintended modifications to shared files (ROADMAP.md, REQUIREMENTS.md, STATE.md) reverting them to older state
Expected behavior
The subagent should only stage and commit files it explicitly created or modified.
Evidence
Incident 1: Phase N+1 executor deletes Phase N files
Intended: Add 3 test files
Actually did: Deleted 22 files including:
A 406-line production module
An 883-line test suite
Several utility scripts
8 Phase N planning files, 6 Phase N+1 planning files
Modified a 7000+ line orchestrator file removing ~149 lines of Phase N wiring
Verified: Parent commit confirmed to have all deleted files via git ls-tree
Delivery: Worktree branch fast-forward merged onto master (initially misreported as direct commit)
Incident 2: Phase N+2 executor deletes Phase N and N+1 files (again)
Intended: Add 3 test files for Phase N+2
Actually did: Deleted 34 files including all Phase N, N+1, and N+2 planning files
Same pattern: worktree branch, broad staging
Incident 3: Partial restoration also deleted
A restore commit after Incident 2 fixed some files but left production source missing until manual forensic restoration
Forensic verification: No external automation
We thoroughly verified no system-level automation is responsible:
No active git hooks (only .sample files in .git/hooks/)
Claude Code hooks (.claude/hooks/) are advisory-only (read-only, never modify git state)
No pre-commit framework
Empty crontab
No Syncthing, rsync, or file sync tools
No IDE auto-staging or auto-commit configuration
No background git processes
Impact
Production source code deleted (not just documentation) — 406-line module, 883-line test suite, query scripts
Orchestrator wiring reverted — phase integration code removed from main 7000+ line file
Config reverted — YAML config sections removed
3 incidents in 2 days — recurring and escalating (each incident deletes more files)
Silent data loss — no warning or error when the agent commits the deletions. Only discovered during milestone audit.
Root Cause Hypothesis
Updated: Two possible root causes, potentially compounding:
Worktree branch point (EnterWorktree creates branch from main instead of current branch HEAD (macOS) #44965):EnterWorktree may create the worktree from main (or another ref) instead of current HEAD. Files committed after that branch point are absent from the worktree. When the agent stages with git add -A, these absent files become explicit deletions.
Broad staging (original hypothesis): Even with a correct branch point, the subagent uses broad git staging (git add -A, git add .) rather than staging only files it created/modified via Edit/Write tools. Any file absent from the working tree — for any reason — gets staged as a deletion.
The system prompt correctly instructs: "prefer adding specific files by name rather than using git add -A or git add ., which can accidentally include sensitive files or large binaries" — but the agent does not reliably follow this instruction.
Suggested Fix
Hard enforcement: Claude Code's commit tooling should refuse or warn when a commit includes file deletions that weren't explicitly requested
Staging guard: Before committing, check git diff --cached --diff-filter=D and require explicit confirmation for any deletions
Subagent scope restriction: Subagents should only be able to stage files within their assigned scope (e.g., files they created or modified via Edit/Write tools)
Summary
Claude Code subagents (spawned via the
Agenttool withisolation: "worktree") delete unrelated files when committing their work. The agent's commits include deletions of files the agent never touched, suggesting broad git staging (git add -Aorgit add .) despite the system prompt instructing "prefer adding specific files by name."This has happened 3 times in our project over 2 days, deleting production source code — not just documentation.
Update: Initial report stated commits were "direct on master." Forensic reflog analysis revealed they were worktree branch commits fast-forward merged onto master. This potentially links to #44965. See comments for full correction.
Reproduction
Environment
.planning/phases/directories containing per-phase artifactsisolation: "worktree"(via GSD framework default)Steps
Agenttool withisolation: "worktree") to work on Phase N+2What happens
The subagent's commits include:
Expected behavior
The subagent should only stage and commit files it explicitly created or modified.
Evidence
Incident 1: Phase N+1 executor deletes Phase N files
git ls-treeIncident 2: Phase N+2 executor deletes Phase N and N+1 files (again)
Incident 3: Partial restoration also deleted
Forensic verification: No external automation
We thoroughly verified no system-level automation is responsible:
.samplefiles in.git/hooks/).claude/hooks/) are advisory-only (read-only, never modify git state)Impact
git diff <commit>..<commit>^ | git applyRoot Cause Hypothesis
Updated: Two possible root causes, potentially compounding:
Worktree branch point (EnterWorktree creates branch from main instead of current branch HEAD (macOS) #44965):
EnterWorktreemay create the worktree frommain(or another ref) instead of current HEAD. Files committed after that branch point are absent from the worktree. When the agent stages withgit add -A, these absent files become explicit deletions.Broad staging (original hypothesis): Even with a correct branch point, the subagent uses broad git staging (
git add -A,git add .) rather than staging only files it created/modified via Edit/Write tools. Any file absent from the working tree — for any reason — gets staged as a deletion.The system prompt correctly instructs: "prefer adding specific files by name rather than using
git add -Aorgit add ., which can accidentally include sensitive files or large binaries" — but the agent does not reliably follow this instruction.Suggested Fix
git diff --cached --diff-filter=Dand require explicit confirmation for any deletionsEnterWorktreebranches from current HEAD, notmainWorkaround
Manually verifying commits via
git show --statafter every subagent execution and maintaining restore scripts. This is fragile and labor-intensive.