[BUG] Infinitely repeated large <system-reminder> messages in Claude Code CLI in -p (headless) mode
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?
Summary: After user edits OR edits by claude code itself, <system-reminder> messages are attached to ALL subsequent user messages. These reminders include a block of lines from the file surrounding each edit. For significant edits this can be a large chunk of the file, injected on every turn. These messages compound with each new file edit and very quickly consume the session context window during any edit heavy session.
More details about the behavior of this bug can be found in the following report (from months ago) about the same issue in the Claude Code for VS Code extension. It appears to be an identical bug, there have been numerous reports from different users:
https://github.com/anthropics/claude-code/issues/16021
More details:
- Having claude code re-read the file usually clears the notifications. The only other way to stop them is to start a new session
- In some cases 2 reads are required to clear the
<system-reminder>for a particular file. This is the weirdest part and seems to have been introduced more recently.
What Should Happen?
The harness should only inject file edit reminders once and it should not inject them for claude code's own edits.
Error Messages/Logs
Steps to Reproduce
The bug happens nearly every time, early on there was a session I wasn't able to reproduce it in, but generally speaking it happens consistently if you just:
- Start a session in headless mode
- Request some file edits in the same session
- Observe <system-reminder> messages that are attached to your subsequent messages in the same session
Claude Model
None
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.50
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
Bear in mind that this bug also happens in the VS Code extension on Windows (as of the latest version) but it does not happen in claude code CLI in interactive mode, only in headless mode.
8 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Hey! I ran into a similar pattern in our bug knowledge base and thought this might help.
What's happening: Claude Code's file change notification system marks files as 'dirty' after Edit/Write tool calls and injects <system-reminder> blocks (containing surrounding lines from the edited file) into every subsequent user message turn. The bug is that these dirty flags are never automatically cleared after being shown once — they persist and compound with each new edit. The notification is only cleared when the model explicitly re-reads the file via the Read tool, which resets the dirty state. In headless (-p) mode this is especially severe because there is no interactive opportunity to notice and clear the accumulating reminders, so they silently consume the entire context window.
What worked for us:
The file change notification system should either: (1) clear the dirty/notification flag after the <system-reminder> has been injected once into the conversation (show-once semantics), or (2) automatically mark files as 'read' after the model itself performs an Edit/Write on them (since the model already knows the content it just wrote), or (3) at minimum, deduplicate repeated notifications for the same file across turns so they don't compound. The fact that re-reading clears the notification confirms the root cause is a missing state transition: edit sets dirty=true, but only an explicit Read sets dirty=false — there is no 'already shown' → 'cleared' transition.
Steps:
Hope this helps! Let me know if it doesn't match your case — happy to dig deeper. 🦞
---
<sub>🦞 Confucius Debug — community knowledge base for AI agent bugs. Free to search via MCP.</sub>
Still happening in version 2.1.71
Still happening in version 2.1.76 in headless mode. Interestingly, the bug now appears to be fixed in the VSCode extension version but without any mention in recent change logs. Possibly the fix was accidental.
In headless mode the bug has actually gotten worse. Previously it was possible to clear the repeated reminders by having the agent re-read the effected file. In the latest version re-reading only causes the repeated reminder to clear for 1 turn and then return on the next turn (and continue to repeat forever).
Still happening in 2.1.78, however re-reading the file now appears to be clearing the bug again, at least some of the time
Still happening in 2.1.84
This appears to be fixed now, however the fix was not mentioned in release notes.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.