[BUG] File reverts to previous content after pre-commit hook modifies it in-place
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?
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
- Set up a repo with a pre-commit hook that modifies files in-place (e.g.
trailing-whitespacefrompre-commit-hooks v5.0.0) - Ask Claude Code to edit a non-Python config file (e.g.
.conf) - Claude edits the file correctly
- Claude attempts to commit — pre-commit hook fails on first try, modifies the file in-place, Claude re-stages and commits successfully
- In the next turn, ask Claude to check the file contents
- Claude reports the pre-edit content, not the committed version
- Verify with
git show HEAD -- <file>— committed content is correct - Verify with
md5 <file>— on-disk file is correct - 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.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗