Skip to content

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

@rizwankce

Description

@rizwankce

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions