claude-code - 💡(How to fix) Fix [FEATURE] Add a configurable token usage threshold to pause or stop Claude Code execution [3 comments, 4 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#52302Fetched 2026-04-24 06:10:46
View on GitHub
Comments
3
Participants
4
Timeline
5
Reactions
0
Author
Timeline (top)
commented ×3labeled ×2

Fix Action

Fix / Workaround

{
  "contextWindowStopThreshold": 70
}

Why this matters:

  • Compaction loses context. Stopping at 70% lets the user decide whether to /clear, /compact, or continue manually.
  • Hooks (PreToolUse, PostToolUse, Stop) don't expose context usage metrics, so there's no reliable workaround today (see related issues #27969, #34340).
  • StatusLine is the only hook that receives remaining_percentage, but it cannot inject /clear or halt execution. Expected behavior: Claude Code pauses the agentic loop, displays a message like: "Context window at 70%. Session paused. Run /compact to summarize or /clear to start fresh." — and waits for user input.

Code Example

{
  "contextWindowStopThreshold": 70
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

Currently, Claude Code has no built-in way to automatically pause or stop an agentic session when the context window reaches a certain fill percentage. The only automated response available is auto-compaction, which summarizes context rather than halting execution.

Proposed Solution

What I'd like: A setting (e.g. in settings.json) that stops Claude Code's agentic loop when context usage reaches a user-defined threshold — for example, 70%. Something like:

{
  "contextWindowStopThreshold": 70
}

Why this matters:

  • Compaction loses context. Stopping at 70% lets the user decide whether to /clear, /compact, or continue manually.
  • Hooks (PreToolUse, PostToolUse, Stop) don't expose context usage metrics, so there's no reliable workaround today (see related issues #27969, #34340).
  • StatusLine is the only hook that receives remaining_percentage, but it cannot inject /clear or halt execution. Expected behavior: Claude Code pauses the agentic loop, displays a message like: "Context window at 70%. Session paused. Run /compact to summarize or /clear to start fresh." — and waits for user input.

This would give users meaningful control over long-running sessions without relying on lossy auto-compaction.

Alternative Solutions

No response

Priority

Medium - Would be very helpful

Feature Category

Configuration and settings

Use Case Example

No response

Additional Context

No response

extent analysis

TL;DR

Implement a contextWindowStopThreshold setting in settings.json to pause the agentic loop when the context window reaches a user-defined threshold.

Guidance

  • Introduce a new setting in settings.json to store the threshold value, e.g., "contextWindowStopThreshold": 70.
  • Modify the agentic loop to check the context usage against the threshold and pause execution when reached.
  • Display a message to the user indicating the session pause and provide options to /compact or /clear.
  • Consider adding a hook to expose context usage metrics, addressing related issues #27969 and #34340.

Example

{
  "contextWindowStopThreshold": 70
}

This example shows the proposed setting in settings.json.

Notes

The implementation details may vary depending on the existing codebase and architecture of Claude Code. The proposed solution requires modifications to the agentic loop and the addition of a new setting.

Recommendation

Apply workaround: Implement the contextWindowStopThreshold setting to provide users with control over long-running sessions, as the current auto-compaction feature is lossy and lacks flexibility.

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