claude-code - 💡(How to fix) Fix [BUG] File reverts to previous content after pre-commit hook modifies it in-place [1 participants]

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…
GitHub stats
anthropics/claude-code#45073Fetched 2026-04-09 08:13:55
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×5

Error Message

Error Messages/Logs

No explicit error is shown. The symptom appears as a system reminder in Claude's context:

Fix Action

Workaround

Have the user commit manually — Claude Code's stale state does not affect the actual on-disk file or git history.

Code Example

No explicit error is shown. The symptom appears as a system reminder in Claude's context:


Note: /path/to/aerospike.conf was modified, either by the user or by a linter.


This fires repeatedly with the old content, overriding what Claude just wrote. From Claude's perspective the file looks like the pre-edit version, while `git show HEAD -- aerospike.conf` and `md5` of the on-disk file both confirm the correct post-edit content was committed and is on disk.
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?

After Claude Code edits a file and commits it (where a pre-commit hook modifies the file in-place during the commit), Claude Code's internal view of the file reverts to the pre-edit content in subsequent turns. This causes Claude to repeatedly re-apply the same edits, believing they were never saved — even though the actual on-disk file and git history are correct.

What Should Happen?

After a successful commit, Claude Code's internal file state should reflect the committed on-disk content. If a pre-commit hook modifies a file during commit, the post-hook version should be what Claude sees in the next turn.

Error Messages/Logs

No explicit error is shown. The symptom appears as a system reminder in Claude's context:


Note: /path/to/aerospike.conf was modified, either by the user or by a linter.


This fires repeatedly with the old content, overriding what Claude just wrote. From Claude's perspective the file looks like the pre-edit version, while `git show HEAD -- aerospike.conf` and `md5` of the on-disk file both confirm the correct post-edit content was committed and is on disk.

Steps to Reproduce

  1. Set up a repo with a pre-commit hook that modifies files in-place (e.g. trailing-whitespace from pre-commit-hooks v5.0.0)
  2. Ask Claude Code to edit a non-Python config file (e.g. .conf)
  3. Claude edits the file correctly
  4. Claude attempts to commit — pre-commit hook fails on first try, modifies the file in-place, Claude re-stages and commits successfully
  5. In the next turn, ask Claude to check the file contents
  6. Claude reports the pre-edit content, not the committed version
  7. Verify with git show HEAD -- <file> — committed content is correct
  8. Verify with md5 <file> — on-disk file is correct
  9. Only Claude Code's internal state is stale

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.85 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Environment

  • OS: macOS 14 (Darwin 24.4.0)
  • Pre-commit hooks: pre-commit-hooks v5.0.0 (trailing-whitespace, end-of-file-fixer)
  • File type: .conf (non-Python, no ruff/mypy involvement)
  • Claude Code model: claude-sonnet-4-6

Workaround

Have the user commit manually — Claude Code's stale state does not affect the actual on-disk file or git history.

extent analysis

TL;DR

Claude Code's internal state can be updated to reflect the committed file content by re-reading the file after a successful commit, potentially by integrating with the pre-commit hook or using a file system watcher.

Guidance

  • Investigate how Claude Code updates its internal file state after a commit, and consider re-reading the file from disk to ensure it reflects the committed content.
  • Review the pre-commit hook implementation to see if it provides any callbacks or notifications that Claude Code can use to update its internal state.
  • Consider using a file system watcher to monitor changes to the file and update Claude Code's internal state accordingly.
  • Verify that the issue is specific to the trailing-whitespace pre-commit hook or if it occurs with other hooks as well.

Example

No specific code example can be provided without more information on Claude Code's internal implementation, but a potential solution might involve adding a callback to the pre-commit hook to update Claude Code's internal state after the hook has modified the file.

Notes

The issue seems to be related to Claude Code's internal state not being updated after a pre-commit hook modifies the file, but the actual on-disk file and git history are correct. The workaround of having the user commit manually suggests that the issue is specific to Claude Code's automation.

Recommendation

Apply workaround: Have the user commit manually until a fix can be implemented, as this ensures the actual on-disk file and git history are correct, even if Claude Code's internal state is stale.

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