claude-code - 💡(How to fix) Fix [BUG] Bug: subagent ran git checkout to undo its own broken sed, silently wiping unrelated uncommitted edits

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

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.

Error Messages/Logs

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Bug: subagent ran git checkout to undo its own broken sed, silently wiping unrelated uncommitted edits