prompt is too long #3462

Closed
opened 2026-02-16 17:40:10 -05:00 by yindo · 23 comments
Owner

Originally created by @berenddeboer on GitHub (Dec 11, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

Got this twice today:

prompt is too long: 202744 tokens > 200000 maximum

OpenCode version

1.0.143 (I think, version used to be visible all th etime, but no longer)

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

Ubuntu 24.04

Terminal

Alacritty/tmux

Originally created by @berenddeboer on GitHub (Dec 11, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description Got this twice today: ``` prompt is too long: 202744 tokens > 200000 maximum ``` ### OpenCode version 1.0.143 (I think, version used to be visible all th etime, but no longer) ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System Ubuntu 24.04 ### Terminal Alacritty/tmux
yindo added the bug label 2026-02-16 17:40:10 -05:00
yindo closed this issue 2026-02-16 17:40:10 -05:00
Author
Owner

@arsham commented on GitHub (Dec 11, 2025):

Was there a tool call just before that? If that was the case, the result of the tool call must have been large. Your only option is to run /undo and then add an additional guidance to the agent to be more careful.

@arsham commented on GitHub (Dec 11, 2025): Was there a tool call just before that? If that was the case, the result of the tool call must have been large. Your only option is to run `/undo` and then add an additional guidance to the agent to be more careful.
Author
Owner

@berenddeboer commented on GitHub (Dec 11, 2025):

Yeah, plenty of things going on.

@berenddeboer commented on GitHub (Dec 11, 2025): Yeah, plenty of things going on.
Author
Owner

@rekram1-node commented on GitHub (Dec 11, 2025):

I'm gonna make it more resilient to these things soon, @arsham nails it w/ suggestion but ofc this isn't really an "acceptable" ux for you guys and that's on us. Will be better soon!

@rekram1-node commented on GitHub (Dec 11, 2025): I'm gonna make it more resilient to these things soon, @arsham nails it w/ suggestion but ofc this isn't really an "acceptable" ux for you guys and that's on us. Will be better soon!
Author
Owner

@taxilian commented on GitHub (Dec 15, 2025):

I haven't seen this much lately, things have been fantastic... but today suddenly it's happened now three times in a row doing different tasks. Did anything change recently?

@taxilian commented on GitHub (Dec 15, 2025): I haven't seen this much lately, things have been fantastic... but today suddenly it's happened now three times in a row doing different tasks. Did anything change recently?
Author
Owner

@taxilian commented on GitHub (Dec 15, 2025):

can't even undo and auto compact, it's failing on the compact message

@taxilian commented on GitHub (Dec 15, 2025): can't even undo and auto compact, it's failing on the compact message
Author
Owner

@rekram1-node commented on GitHub (Dec 15, 2025):

@taxilian could u share:

  • what model/provider it happened with
  • the session?

opencode export > session.json

@rekram1-node commented on GitHub (Dec 15, 2025): @taxilian could u share: - what model/provider it happened with - the session? `opencode export > session.json`
Author
Owner

@taxilian commented on GitHub (Dec 15, 2025):

It just happened again.

This is with claude opus 4.5, anthropic pro plan.

The other session is in a weird state now because it's the one I tried to fix. This is exactly the same thing I was working on Friday / Saturday though and haven't seen this issue before, now it keeps happening left and right.

@taxilian commented on GitHub (Dec 15, 2025): It just happened again. This is with claude opus 4.5, anthropic pro plan. * https://opncd.ai/share/b6z1zV7h * https://opncd.ai/share/HNLgGiUx The other session is in a weird state now because it's the one I tried to fix. This is exactly the same thing I was working on Friday / Saturday though and haven't seen this issue before, now it keeps happening left and right.
Author
Owner

@taxilian commented on GitHub (Dec 15, 2025):

session.json
session2.json

I think those are the same two

@taxilian commented on GitHub (Dec 15, 2025): [session.json](https://github.com/user-attachments/files/24176402/session.json) [session2.json](https://github.com/user-attachments/files/24176403/session2.json) I think those are the same two
Author
Owner

@taxilian commented on GitHub (Dec 15, 2025):

I am on the community discord server if that's useful. still trying to make this work

@taxilian commented on GitHub (Dec 15, 2025): I am on the community discord server if that's useful. still trying to make this work
Author
Owner

@rekram1-node commented on GitHub (Dec 15, 2025):

It looks like it's because of the "bd" cmd in bash it's absolutely devouring tokens

@rekram1-node commented on GitHub (Dec 15, 2025): It looks like it's because of the "bd" cmd in bash it's absolutely devouring tokens
Author
Owner

@rekram1-node commented on GitHub (Dec 15, 2025):

I think the proper pty should fix that

@rekram1-node commented on GitHub (Dec 15, 2025): I think the proper pty should fix that
Author
Owner

@ben-vargas commented on GitHub (Dec 17, 2025):

Yeah, I'm running into similar error a ton, haven't been able to reliably use opencode for a few versions now. This is on the latest v1.0.164 and there was a firecrawl scrape right before truncation failed to work?

Image

Also opus 4.5 (max plan).

@ben-vargas commented on GitHub (Dec 17, 2025): Yeah, I'm running into similar error a ton, haven't been able to reliably use opencode for a few versions now. This is on the latest v1.0.164 and there was a firecrawl scrape right before truncation failed to work? <img width="2300" height="482" alt="Image" src="https://github.com/user-attachments/assets/5997b4c8-9169-4f1e-8eb1-60df3ed61aca" /> Also opus 4.5 (max plan).
Author
Owner

@justcarlson commented on GitHub (Dec 18, 2025):

session.json

Also running into this a lot.
It's definitely large tool calls that are devouring context.
Probably because of bd (but it's so good).
Model: Anthropic/Claude Opus 4.5
If I switch model to Gemini, it's fine (mostly).
Truncation isn't aggressive enough, I think.

Cleaned up JSON from my session showing where it all went wrong.

[
  {
    info: {
      id: msg_b3475413b001geGkBJYoGtUd0o,
      role: assistant,
      modelID: claude-opus-4-5,
      tokens: {
        input: 6,
        output: 10586,
        cache: { read: 68795, write: 12195 }
      },
      finish: tool-calls
    },
    parts: [
      {
        type: reasoning,
        text: Good, test file cleaned up. Now I need to push these commits to the PR and update the PR.
      },
      {
        type: tool,
        tool: bash,
        state: {
          status: completed,
          input: {
            command: git push 2>&1,
            description: Push cleanup commits,
            env: {
              /* ... [21,965 character-indexed entries truncated] ... */
              CI: true,
              DEBIAN_FRONTEND: noninteractive,
              GIT_TERMINAL_PROMPT: 0,
              GCM_INTERACTIVE: never,
              HOMEBREW_NO_AUTO_UPDATE: 1
            }
          },
          output: To https://github.com/justcarlson/dotfiles.git\n   d263a20..f890276  feat/beads-init -> feat/beads-init\n,
          time: {
            start: 1766111786187,
            end: 1766111786842
          }
        }
      }
    ]
  },
  {
    info: {
      id: msg_b3477378e001PSDz7CbpYGme0T,
      role: assistant,
      error: {
        name: APIError,
        data: {
          message: prompt is too long: 212032 tokens > 200000 maximum,
          statusCode: 400,
          responseBody: {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 212032 tokens > 200000 maximum"},"request_id":"req_011CWFGUE8UeR24su49Cs3jB"}
        }
      }
    },
    parts: []
  }
]
...
@justcarlson commented on GitHub (Dec 18, 2025): [session.json](https://github.com/user-attachments/files/24249784/session.json) Also running into this a lot. It's definitely large tool calls that are devouring context. Probably because of bd (but it's so good). Model: Anthropic/Claude Opus 4.5 If I switch model to Gemini, it's fine (mostly). Truncation isn't aggressive enough, I think. Cleaned up JSON from my session showing where it all went wrong. ```json [ { info: { id: msg_b3475413b001geGkBJYoGtUd0o, role: assistant, modelID: claude-opus-4-5, tokens: { input: 6, output: 10586, cache: { read: 68795, write: 12195 } }, finish: tool-calls }, parts: [ { type: reasoning, text: Good, test file cleaned up. Now I need to push these commits to the PR and update the PR. }, { type: tool, tool: bash, state: { status: completed, input: { command: git push 2>&1, description: Push cleanup commits, env: { /* ... [21,965 character-indexed entries truncated] ... */ CI: true, DEBIAN_FRONTEND: noninteractive, GIT_TERMINAL_PROMPT: 0, GCM_INTERACTIVE: never, HOMEBREW_NO_AUTO_UPDATE: 1 } }, output: To https://github.com/justcarlson/dotfiles.git\n d263a20..f890276 feat/beads-init -> feat/beads-init\n, time: { start: 1766111786187, end: 1766111786842 } } } ] }, { info: { id: msg_b3477378e001PSDz7CbpYGme0T, role: assistant, error: { name: APIError, data: { message: prompt is too long: 212032 tokens > 200000 maximum, statusCode: 400, responseBody: {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 212032 tokens > 200000 maximum"},"request_id":"req_011CWFGUE8UeR24su49Cs3jB"} } } }, parts: [] } ] ...
Author
Owner

@ben-vargas commented on GitHub (Dec 18, 2025):

I didn't post it here, but I did in a thread on their discord... my root cause (at least for my issue) is non-truncated mcp tool calls dumping too much into the context window. There should be a truncation of mcp and all tools, similar to the 30k limit on bash/internal tools.

I created a personal fix, but haven't PR'd it because opencode maintainers should probably weigh in on how they want to address this (truncation vs something like claude does - detailed below).

https://discord.com/channels/1391832426048651334/1450309314337308762

Image Image

Claude Code has a unique way of handling really large bash outputs that I noticed... I asked it to explain the approach:

  When a tool result is too large, Claude Code:

  1. Persists the full output to a file in the session folder:
  /Users/ben/.claude/projects/.../tool-results/mcp-firecrawl-firecrawl_scrape-1765980251222.txt
  2. Returns a helpful message to the model instead of the raw content:
  Error: result (1,055,387 characters) exceeds maximum allowed tokens.
  Output has been saved to /Users/ben/.claude/projects/.../tool-results/...
  Format: JSON array with schema: [{type: string, text: string}]
  Use offset and limit parameters to read specific portions of the file,
  the Grep tool to search for specific content, and jq to make structured queries.

  This is much better than truncation because:
  - Data isn't lost - the full output is preserved
  - Model can explore - using Read (with offset/limit), Grep, or jq
  - Context stays small - only the file path and instructions go into context

  Would you like me to update the fix to implement this pattern instead of simple truncation? It would involve:

  1. Writing large MCP outputs to .opencode/tool-results/ (or similar)
  2. Returning a message with the file path and exploration instructions
  3. The model can then use existing tools (Read, Grep, Bash with jq) to explore
@ben-vargas commented on GitHub (Dec 18, 2025): I didn't post it here, but I did in a thread on their discord... my root cause (at least for my issue) is non-truncated mcp tool calls dumping too much into the context window. There should be a truncation of mcp and all tools, similar to the 30k limit on bash/internal tools. I created a personal fix, but haven't PR'd it because opencode maintainers should probably weigh in on how they want to address this (truncation vs something like claude does - detailed below). https://discord.com/channels/1391832426048651334/1450309314337308762 <img width="1936" height="1562" alt="Image" src="https://github.com/user-attachments/assets/da5917fb-4b74-4c37-b1ad-9dbedca3f2db" /> <img width="1936" height="1538" alt="Image" src="https://github.com/user-attachments/assets/a160a327-73e9-4199-adde-c868d558a456" /> Claude Code has a unique way of handling really large bash outputs that I noticed... I asked it to explain the approach: ``` When a tool result is too large, Claude Code: 1. Persists the full output to a file in the session folder: /Users/ben/.claude/projects/.../tool-results/mcp-firecrawl-firecrawl_scrape-1765980251222.txt 2. Returns a helpful message to the model instead of the raw content: Error: result (1,055,387 characters) exceeds maximum allowed tokens. Output has been saved to /Users/ben/.claude/projects/.../tool-results/... Format: JSON array with schema: [{type: string, text: string}] Use offset and limit parameters to read specific portions of the file, the Grep tool to search for specific content, and jq to make structured queries. This is much better than truncation because: - Data isn't lost - the full output is preserved - Model can explore - using Read (with offset/limit), Grep, or jq - Context stays small - only the file path and instructions go into context Would you like me to update the fix to implement this pattern instead of simple truncation? It would involve: 1. Writing large MCP outputs to .opencode/tool-results/ (or similar) 2. Returning a message with the file path and exploration instructions 3. The model can then use existing tools (Read, Grep, Bash with jq) to explore ```
Author
Owner

@justcarlson commented on GitHub (Dec 18, 2025):

I am loving this idea

@justcarlson commented on GitHub (Dec 18, 2025): I am loving this idea
Author
Owner

@CybotTM commented on GitHub (Dec 19, 2025):

Not sure if this #5360 or #1092 or #4845 are all about the same or more specific different issues, so I just post here: me too! ;-)

Run into this every time on /compact ... sadly, but this makes OpenCode currently unusable for me. :-(

@CybotTM commented on GitHub (Dec 19, 2025): Not sure if this #5360 or #1092 or #4845 are all about the same or more specific different issues, so I just post here: me too! ;-) Run into this every time on /compact ... sadly, but this makes OpenCode currently unusable for me. :-(
Author
Owner

@guilllex commented on GitHub (Dec 24, 2025):

I have the same problem with opencode , claude opus 4.5 and BMAD, I asked the agent to try to fix the probleme

Done! The session should now work.

 Summary of the Root Cause & Fix                                                                                                                                                                                                  
                                                                                                                                                                                                                                  
 Root Cause: OpenCode stores ALL tool outputs (webfetch, read, write, task results) in the session history. When you fetch large web pages or read large files, they accumulate and                                               
 eventually exceed the 200K token limit.                                                                                                                                                                                          
                                                                                                                                                                                                                                  
 What I Fixed:                                                                                                                                                                                                                    
 - Truncated 20+ large parts in your session                                                                                                                                                                                      
 - Reduced session from ~330KB to ~123KB                                                                                                                                                                                          
 - Estimated tokens: from 200K+ down to ~47K                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                  
 To Prevent This in Future:                                                                                                                                                                                                       
 1. Avoid using webfetch on large documentation pages                                                                                                                                                                             
 2. If you need to read large files, summarize them rather than keeping full content                                                                                                                                              
 3. Consider starting a new session when doing research-heavy work with lots of webfetches                                                                                                                                        
 4. OpenCode should ideally have auto-truncation, but until then, be mindful of large fetches                                                                                                                                     
                                                                                                                                                                                                                                  
 Try your session now! 🚀
@guilllex commented on GitHub (Dec 24, 2025): I have the same problem with opencode , claude opus 4.5 and BMAD, I asked the agent to try to fix the probleme Done! The session should now work. Summary of the Root Cause & Fix Root Cause: OpenCode stores ALL tool outputs (webfetch, read, write, task results) in the session history. When you fetch large web pages or read large files, they accumulate and eventually exceed the 200K token limit. What I Fixed: - Truncated 20+ large parts in your session - Reduced session from ~330KB to ~123KB - Estimated tokens: from 200K+ down to ~47K To Prevent This in Future: 1. Avoid using webfetch on large documentation pages 2. If you need to read large files, summarize them rather than keeping full content 3. Consider starting a new session when doing research-heavy work with lots of webfetches 4. OpenCode should ideally have auto-truncation, but until then, be mindful of large fetches Try your session now! 🚀
Author
Owner

@ben-vargas commented on GitHub (Dec 26, 2025):

I ended up creating #6234 for this since I had to patch this in my local fork I use, opencode was pretty unusable for me without it and I couldn't wait for a fix. Not sure if opencode team will accept it, but at least it is shared here so others can merge it onto their own versions if desired.

@ben-vargas commented on GitHub (Dec 26, 2025): I ended up creating #6234 for this since I had to patch this in my local fork I use, opencode was pretty unusable for me without it and I couldn't wait for a fix. Not sure if opencode team will accept it, but at least it is shared here so others can merge it onto their own versions if desired.
Author
Owner

@PeterHa-UoH commented on GitHub (Dec 30, 2025):

does anyone find a way to fix this?

@PeterHa-UoH commented on GitHub (Dec 30, 2025): does anyone find a way to fix this?
Author
Owner

@Traves-Theberge commented on GitHub (Dec 31, 2025):

Same issue specifically when running up services for docker compose.. and using Claude code. it doesn't condense and summarize properly.

@Traves-Theberge commented on GitHub (Dec 31, 2025): Same issue specifically when running up services for docker compose.. and using Claude code. it doesn't condense and summarize properly.
Author
Owner

@rekram1-node commented on GitHub (Dec 31, 2025):

fixing soon

@rekram1-node commented on GitHub (Dec 31, 2025): fixing soon
Author
Owner

@raadkasem commented on GitHub (Feb 6, 2026):

Still getting this issue using opus 4.6 on February 2026

@raadkasem commented on GitHub (Feb 6, 2026): Still getting this issue using opus 4.6 on February 2026
Author
Owner

@MalteBoehm commented on GitHub (Feb 15, 2026):

me too

@MalteBoehm commented on GitHub (Feb 15, 2026): me too
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3462