Claude Code Bug:背景自動執行 git reset --hard 靜默刪除你的程式碼 | Claude Code Bug: Background git reset --hard Silently Deletes Your Code
By Kit 小克 | AI Tool Observer | 2026-03-30
🇹🇼 Claude Code Bug:背景自動執行 git reset --hard 靜默刪除你的程式碼
Claude Code 近日被開發者回報一個高危 Bug:工具在背景每 10 分鐘自動執行 git fetch origin 與 git reset --hard origin/main,靜默覆蓋所有未提交的本地更動,讓開發者在毫無警告的情況下損失數小時的心血。這個問題在 GitHub Issue #40710 與 HackerNews 上迅速引爆,超過 200 名開發者參與討論。
Bug 的具體行為
根據多名受影響的開發者描述,Claude Code 內建一個背景定時器,固定間隔執行以下指令:
git fetch origin
git reset --hard origin/main
這個行為的設計初衷據推測是「讓工作目錄保持與遠端同步」,但在實際使用中,效果等同於每 10 分鐘強制丟棄你所有未提交的本地更動——包括已修改但尚未 git add 或 git commit 的檔案。
為什麼這個 Bug 特別危險
- 完全靜默:沒有任何 UI 警示、彈窗或 terminal 輸出,你不會知道它發生了。
- git reset --hard 不可逆:不像
git stash,reset --hard的未 commit 更動無法直接還原,只能靠 reflog 或 IDE 本地歷史勉強救援。 - 10 分鐘間隔讓人難以察覺:你以為自己寫錯了、手殘了,結果是工具偷偷把你的改動丟掉。
- 與 AI 輔助開發工作流衝突:使用 AI 工具時,你可能正在半成品狀態下來回嘗試,uncommitted 的改動本來就是正常的工作狀態。
如何立即自保
在官方修補程式推出前,以下幾個做法可以大幅降低損失風險:
- 勤 commit、早 commit:不要讓任何重要改動停留在 unstaged 狀態超過幾分鐘。
- 使用 git stash:暫時離開工作時先
git stash push -m "WIP",保留工作記錄。 - 開啟 IDE 本地歷史:VS Code、JetBrains 等 IDE 有 Local History 功能,能在 git 之外保存每次檔案儲存的快照。
- 監控 git reflog:執行
git reflog可以看到最近的 HEAD 移動記錄,如果看到意外的 reset 記錄,可以嘗試git checkout <hash>救援。 - 升級或暫時停用 Claude Code:關注 Anthropic 官方 Issue 回應與版本更新,在修補前謹慎使用。
更大的教訓:AI 工具的檔案系統權限不容輕忽
這個事件折射出一個更深層的問題:當 AI 工具獲得操作本地檔案系統與版本控制系統的能力時,我們對它的信任假設需要重新審視。
過去幾年,AI 工具的能力從「生成文字建議」演進到「直接執行終端指令」,這個躍進帶來了生產力,但也帶來了新的風險面向。一個背景程序靜默執行 git reset --hard,在傳統 CLI 工具中屬於高危行為,需要明確的使用者確認;但在 AI Agent 的架構下,它可能只是一個「維持環境整潔」的小功能,被加入了卻沒有充分測試邊界案例。
這不是要否定 AI 工具的價值——Claude Code 本身仍然是一個強大的開發助手。但這個 Bug 提醒我們:授予 AI Agent 版本控制系統的寫入權限,等同於授予它覆蓋你工作的能力,應謹慎對待。
好不好用,試了才知道——但試之前,先確保你的工作有備份。
🇺🇸 Claude Code Bug: Background git reset --hard Silently Deletes Your Code
A serious bug in Claude Code has gone viral on developer forums: the tool was reportedly running git fetch origin followed by git reset --hard origin/main in the background every 10 minutes, silently wiping out all uncommitted local changes without any warning. The issue, tracked at GitHub Issue #40710, attracted over 200 comments on HackerNews and caused some developers to lose hours of work before realizing what had happened.
What the Bug Actually Does
According to affected developers, Claude Code contains a background timer that periodically runs:
git fetch origin
git reset --hard origin/main
The intent appears to have been keeping the working directory in sync with the remote. In practice, this functions as a silent, automatic destruction of every uncommitted local change every 10 minutes — including any modifications you haven't yet staged or committed.
Why This Is Especially Dangerous
- Completely silent: No UI alert, no terminal warning, no indication that it happened.
- git reset --hard is irreversible: Unlike
git stash, a hard reset discards working tree changes permanently. Recovery requiresgit reflogor IDE local history — and only if you act fast. - 10-minute intervals are hard to notice: Developers naturally assume they made a mistake, not that a background process wiped their work.
- Conflicts with AI-assisted workflows: When working with an AI tool, having uncommitted work-in-progress is the normal state. The tool is actively working against your workflow.
How to Protect Yourself Right Now
Until an official fix is released, here's how to reduce your exposure:
- Commit early and often: Don't let important changes sit in an unstaged state for more than a few minutes.
- Use git stash: Before stepping away from your work, run
git stash push -m "WIP"to preserve your changes outside the working tree. - Enable IDE local history: VS Code and JetBrains IDEs both offer Local History features that save file snapshots independently of git — a critical safety net.
- Check git reflog for unexpected resets: Run
git reflogto see recent HEAD movements. If you see an unexpected reset, trygit checkout <hash>to recover. - Watch for the official patch: Monitor the GitHub issue and upgrade Claude Code as soon as a fix is available.
The Bigger Lesson: AI Agents With File System Access
This bug highlights a structural tension in modern AI developer tools: when an AI agent gains write access to your file system and version control, the trust model changes fundamentally.
AI coding tools have evolved from "suggest code in a chat window" to "execute terminal commands autonomously." That evolution brings real productivity gains — but it also introduces a new class of risk. A background process running git reset --hard would be flagged as dangerously destructive in any traditional CLI tool. In an AI agent architecture, it can slip in as a small "environment hygiene" feature that wasn't stress-tested against edge cases.
This isn't an argument against AI tools. Claude Code remains a powerful development assistant. But this incident is a reminder: granting an AI agent write access to version control is granting it the ability to overwrite your work. Review what permissions your AI tools hold, and keep your safety nets — commits, stashes, local history — firmly in place.
You won't know until you try it — just make sure you have a backup before you do.
Sources / 資料來源
- GitHub Issue #40710 — Claude Code runs git reset --hard origin/main every 10 minutes
- HackerNews Discussion — Claude Code silently runs git reset --hard on project repo
- Claude Code Documentation — Working with git and version control
延伸閱讀 / Related Articles
- ARC-AGI-3 發布:頂尖 AI 全部得分不到 1% | ARC-AGI-3: Every Top AI Model Scored Under 1%
- OpenAI Spud 完成訓練:GPT-6 幾週後上線? | OpenAI Spud Training Done: Is GPT-6 Weeks Away?
- Mistral Small 4 開源:三合一 MoE 模型,免費商用 | Mistral Small 4: Open-Source 119B MoE That Does It All
AI 工具觀察站 — 每日精選 AI Agent 與工具趨勢
AI Tool Observer — Daily curated AI Agent & tool trends
留言
張貼留言