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
[v0.1.162] [Anthropic: Claude Sonnet 4]: AI_APICallError: input length and 'max_tokens' exceed context limit: 140740 + 64000 > 200000, decrease input length or 'max_tokens and try again #491
oh i see the issue it only does the compaction check when you send a message, if it's running in a loop for a while it can exceed it and not trigger compaction
@flybayer we need help @thdxr to fix it, all other tool in code agent space no have so high code quality. I try few in parallel with same codebase/prompts/model
every time i hit this, i have to kill and restart opencode. is there a better way? it gets this error when it tries to read a large webpage or largish (600k) file . also, would be nice if i could cut and paste the error instead of a screenshot, but copy /paste doesn't seem to work in opencode
For those looking for a workaround right now. I'm making very fine grained checklists to work through and put specific instructions in AGENTS.MD to stop and ask if you are ready to continue after checking off each item. It lets me manually eyeball the current context number and if its about to blow I get it to update where its up to in the checklist and restart a new session to continue.
I know this sounds cumbersome but its better than losing the whole chat.
The other challenge that happens when one of these errors pops is that you lose the last prompt you wrote so if it was very long it means a full rewrite of that one.
another strategy is to make the agent use a markdown file to store its plan and progress. that way you can continue in new sessions or if a session fails. also use compact at each checkpoint.
we upgraded to ai sdk v5 which paves the way to fix this issue - note there is no magic fix, what i'm planning to do here is run compaction in between if the context gets too big in the middle of a loop
Activity
ezynda3 commentedon Jun 28, 2025
Having the same issue. The default max output used to be 50000 for claude no? Context runs out way to quickly when set to 64k I think.
thdxr commentedon Jun 29, 2025
so it turns out if you specify max tokens it needs to be less than (max context - input) but it's hard to know the exact input up front
thinking about how to deal with this
joegearlesss commentedon Jun 29, 2025
@thdxr if you tell me some specific way to share debug information, I'll do it
thdxr commentedon Jun 29, 2025
the problem might be that auto compaction isn't happening - checking now
thdxr commentedon Jun 29, 2025
we have the following logic
for anthropic it should be (200,000 - 64,000) * 0.9 = 122,400
so i'm not sure how it got to 140,740
thdxr commentedon Jun 29, 2025
oh i see the issue it only does the compaction check when you send a message, if it's running in a loop for a while it can exceed it and not trigger compaction
to fix this we need to upgrade to v5 ai sdk
joegearlesss commentedon Jun 29, 2025
@thdxr I hit it every 30 minutes )
joegearlesss commentedon Jun 29, 2025
and /compact do not work for this case. restart and reopen session do not working for this case too
https://opencode.ai/s/WjniS1OH
[-]AI_APICallError: input length and 'max_tokens' exceed context limit: 140740 + 64000 > 200000, decrease input length or 'max_tokens and try again[/-][+][v0.1.162] [Anthropic: Claude Sonnet 4]: AI_APICallError: input length and 'max_tokens' exceed context limit: 140740 + 64000 > 200000, decrease input length or 'max_tokens and try again[/+]joegearlesss commentedon Jun 29, 2025
@thdxr if you can give me some way to continue sessions like this before redesign or update to v5, it will be great
oscaromsn commentedon Jul 2, 2025
same situation here when asking the agent to fetch some web content. currently my main reason to not use opencode more.
4 remaining items
flybayer commentedon Jul 4, 2025
this is rendering opencode unusable for me for even the most basic tasks, Context: building a new app package within a large monorepo.
joegearlesss commentedon Jul 5, 2025
@oscaromsn I understand you pain! But even with this bug code made with opencode have ijigen-level quality
joegearlesss commentedon Jul 5, 2025
@flybayer we need help @thdxr to fix it, all other tool in code agent space no have so high code quality. I try few in parallel with same codebase/prompts/model
stellarthemes commentedon Jul 7, 2025
every time i hit this, i have to kill and restart opencode. is there a better way? it gets this error when it tries to read a large webpage or largish (600k) file . also, would be nice if i could cut and paste the error instead of a screenshot, but copy /paste doesn't seem to work in opencode
hbthegreat commentedon Jul 9, 2025
For those looking for a workaround right now. I'm making very fine grained checklists to work through and put specific instructions in AGENTS.MD to stop and ask if you are ready to continue after checking off each item. It lets me manually eyeball the current context number and if its about to blow I get it to update where its up to in the checklist and restart a new session to continue.
I know this sounds cumbersome but its better than losing the whole chat.
The other challenge that happens when one of these errors pops is that you lose the last prompt you wrote so if it was very long it means a full rewrite of that one.
sockthedev commentedon Jul 9, 2025
another strategy is to make the agent use a markdown file to store its plan and progress. that way you can continue in new sessions or if a session fails. also use compact at each checkpoint.
thdxr commentedon Jul 9, 2025
we upgraded to ai sdk v5 which paves the way to fix this issue - note there is no magic fix, what i'm planning to do here is run compaction in between if the context gets too big in the middle of a loop
joegearlesss commentedon Jul 9, 2025
looks good
BernieSumption commentedon Jul 10, 2025
When this happens to me I run
/compactmanually and I can continue the session.thdxr commentedon Mar 25, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.
feat: agent compression, inspection logic, governance hooks (anomalyc…
feat: agent description compression with lazy loading (anomalyco#696)
fix: allow data:image/* URLs in markdown renderer (anomalyco#491)