Error message: JSON Parse error: Expected '}' #8681

Open
opened 2026-02-16 18:10:34 -05:00 by yindo · 3 comments
Owner

Originally created by @Starlight0798 on GitHub (Feb 6, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Image

invalid [tool=write, error=Invalid input for tool write: JSON parsing failed:

Error message: JSON Parse error: Expected '}’

I simply asked the agent to complete a project, and it started writing code on its own, which then frequently resulted in this error.

Once this happens, the agent will continuously report errors and retry writing, getting stuck in an infinite loop and unable to continue working. It seems unaware that the write tool call failed.

This issue occurs with both Gemini3 (flash or pro) and Claude (4.5 or 4.6). Why is this?

Plugins

oh-my-opencode-slim, opencode-dcp

OpenCode version

1.1.53

Steps to reproduce

1.ask agent to write a project.
2.Randomly, when writing to a file, it occurs.

Screenshot and/or share link

No response

Operating System

macOS 26.2

Terminal

No response

Originally created by @Starlight0798 on GitHub (Feb 6, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description <img width="1250" height="604" alt="Image" src="https://github.com/user-attachments/assets/28ace9c2-76b6-4be5-8140-414451cbdef5" /> invalid [tool=write, error=Invalid input for tool write: JSON parsing failed: Error message: JSON Parse error: Expected '}’ **I simply asked the agent to complete a project, and it started writing code on its own, which then frequently resulted in this error.** **Once this happens, the agent will continuously report errors and retry writing, getting stuck in an infinite loop and unable to continue working. It seems unaware that the write tool call failed.** **This issue occurs with both Gemini3 (flash or pro) and Claude (4.5 or 4.6). Why is this?** ### Plugins oh-my-opencode-slim, opencode-dcp ### OpenCode version 1.1.53 ### Steps to reproduce 1.ask agent to write a project. 2.Randomly, when writing to a file, it occurs. ### Screenshot and/or share link _No response_ ### Operating System macOS 26.2 ### Terminal _No response_
yindo added the bug label 2026-02-16 18:10:34 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 6, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #10755: JSON Parse error: Unterminated string during normal operation with gpt-5.2-codex
  • #11630: Write tool JSON parsing error with large files and special characters
  • #12412: Plan mode unable to save due to malformed write payload (JSON Parse error)
  • #5890: Incomplete JSON when writing out files with Claude Opus - exact error "Expected '}'"
  • #1803: AWS Bedrock Anthropic Opus JSON parsing failed on write tool
  • #2188: JSON parsing failed with "Expected '}'" - exact same error message
  • #12234: Infinite retry loop when StreamIdleTimeoutError occurs during tool input generation
  • #11079: Write tool continuously getting aborted with Claude Sonnet 4.5
  • #11112: Agent stuck at "Preparing write..." showing infinite retry loop pattern
  • #8102: MCP Tool JSON Parsing Errors where model produces invalid JSON arguments
  • #7692: JSON Parse error "Expected '}'" with stream chunk concatenation issues

These issues share your core symptoms:

  1. JSON parsing errors in write tool payloads
  2. Agent generating malformed JSON and unable to recover
  3. Infinite retry loops when write tool fails
  4. Affects multiple LLM models (Claude, Gemini, etc.)
  5. Same version patterns and error signatures

Feel free to ignore if your specific case differs, but these likely share the same root cause.

@github-actions[bot] commented on GitHub (Feb 6, 2026): This issue might be a duplicate of existing issues. Please check: - #10755: JSON Parse error: Unterminated string during normal operation with gpt-5.2-codex - #11630: Write tool JSON parsing error with large files and special characters - #12412: Plan mode unable to save due to malformed write payload (JSON Parse error) - #5890: Incomplete JSON when writing out files with Claude Opus - exact error "Expected '}'" - #1803: AWS Bedrock Anthropic Opus JSON parsing failed on write tool - #2188: JSON parsing failed with "Expected '}'" - exact same error message - #12234: Infinite retry loop when StreamIdleTimeoutError occurs during tool input generation - #11079: Write tool continuously getting aborted with Claude Sonnet 4.5 - #11112: Agent stuck at "Preparing write..." showing infinite retry loop pattern - #8102: MCP Tool JSON Parsing Errors where model produces invalid JSON arguments - #7692: JSON Parse error "Expected '}'" with stream chunk concatenation issues These issues share your core symptoms: 1. JSON parsing errors in write tool payloads 2. Agent generating malformed JSON and unable to recover 3. Infinite retry loops when write tool fails 4. Affects multiple LLM models (Claude, Gemini, etc.) 5. Same version patterns and error signatures Feel free to ignore if your specific case differs, but these likely share the same root cause.
Author
Owner

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

I've encountered this error in the past and the cause of this is most likely that the agent is trying to write more than the model's output token limit (the global default is set to 32K tokens in opencode).

You could try getting the model to write in smaller chunks or if not setting OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX to a higher value to see if that solves the issue.

@NachoFLizaur commented on GitHub (Feb 6, 2026): I've encountered this error in the past and the cause of this is most likely that the agent is trying to write more than the model's output token limit (the global default is set to 32K tokens in opencode). You could try getting the model to write in smaller chunks or if not setting OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX to a higher value to see if that solves the issue.
Author
Owner

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

I've encountered this error in the past and the cause of this is most likely that the agent is trying to write more than the model's output token limit (the global default is set to 32K tokens in opencode).

You could try getting the model to write in smaller chunks or if not setting OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX to a higher value to see if that solves the issue.

thanks, i will try

@Starlight0798 commented on GitHub (Feb 6, 2026): > I've encountered this error in the past and the cause of this is most likely that the agent is trying to write more than the model's output token limit (the global default is set to 32K tokens in opencode). > > You could try getting the model to write in smaller chunks or if not setting OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX to a higher value to see if that solves the issue. thanks, i will try
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8681