opencode icon indicating copy to clipboard operation
opencode copied to clipboard

prompt is too long

Open berenddeboer opened this issue 2 weeks ago • 12 comments

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

berenddeboer avatar Dec 11 '25 05:12 berenddeboer

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 avatar Dec 11 '25 06:12 arsham

Yeah, plenty of things going on.

berenddeboer avatar Dec 11 '25 19:12 berenddeboer

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 avatar Dec 11 '25 19:12 rekram1-node

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 avatar Dec 15 '25 21:12 taxilian

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

taxilian avatar Dec 15 '25 21:12 taxilian

@taxilian could u share:

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

opencode export > session.json

rekram1-node avatar Dec 15 '25 22:12 rekram1-node

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.

taxilian avatar Dec 15 '25 22:12 taxilian

session.json session2.json

I think those are the same two

taxilian avatar Dec 15 '25 22:12 taxilian

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

taxilian avatar Dec 15 '25 22:12 taxilian

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

rekram1-node avatar Dec 16 '25 01:12 rekram1-node

I think the proper pty should fix that

rekram1-node avatar Dec 16 '25 01:12 rekram1-node

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 avatar Dec 17 '25 13:12 ben-vargas

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 avatar Dec 19 '25 03:12 justcarlson

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 avatar Dec 19 '25 03:12 ben-vargas

I am loving this idea

justcarlson avatar Dec 19 '25 03:12 justcarlson

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 avatar Dec 19 '25 08:12 CybotTM