False "Context limit reached" on Sonnet 5 well below reported usage — not specific to skill loading
Description
"Context limit reached · /compact or /clear to continue" fires despite /context reporting only a small fraction of usage moments before. The claude-api skill was one confirmed trigger, but this is not specific to skill loading — I've since seen the same failure in other sessions with no skill invocation involved at all. This appears related to #69179, but that report was filed against Sonnet 4.6 — I'm only able to reproduce this on Sonnet 5 (claude-sonnet-5).
Repro steps (one confirmed instance, via the claude-api skill)
/clear/context→ reports 15.6k/200k tokens (8%): System prompt 8.6k, Custom agents 1.5k, Memory files 3.1k, Skills 2.3k, Messages 137 tokens, Free space 151.4k (75.7%), Autocompact buffer 33k (16.5%)- Ask a short question ("does Sonnet 5 have adaptive thinking? Do I need to change any settings to enable it?")
- Claude invokes the
claude-apiskill (Skill(claude-api)→ "Successfully loaded skill · 4 tools allowed") - Immediately: "Context limit reached · /compact or /clear to continue" — no assistant response produced.
Note: skill loading is not required to reproduce this — it has recurred in unrelated sessions with no skill invocation nearby.
Expected behavior
/context's reported percentage should reflect what the actual enforcement check uses, or the limit should not trip while substantial free space is still reported.
Additional observation
In a later, unrelated exchange in the same investigation, dispatching one background Agent call plus a couple of /context calls (including two pastes of raw /context terminal output) increased the "Messages" category from 137 tokens to 86.1k tokens, while System prompt/Custom agents/Memory/Skills stayed exactly flat. This suggests /context's per-category breakdown itself may not be a reliable predictor of when the hard limit will trip — consistent with the theory in #28167 that the displayed percentage only counts input tokens while the real limit check includes output + cache tokens.
Environment
- Model: claude-sonnet-5
- Related issues: #69179 (same claude-api skill trigger, filed on Sonnet 4.6/Foundry, unconfirmed), #28167 (input-only token counting theory), #46318, #20455, #24458, #18159, #19018, #34158 (same class of premature context-limit bug)
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗