False "Context limit reached" at 21% context after loading claude-api skill
Claude Code bug report: false "Context limit reached" at 21% context
Summary
Claude Code reported Context limit reached · /compact or /clear to continue · /model sonnet[1m] immediately after loading the built-in claude-api skill, even though /context and the statusline both showed the session was far below the configured 200k context window.
This appears to be a context accounting, skill-loading, or provider-specific bug. The observed session had only about 42k tokens in use when the limit error appeared.
Environment
- OS/shell: Windows PowerShell
- Working directory:
C:\Users\peter.washburn\scratch - Claude Code version:
2.1.179 - Model shown by Claude Code:
Sonnet 4.6 - Provider/backend shown by Claude Code:
Microsoft Foundry - Model deployment shown in
/context:claude-sonnet-4-6 - Auto-compact window shown in
/context:200k tokens - Foundry setup variables documented locally:
CLAUDE_CODE_USE_FOUNDRY=1ANTHROPIC_FOUNDRY_RESOURCE=codex-cli-rsrcANTHROPIC_FOUNDRY_USE_ENTRA=1ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-6ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5
Reproduction steps
- Run
claude update. - Confirm Claude Code reports it is up to date at version
2.1.179. - Start Claude Code from PowerShell in
C:\Users\peter.washburn\scratch. - Run
/context. - Ask Claude Code:
``text``
I want to update the cost factors in $env:USERPROFILE\.claude\statusline.ps1 to reflect the current costs
- Claude Code reads
C:\Users\peter.washburn\.claude\statusline.ps1. - Claude Code loads the built-in
claude-apiskill. - Claude Code immediately reports
Context limit reached.
Expected behavior
Claude Code should continue the task. The session is well below the advertised 200k context window and still has substantial free space.
Actual behavior
Claude Code stops immediately after loading the claude-api skill:
● Skill(claude-api)
⎿ Successfully loaded skill · 4 tools allowed
⎿ Context limit reached · /compact or /clear to continue · /model sonnet[1m]
The statusline at the same time shows:
[Sonnet 4.6] ~$0.4054 | 21% ctx | 2m 42428 tokens
Evidence from /context
Before the prompt, /context reported:
24.2k/200k tokens (12%)
Estimated usage by category
System prompt: 6.2k tokens (3.1%)
System tools: 13.7k tokens (6.9%)
Memory files: 148 tokens (0.1%)
Skills: 4.2k tokens (2.1%)
Messages: 8 tokens (0.0%)
Free space: 142.8k (71.4%)
Autocompact buffer: 33k tokens (16.5%)
Auto-compact window: 200k tokens
After the failure, the statusline reported:
42428 tokens
21% ctx
The failure is inconsistent with both readings.
Suspicious configuration detail
The /context output shows duplicated Azure MCP tool registrations:
mcp__Azure-MCP-Server__...mcp__plugin_azure_azure__...
The same Azure tool families appear under both prefixes. This likely wastes tool/context budget, but it still does not explain a hard context-limit failure at roughly 21% of a 200k window.
Additional UI anomaly
On startup, the Claude Code welcome frame appears duplicated/nested:
╭─── Claude Code v2.1.179 ...
│ │ Tips for getting started
╭─── Claude Code v2.1.179 ...
│ │ Tips for getting started
This may be unrelated terminal rendering behavior, but it occurred in the same session.
Raw session artifact
The raw captured transcript is available locally at:
C:\Users\peter.washburn\scratch\claude-session.txt
Hypothesis
This looks like one of:
- Claude Code incorrectly applying a smaller context limit after skill loading.
- A bug in context accounting for the
claude-apiskill. - A provider/backend-specific limit mismatch when using
Sonnet 4.6 · Microsoft Foundry. - Tool/schema accounting issues caused or amplified by duplicate Azure MCP registrations.
Impact
The session becomes unusable for a simple task despite reporting substantial remaining context. The suggested remedies /compact and /clear are misleading because the session is not close to the reported context limit.
3 Comments
Was having the same issue, but doesn't seem like widely discussed over the web. I had to disable the invoke from claude.md.
I have the same issue, really frustrating
Confirming this on a completely different platform/provider/model combination, and with one correction to the framing that I think matters for triage: this is not a long-context problem. It reproduces on a fresh process, on the first user prompt.
Environment
~/.local/share/claude/versions/2.1.220)tmux-256colorCLAUDE_CODE_USE_VERTEX=1)claude-opus-5) — note this is a 1M-token context model, and it still tripsCLAUDE_EFFORT=highRepro
claude(or/clear— identical result either way).what is diff between opus 5 and opus 4.8?claude-apiskill auto-fires.There is no prior conversation. Messages is effectively zero. The only things in the window are the system prompt, tools, memory files, and the skill that was just loaded.
Why I think this is worth separating from #81636
#81636 proposes that
/clearfails to reset a latched limit state. In my case/clearalso fails to recover — but I can't attribute that to a latch, because a brand-new process fails identically on its first prompt. The simpler explanation for both observations is that loadingclaude-apialone overruns (or is accounted as overrunning) the window, so it re-trips every time regardless of what/cleardoes or doesn't reset. Worth checking whether #81636 is actually a duplicate of this one rather than a distinct state-management bug.Interaction with #66643 makes this worse than it looks
#66643 documents that the
claude-apiskill's trigger list includes bare model names (Opus,Sonnet,Haiku,Fable) and the literal ANSI escape[1m. So the failure mode is self-reinforcing: any question about a Claude model — exactly the question the skill exists to answer — auto-loads a skill that then can't fit in the window, and the user gets a hard stop instead of an answer. The skill is unusable for its own primary use case.I answered my original question by
WebFetch-ingplatform.claude.com/docs/en/about-claude/models/overviewand the migration guide in a fresh session, which cost a few thousand tokens and worked fine. That's a reasonable sketch of a fix: the skill could fetch or lazily load its reference material rather than inlining the full multi-language corpus up front. Inspecting the 2.1.220 binary, there's a substantial set of embedded per-language references (Claude API and Managed Agents docs for C#, Java, Python, TypeScript, Ruby, Go, PHP, plus endpoint and onboarding references) — I couldn't cleanly total it from the stripped bundle, but loading all of it eagerly for a one-line model-comparison question is the wrong tradeoff regardless of the exact number.Workaround for anyone hitting this
disableBundledSkills: truein settings avoids it, but it's indiscriminate — it also removes/init,/review,/security-review,/simplify,/loop,dataviz,run, andupdate-config. There's no documented per-skill disable. AdisabledSkills: ["claude-api"]setting would be a useful stopgap while the size issue is addressed.