Skip to content

prompt is too long #5360

Closed as duplicate
Closed as duplicate

Description

@berenddeboer

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

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 11, 2025
  2. self-assigned this
    on Dec 11, 2025
  3. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 11, 2025
  4. arsham commented on Dec 11, 2025

    @arsham

    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.

  5. berenddeboer commented on Dec 11, 2025

    @berenddeboer
    Author

    Yeah, plenty of things going on.

  6. rekram1-node commented on Dec 11, 2025

    @rekram1-node
    Collaborator

    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!

  7. taxilian commented on Dec 15, 2025

    @taxilian

    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?

  8. taxilian commented on Dec 15, 2025

    @taxilian

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

  9. rekram1-node commented on Dec 15, 2025

    @rekram1-node
    Collaborator

    @taxilian could u share:

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

    opencode export > session.json

  10. taxilian commented on Dec 15, 2025

    @taxilian

    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.

  11. taxilian commented on Dec 15, 2025

    @taxilian

    session.json
    session2.json

    I think those are the same two

  12. taxilian commented on Dec 15, 2025

    @taxilian

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

  13. rekram1-node commented on Dec 16, 2025

    @rekram1-node
    Collaborator

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

  14. rekram1-node commented on Dec 16, 2025

    @rekram1-node
    Collaborator

    I think the proper pty should fix that

  15. ben-vargas commented on Dec 17, 2025

    @ben-vargas
    Contributor

    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).

  16. justcarlson commented on Dec 19, 2025

    @justcarlson

    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: []
      }
    ]
    ...
  17. ben-vargas commented on Dec 19, 2025

    @ben-vargas
    Contributor

    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
    
  18. justcarlson commented on Dec 19, 2025

    @justcarlson

    I am loving this idea

  19. CybotTM commented on Dec 19, 2025

    @CybotTM

    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. :-(

  20. guilllex commented on Dec 24, 2025

    @guilllex

    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! 🚀
    
  21. ben-vargas commented on Dec 27, 2025

    @ben-vargas
    Contributor

    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.

  22. PeterHa-UoH commented on Dec 30, 2025

    @PeterHa-UoH

    does anyone find a way to fix this?

  23. Traves-Theberge commented on Dec 31, 2025

    @Traves-Theberge

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

  24. rekram1-node commented on Dec 31, 2025

    @rekram1-node
    Collaborator

    fixing soon

  25. raadkasem commented on Feb 6, 2026

    @raadkasem

    Still getting this issue using opus 4.6 on February 2026

  26. MalteBoehm commented on Feb 15, 2026

    @MalteBoehm

    me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions