anomalyco / anomalyco/opencode
Large tool arguments (>~30KB) are truncated at the content boundary, causing "Unterminated string in JSON" — affects all tools incl. MCP
@jlongster is already working on this.
Since Aug 13, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
When a tool call carries a real string-literal argument larger than roughly 30KB, the opencode client truncates the tool-call JSON exactly at the end of the embedded content (missing closing quote/brace), and the call fails with:
The arguments provided to the tool are invalid: Invalid input for tool <TOOL>: JSON parsing failed: Text: {…content…}. Error message: Unterminated string in JSON at position N (line 1 column N+1)
The failure position N always equals the length of the sent payload — the string is cut at the content boundary. Small arguments (a few KB) work fine.
Environment
- opencode 1.18.15 and 1.18.18 (bug reproduces on both; upgrade did not fix it)
- Windows 11, PowerShell 5.1, TUI
- Reproduced on multiple tool types:
bash(built-in), an MCPrun_scripttool, andtask— i.e. it is not specific to any one tool or to MCP servers
Steps to reproduce
- Invoke any tool (e.g.
bash) with an argument containing a literal string of ~30KB+ (e.g. a multi-line ASCII payload). Note:"a" * 30000-style runtime-generated strings do NOT reproduce it — the payload must physically be large in the tool-call argument. - The client rejects the call before it ever reaches the tool/server:
JSON parsing failed … Unterminated string in JSON at position N.
Evidence (position ≈ payload length)
| Payload | Tool | Error position |
|---|---|---|
| 29.6KB wrapper (base85-encoded) | MCP run_script | 79,585 |
| 70,100B raw script | MCP run_script | ~79,585 |
| 137,466B pure-ASCII (no quotes/backslashes/control chars) | bash | 137,466 |
| 189,623B pure-ASCII (nested) | bash | 189,623 |
| 240,586B pure-ASCII | bash | 240,586 |
| 1,035,824B pure-ASCII | MCP run_script | 1,035,824 |
| 1,039,076B pure-ASCII | bash | 1,039,076 |
| Small args (few KB) | bash / MCP | OK |
Key observations:
- Character set is irrelevant: 100% pure-ASCII payloads containing no quotes, no backslashes, no control characters fail identically. Base85 + JSON-escaped payloads fail identically. The truncation is purely length-based.
- JSON is truncated at the content boundary: position N ≈ exact payload length, i.e. the closing
"and}are never emitted. - Never reached the target: the MCP server reported 0 requests received; all failures are client-side.
- Cross-tool: bash (fully local, no network), MCP tools, and task tool all fail the same way.
- Repro'd across two releases (1.18.15 → 1.18.18).
Expected behavior
Large tool arguments should either be transmitted intact, fail with an explicit size-limit error, or be configurable (e.g. a documented max tool-argument size). Currently there is no way to pass payloads >~30KB to any tool, which blocks legitimate workflows such as executing large scripts through MCP run_script or passing large data blobs.
Impact
- Cannot execute any MCP tool that requires a >~30KB argument (e.g. running a 70KB script via
run_script). - Affects all tool types uniformly, not just MCP.
Happy to provide additional traces (opencode.log excerpts, persisted tool-output files) on request.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.