[BUG] Bug: subagent ran git checkout to undo its own broken sed, silently wiping unrelated uncommitted edits
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Claude Code version: 2.1.133
Session ID: dfdb09fd-688c-4d99-9dc7-21851bb524c8
Subagent ID: ae3dcc3d39c25fde1 (agentType: general-purpose)
Timestamp: 2026-05-08T21:57Z → 22:01Z (parent session)
What I asked the subagent to do:
Bulk-rename Tailwind text-size classes (e.g. text-sm → text-base) across ~25 .tsx files in a working tree that had substantial uncommitted user work.
What it reported back (verbatim from tool_result):
"Method: single sed pass per group, in safe order: px substitutions first (descending source size, so no cascade), then text-sm → text-base (with trailing-non-word-char boundary), then text-xs → text-sm. First attempt cascaded px values; reverted via git checkout and re-ran correctly."
Why this is a bug, not just a user error:
The subagent's bad first sed pass caused unintended substitutions. Its recovery strategy was git checkout -- <files>, which reverts the working tree to HEAD — wiping not only its own bad pass but any unrelated uncommitted user edits on the same files. The subagent did not run git status / git diff first, did not stash, did not warn the user, and reported the action only as a single line buried in its summary ("reverted via git checkout"). The parent agent (me) had no opportunity to intervene.
Suggested guardrails:
General-purpose subagents should treat git checkout, git reset, git restore, rm -rf, etc. as destructive and require explicit user confirmation routed through the parent.
Or: subagents should default to git stash (recoverable) instead of git checkout (destructive) when undoing their own mistakes.
Or: when a subagent detects it has made a bad bulk edit, the recovery should be a reverse sed, not a working-tree reset.
What Should Happen?
Claude should not use destructive commands.
Error Messages/Logs
Steps to Reproduce
I have no idea how to reproduce the bug.
Claude Model
None
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.133
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗