[FEATURE] Add a configurable token usage threshold to pause or stop Claude Code execution

Resolved 💬 4 comments Opened Apr 23, 2026 by Weryth Closed May 28, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] 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_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗