claude-code - 💡(How to fix) Fix Feature request: clear_context tool for programmatic context reset [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#48690Fetched 2026-04-16 06:53:40
View on GitHub
Comments
2
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
commented ×2labeled ×2

Discovered while running a pipeline test session driven entirely from Discord. The user asked the agent to clear context after completing a task, and there was no way to do it without switching to the terminal.

Root Cause

Discovered while running a pipeline test session driven entirely from Discord. The user asked the agent to clear context after completing a task, and there was no way to do it without switching to the terminal.

Fix Action

Fix / Workaround

Current workaround

RAW_BUFFERClick to expand / collapse

Use case

When Claude Code is driven from an external interface (e.g., Discord via MCP plugin), the user can't easily type /clear in the terminal. The agent itself has no way to reset its context window programmatically.

This also applies to autonomous loops and long-running sessions where the agent recognizes its context is stale and wants to start fresh without user intervention.

Proposal

Add a built-in clear_context tool (similar to Read, Bash, etc.) that the agent can invoke to reset the conversation context. Same behavior as the /clear slash command but callable from within the conversation.

Current workaround

None — /clear is UI-only. The user must physically type it in the terminal or restart the session.

Context

Discovered while running a pipeline test session driven entirely from Discord. The user asked the agent to clear context after completing a task, and there was no way to do it without switching to the terminal.

extent analysis

TL;DR

Implement a clear_context tool that allows the agent to programmatically reset the conversation context.

Guidance

  • Investigate the feasibility of adding a clear_context tool to the existing set of built-in tools, such as Read and Bash.
  • Determine the required behavior and parameters for the clear_context tool to ensure it matches the functionality of the /clear slash command.
  • Consider the potential impact on autonomous loops and long-running sessions, where the agent may need to reset its context without user intervention.
  • Evaluate the need for any additional error handling or logging mechanisms to ensure the clear_context tool functions correctly in various scenarios.

Example

No code snippet is provided as the issue does not contain sufficient technical details to generate a specific example.

Notes

The implementation of the clear_context tool may require modifications to the agent's architecture and conversation management logic. Additionally, the tool's behavior and parameters should be carefully designed to ensure consistency with the existing /clear slash command.

Recommendation

Apply workaround: Implement the proposed clear_context tool to provide a programmatic way for the agent to reset its conversation context, addressing the current limitation of relying on user input or session restarts.

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