You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Extra usage is required for long context requests" error still occurs after Anthropic removed long-context premium (March 13) #18242
OpenCode shows "Extra usage is required for long context requests. retrying in Xs - attempt #N" and enters an infinite retry loop during long sessions. This error appears to be a stale handler for a restriction that Anthropic officially removed on March 13, 2026.
Anthropic's announcement (1M context GA, March 13 2026) explicitly states:
Full rate limits at every context length. Your standard account throughput applies across the entire window. No long-context premium. Claude Opus 4.6 and Sonnet 4.6 now include the full 1M context window at standard pricing.
Environment
OpenCode version: 1.2.27
Provider: Anthropic (Claude Max — OAuth, not API key)
Model: `anthropic/claude-sonnet-4-6`
Context at time of error: ~313,655 tokens (31% of 1M limit)
Platform: macOS
What happened
After ~20 minutes of a coding session, OpenCode displayed:
Extra usage is required for long context requests.
retrying in 3387s - attempt #14
The session was stuck retrying with a ~56 minute delay between attempts, making it completely unusable. The session had to be abandoned.
What should happen
With the long-context premium removed by Anthropic on March 13, this error should no longer occur. OpenCode should either:
Remove or update the handler for this specific error code/message, or
Fail gracefully with a clear message rather than an infinite retry loop with 3000+ second delays
Context panel at time of error
Context Limit: 1,000,000
Total Tokens: 313,655
Cache Tokens (read/write): 313,091 / 349
Usage: 31%
Messages: 200 (190 assistant, 10 user)
Additional notes
The retry interval of 3387 seconds (56 minutes) and attempt #14 suggest this had been retrying silently for an extended period before surfacing in the UI. The retry behavior itself may also warrant review — exponential backoff with this ceiling is not user-friendly for what should now be a non-existent restriction.
Additional findings after source code review + further testing
1. The error is intermittent, not threshold-based
A subsequent session reached 450,743 tokens (45% of 1M) on the same model/provider with no error. This confirms the error is not triggered by a fixed token count — it appears to be an Anthropic-side capacity issue for Claude Max OAuth requests that only surfaces occasionally.
2. Root cause identified in retry.ts
Two bugs compound the problem:
No cap on retry-after header values — delay() in retry.ts directly passes the retry-after header value from Anthropic with no maximum cap. When Anthropic returns retry-after: 3387, OpenCode waits 56 minutes per attempt with no bound.
"Extra usage required" treated as indefinitely retryable — retryable() returns the message string for any retryable API error, causing the while loop in processor.ts to retry forever. There is no escape hatch for this specific error type.
Suggested fix in packages/opencode/src/session/retry.ts:
// 1. Cap retry-after header at RETRY_MAX_DELAY_NO_HEADERS (30s)returnMath.min(Math.ceil(parsedSeconds*1000),RETRY_MAX_DELAY_NO_HEADERS)// 2. Treat "Extra usage is required" as non-retryableif(error.data.responseBody?.includes("Extra usage is required")||error.data.message?.includes("Extra usage is required"))returnundefined
3. Tool calls dominate context in active sessions
Context breakdown at 450K: Tool Calls 87.5%, Other 12.5%. The system prompt baseline (~132K) is not the primary growth driver — accumulated tool outputs are. This is relevant context for the compaction/prune behavior as well.
Root Cause Found: [email protected] sends a header Anthropic rejects for OAuth
After extensive debugging, I found the actual cause. It's not a stale retry handler or a context-length issue — it's the deprecated builtin plugin [email protected] injecting context-1m-2025-08-07 into the anthropic-beta header, which Anthropic actively rejects for OAuth tokens.
The Problem
The published [email protected] (deprecated on npm, maintained by thdxr) hardcodes these required betas:
// node_modules/opencode-anthropic-auth/index.mjsconstrequiredBetas=["claude-code-20250219","oauth-2025-04-20","context-1m-2025-08-07",// ← THIS CAUSES THE ERROR"interleaved-thinking-2025-05-14","prompt-caching-scope-2026-01-05",];
Anthropic's API rejectscontext-1m-2025-08-07 when sent with an OAuth Bearer token — returning the "Extra usage is required for long context requests" error. This happens on every request, regardless of actual context size. Even a brand new session with <10K tokens gets rejected.
Despite the March 13 GA announcement saying "no beta header required," the reality is:
Withoutcontext-1m-2025-08-07: OAuth requests work fine, and 1M context works automatically (tested at 281K tokens with Sonnet 4.6)
Withcontext-1m-2025-08-07: OAuth requests are rejected at any context size
The Fix
Remove context-1m-2025-08-07 from the plugin's requiredBetas array. The header is not needed post-GA and actively breaks OAuth authentication.
Patch for ~/.cache/opencode/node_modules/opencode-anthropic-auth/index.mjs:
After this change, both short and long-context requests work correctly through OAuth. Successfully tested at 281K tokens with anthropic/claude-sonnet-4-6 on a Max plan.
Note: The fix needs to be re-applied any time the plugin is re-downloaded (cache clear, reinstall, etc.) since the npm package itself ships with the broken header.
Additional Context
The binary's CUSTOM_LOADERS["anthropic"] headers are irrelevant — the opencode-anthropic-auth plugin's chat.headers hook overwrites them entirely
The plugin is marked as DEPRECATED on npm — unclear if it's being maintained or if auth was supposed to be internalized into the OpenCode binary
This also affects the retry behavior from the original issue: the infinite retry loop with 3387s delays is because OpenCode's retry.ts treats the 429 response as retryable and honors Anthropic's retry-after header. But the real fix is preventing the rejection in the first place.
# Before fix: fails immediately on any Anthropic request
opencode run -m anthropic/claude-sonnet-4-6 "say hello"# → "Extra usage is required for long context requests"# After fix: works, including >200K token requests
opencode run -m anthropic/claude-sonnet-4-6 "count fox" -f large-file.txt
# → 25000 (281K tokens, no error)
This looks like two independent issues getting collapsed into one failure mode.
1) Root cause (request rejection)
The OAuth + context-1m-2025-08-07 header mismatch is causing the request to be rejected upstream. That part seems correctly identified above.
2) Execution behavior (retry loop)
What’s interesting is how the system responds after that rejection:
retry-after: 3387 is treated as fully authoritative
Activity
coolbossov commentedon Mar 19, 2026
Additional findings after source code review + further testing
1. The error is intermittent, not threshold-based
A subsequent session reached 450,743 tokens (45% of 1M) on the same model/provider with no error. This confirms the error is not triggered by a fixed token count — it appears to be an Anthropic-side capacity issue for Claude Max OAuth requests that only surfaces occasionally.
2. Root cause identified in
retry.tsTwo bugs compound the problem:
No cap on
retry-afterheader values —delay()inretry.tsdirectly passes theretry-afterheader value from Anthropic with no maximum cap. When Anthropic returnsretry-after: 3387, OpenCode waits 56 minutes per attempt with no bound."Extra usage required" treated as indefinitely retryable —
retryable()returns the message string for any retryable API error, causing the while loop inprocessor.tsto retry forever. There is no escape hatch for this specific error type.Suggested fix in
packages/opencode/src/session/retry.ts:3. Tool calls dominate context in active sessions
Context breakdown at 450K: Tool Calls 87.5%, Other 12.5%. The system prompt baseline (~132K) is not the primary growth driver — accumulated tool outputs are. This is relevant context for the compaction/prune behavior as well.
davetha commentedon Mar 19, 2026
Root Cause Found:
[email protected]sends a header Anthropic rejects for OAuthAfter extensive debugging, I found the actual cause. It's not a stale retry handler or a context-length issue — it's the deprecated builtin plugin
[email protected]injectingcontext-1m-2025-08-07into theanthropic-betaheader, which Anthropic actively rejects for OAuth tokens.The Problem
The published
[email protected](deprecated on npm, maintained bythdxr) hardcodes these required betas:Anthropic's API rejects
context-1m-2025-08-07when sent with an OAuth Bearer token — returning the "Extra usage is required for long context requests" error. This happens on every request, regardless of actual context size. Even a brand new session with <10K tokens gets rejected.Despite the March 13 GA announcement saying "no beta header required," the reality is:
context-1m-2025-08-07: OAuth requests work fine, and 1M context works automatically (tested at 281K tokens with Sonnet 4.6)context-1m-2025-08-07: OAuth requests are rejected at any context sizeThe Fix
Remove
context-1m-2025-08-07from the plugin'srequiredBetasarray. The header is not needed post-GA and actively breaks OAuth authentication.Patch for
~/.cache/opencode/node_modules/opencode-anthropic-auth/index.mjs:const requiredBetas = [ "claude-code-20250219", "oauth-2025-04-20", - "context-1m-2025-08-07", "interleaved-thinking-2025-05-14", "prompt-caching-scope-2026-01-05", ];After this change, both short and long-context requests work correctly through OAuth. Successfully tested at 281K tokens with
anthropic/claude-sonnet-4-6on a Max plan.Note: The fix needs to be re-applied any time the plugin is re-downloaded (cache clear, reinstall, etc.) since the npm package itself ships with the broken header.
Additional Context
CUSTOM_LOADERS["anthropic"]headers are irrelevant — theopencode-anthropic-authplugin'schat.headershook overwrites them entirelyretry.tstreats the 429 response as retryable and honors Anthropic'sretry-afterheader. But the real fix is preventing the rejection in the first place.context-1m— same conclusion we reached independentlyVerification
rawscripter commentedon Mar 19, 2026
@davetha it worked.
vinzabe commentedon Apr 10, 2026
here's the fix, obfuscated it so anthropic wont know how it is done. https://github.com/vinzabe/opencode-anthropic-max-fix/tree/master
SirBrenton commentedon Apr 10, 2026
This looks like two independent issues getting collapsed into one failure mode.
1) Root cause (request rejection)
The OAuth +
context-1m-2025-08-07header mismatch is causing the request to be rejected upstream. That part seems correctly identified above.2) Execution behavior (retry loop)
What’s interesting is how the system responds after that rejection:
retry-after: 3387is treated as fully authoritativeSo the system ends up doing:
At that point it’s no longer a retry strategy — it’s a stalled execution loop.
What’s missing is a classification step before retry
Right now the system effectively treats all 429-like responses as:
But in practice these tend to fall into different buckets:
This case looks closer to the last category once the header mismatch is present.
Concrete improvements (independent of root fix):
retry-after(e.g. 30–60s max inside a single execution)retry-aftervalues as terminal for the current runFixing the header removes the trigger, but without these guards the same pattern can reappear with other provider responses.
xNarkon commentedon Apr 19, 2026
Any update?
github-actions commentedon Jul 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.