claude-code - 💡(How to fix) Fix [BUG] `/clear` bleeds into the next session (what also breaks cache) [2 comments, 2 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#47756Fetched 2026-04-15 06:43:08
View on GitHub
Comments
2
Participants
2
Timeline
15
Reactions
0
Author
Timeline (top)
labeled ×4subscribed ×4commented ×2mentioned ×2

Error Message

Error Messages/Logs

Code Example

via ANTHROPIC_BASE_URL:

anthropicReq.messages: [
 {
  "role": "user",
  "content": [
   {
    "type": "text",
    "text": "<system-reminder>\nThe following skills are availabl...../ML.\n</system-reminder>\n"
   },
   {
    "type": "text",
    "text": "<system-reminder>\nAs you answer the user's ques.....hly relevant to your task.\n</system-reminder>\n\n"
   },
   {
    "type": "text",
    "text": "<local-command-caveat>Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.</local-command-caveat>\n"
   },
   {
    "type": "text",
    "text": "<command-name>/clear</command-name>\n            <command-message>clear</command-message>\n            <command-args></command-args>\n"
   },
   {
    "type": "text",
    "text": "<local-command-stdout></local-command-stdout>\n"
   },
   {
    "type": "text",
    "text": "alive?",
    "cache_control": {
     "type": "ephemeral"
    }
   }
  ]
 }
]

---

claude "alive?"
> /clear
> alive?
RAW_BUFFERClick to expand / collapse

What's Wrong?

When using /clear the new session has <local-command-caveat> artifacts left in messages.

This not only breaks (half) the prompt-cache, but is also "clearly wrong" so creating this issue here for it.</system-reminder> -> tools get cached, system-prompt gets cached, skills and project-claude.md do not

What Should Happen?

a /clear session should be indistinguishable from "relaunching claude" (and in fact should have an even higher chance to cache-hit, since the version sting & system-prompt will match)

Error Messages/Logs

via ANTHROPIC_BASE_URL:

anthropicReq.messages: [
 {
  "role": "user",
  "content": [
   {
    "type": "text",
    "text": "<system-reminder>\nThe following skills are availabl...../ML.\n</system-reminder>\n"
   },
   {
    "type": "text",
    "text": "<system-reminder>\nAs you answer the user's ques.....hly relevant to your task.\n</system-reminder>\n\n"
   },
   {
    "type": "text",
    "text": "<local-command-caveat>Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.</local-command-caveat>\n"
   },
   {
    "type": "text",
    "text": "<command-name>/clear</command-name>\n            <command-message>clear</command-message>\n            <command-args></command-args>\n"
   },
   {
    "type": "text",
    "text": "<local-command-stdout></local-command-stdout>\n"
   },
   {
    "type": "text",
    "text": "alive?",
    "cache_control": {
     "type": "ephemeral"
    }
   }
  ]
 }
]

Steps to Reproduce

claude "alive?"
> /clear
> alive?

observe massive cache-miss

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.105

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Xterm

Additional Information

Note that this is catalyzed by https://github.com/anthropics/claude-code/issues/47098 - but this is its own issue

extent analysis

TL;DR

The /clear command is not properly clearing the session, leaving behind artifacts in messages and causing cache misses.

Guidance

  • The issue seems to be related to the /clear command not properly removing all messages from the session, specifically the <local-command-caveat> artifacts.
  • To verify, try checking the anthropicReq.messages array after calling /clear to see if the artifacts are still present.
  • One possible workaround could be to manually remove the <local-command-caveat> artifacts from the messages array after calling /clear.
  • Investigate the code that handles the /clear command to see if there's a logic error or a missing step that's causing the artifacts to remain.

Example

No code snippet is provided as it's not clearly supported by the issue, but the anthropicReq.messages array could be checked and modified as follows:

// Example of what the messages array might look like
[
  {
    "role": "user",
    "content": [
      {
        "type": "text",
        "text": "<local-command-caveat>...</local-command-caveat>\n"
      },
      // ...
    ]
  }
]

// Potential workaround: remove the <local-command-caveat> artifact
const messages = anthropicReq.messages;
messages.forEach(message => {
  message.content = message.content.filter(part => !part.text.includes('<local-command-caveat>'));
});

Note that this is just a hypothetical example and may not be the actual solution.

Notes

The issue is related to a previous issue (https://github.com/anthropics/claude-code/issues/47098), but it's not clear if the fix for that issue will also fix this one. The Claude Code Version is 2.1.105, but it's not clear if upgrading to a newer version would fix the issue.

Recommendation

Apply workaround: manually remove the <local-command-caveat> artifacts from the messages array after calling /clear, as shown in the example above. This should help mitigate the issue until a more permanent fix can be found.

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