[BUG] Infinitely repeated large <system-reminder> messages in Claude Code CLI in -p (headless) mode

Status Fixed / completed
Reported on v2.1.50
Maintainer reply None cached
Activity 8 comments · opened Feb 22, 2026 · closed Mar 31, 2026

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.

View original on GitHub ↗

8 Comments

github-actions[bot] · 6 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/16021
  2. https://github.com/anthropics/claude-code/issues/21693
  3. https://github.com/anthropics/claude-code/issues/21650

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

sstklen · 6 months ago

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:

  1. Locate the file change notification tracker (likely in the message construction pipeline that builds user turn payloads) — this is the component that checks which files have been modified since last read and injects <system-reminder> blocks
  2. Add a 'notification_shown' or 'acknowledged' state: after a <system-reminder> for a file edit is injected into a user message, mark that specific edit notification as consumed so it is not re-injected on the next turn
  3. For edits performed by the model itself (via Edit/Write tools), auto-clear the dirty flag immediately — the model already knows the new content since it authored the change, so no reminder is needed
  4. Add a deduplication guard: even if dirty flags persist, never inject the same file's <system-reminder> more than once per conversation turn, and cap the total size of injected reminders to prevent context window exhaustion
  5. In headless (-p) mode specifically, consider suppressing file-change reminders entirely or limiting them to a single compact line (filename + line range changed) rather than including surrounding file content
// Pseudocode for the fix in the message construction pipeline:

// BEFORE (buggy): notification persists until explicit Read
if (file.isDirty && !file.wasReadSinceEdit) {
  injectSystemReminder(file); // injected EVERY turn
}

// AFTER (fixed): notification shown once then cleared
if (file.isDirty && !file.wasReadSinceEdit && !file.notificationShown) {
  injectSystemReminder(file);
  file.notificationShown = true; // show-once semantics
}

// Also: auto-clear for model's own edits
function onEditToolComplete(filePath) {
  fileTracker.markAsRead(filePath); // model knows what it wrote
}

Hope this helps! Let me know if it doesn't match your case — happy to dig deeper. 🦞

_Disclosure: This analysis is from Confucius Debug, an AI-powered community KB for agent bugs. Please verify before applying._

---
<sub>🦞 Confucius Debug — community knowledge base for AI agent bugs. Free to search via MCP.</sub>

designbyian · 5 months ago

Still happening in version 2.1.71

designbyian · 5 months ago

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).

designbyian · 5 months ago

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

designbyian · 5 months ago

Still happening in 2.1.84

designbyian · 5 months ago

This appears to be fixed now, however the fix was not mentioned in release notes.

github-actions[bot] · 4 months ago

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.