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.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗