Skip to content

Bug: write tool fails with JSON parse error on large content #147

@fparrav

Description

@fparrav

Environment:

  • Agent: Sisyphus (oh-my-opencode)
  • Model: Claude Sonnet 4.5
  • Tool: write

Description:

The write tool fails when attempting to write large content (approximately 800+ lines) with a JSON parsing error. The error message is:

invalid [tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"filePath": "/path/to/file.md".
Error message: JSON Parse error: Expected '}']

Steps to Reproduce:

  1. Agent attempts to write a large markdown file (~810 lines) using the write tool
  2. Tool call is constructed with filePath and content parameters
  3. JSON appears to be truncated or malformed during serialization
  4. Error is returned indicating missing closing brace

Expected Behavior:

One of the following:

  • Accept arbitrarily large content in the content parameter
  • Return a clear error message like "Content exceeds maximum size of X characters/lines"
  • Document size limits in the tool's description

Actual Behavior:

Returns confusing JSON parse error that doesn't clearly indicate the root cause is content size.

Workaround:

Use bash tool with heredoc instead of write for large files:

cat >> /path/to/file.md << 'EOF'
[large content here]
EOF

This approach successfully wrote the same 810-line file without errors by chunking the content into multiple bash heredoc operations.

Impact:

  • Not critical (workaround exists)
  • Affects any use case requiring large file generation (documentation, config files, generated code)
  • Error message is misleading - suggests JSON structure issue rather than size limit

Suggested Fix:

  1. Increase or remove size limit on content parameter
  2. If limit is intentional, add validation that returns clear error message before JSON serialization
  3. Document any size constraints in the tool description

Additional Context:

The same content was successfully written using bash + heredoc, confirming the issue is specific to the write tool's handling of large content, not the underlying file system or content itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions