Write tool JSON parsing error with large files and special characters #8232

Open
opened 2026-02-16 18:09:29 -05:00 by yindo · 1 comment
Owner

Originally created by @rizwankce on GitHub (Feb 1, 2026).

Originally assigned to: @thdxr on GitHub.

Bug Description

The Write tool consistently fails with JSON parsing errors when writing files that contain:

  1. Large content (>~1000 characters)
  2. Special characters (quotes, newlines, backticks)
  3. Code blocks with nested structures

Error Messages

Common errors encountered:

  • JSON Parse error: Unterminated string
  • Invalid input for tool write: JSON parsing failed
  • JSON Parse error: Expected ']'

Reproduction Steps

  1. Try to write a Rust file with ~200+ lines using the Write tool
  2. Content includes code with quotes, backticks, or special characters
  3. Error occurs consistently

Example that fails:

/// Fixed-point arithmetic module (16.16 format)
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Fixed(i32);

impl Fixed {
    const FRACTIONAL_BITS: i32 = 16;
    // ... more code with quotes and special chars
}

Workaround

Using bash with heredoc works reliably:

cat > /path/to/file.rs << 'EOF'
// Large file content here
// With any special characters
EOF

Environment

  • Platform: macOS (darwin)
  • Model: kimi-k2.5-free
  • Working with: Rust code files, Markdown documentation

Impact

  • Must use bash workarounds for any substantial file writes
  • Breaks flow when editing multiple files
  • Limits ability to use Write tool effectively

Suggested Fix

Either:

  1. Increase JSON string size limits
  2. Better escaping for special characters
  3. Alternative write method for large files
  4. Document the limitation and recommend bash for large files
Originally created by @rizwankce on GitHub (Feb 1, 2026). Originally assigned to: @thdxr on GitHub. ## Bug Description The Write tool consistently fails with JSON parsing errors when writing files that contain: 1. Large content (>~1000 characters) 2. Special characters (quotes, newlines, backticks) 3. Code blocks with nested structures ## Error Messages Common errors encountered: - `JSON Parse error: Unterminated string` - `Invalid input for tool write: JSON parsing failed` - `JSON Parse error: Expected ']'` ## Reproduction Steps 1. Try to write a Rust file with ~200+ lines using the Write tool 2. Content includes code with quotes, backticks, or special characters 3. Error occurs consistently ### Example that fails: ```rust /// Fixed-point arithmetic module (16.16 format) #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Fixed(i32); impl Fixed { const FRACTIONAL_BITS: i32 = 16; // ... more code with quotes and special chars } ``` ## Workaround Using bash with heredoc works reliably: ```bash cat > /path/to/file.rs << 'EOF' // Large file content here // With any special characters EOF ``` ## Environment - Platform: macOS (darwin) - Model: kimi-k2.5-free - Working with: Rust code files, Markdown documentation ## Impact - Must use bash workarounds for any substantial file writes - Breaks flow when editing multiple files - Limits ability to use Write tool effectively ## Suggested Fix Either: 1. Increase JSON string size limits 2. Better escaping for special characters 3. Alternative write method for large files 4. Document the limitation and recommend bash for large files
Author
Owner

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

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

  • #11531: JSON Parse Error - Unterminated String on Write Tool (similar issue with large content and special characters)
  • #10755: JSON Parse error: Unterminated string errors with Write tool
  • #5890: Incomplete JSON when writing out files (missing closing braces)
  • #11079: Write tool continuously getting aborted on macOS
  • #11112: Write tool stuck at "Preparing write..." state
  • #2904: Unicode/special characters causing file handling failures
  • #11282: Write tool fails when switching from Plan to Build mode
  • #1803: JSON parsing failed when writing files with AWS Bedrock
  • #8102: MCP Tool JSON Parsing Errors with invalid JSON arguments
  • #6838: Tool.edit and Write tool JSON parsing issues
  • #7030: Tool calls appear executed but files aren't created
  • #5362: Write Tool including metadata in file content

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 1, 2026): This issue might be a duplicate of existing issues. Please check: - #11531: JSON Parse Error - Unterminated String on Write Tool (similar issue with large content and special characters) - #10755: JSON Parse error: Unterminated string errors with Write tool - #5890: Incomplete JSON when writing out files (missing closing braces) - #11079: Write tool continuously getting aborted on macOS - #11112: Write tool stuck at "Preparing write..." state - #2904: Unicode/special characters causing file handling failures - #11282: Write tool fails when switching from Plan to Build mode - #1803: JSON parsing failed when writing files with AWS Bedrock - #8102: MCP Tool JSON Parsing Errors with invalid JSON arguments - #6838: Tool.edit and Write tool JSON parsing issues - #7030: Tool calls appear executed but files aren't created - #5362: Write Tool including metadata in file content Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8232