ultraworkers/claw-code · error · std::io::Error

content is too large ({} bytes, max {} bytes)

Error message

content is too large ({} bytes, max {} bytes)

What it means

`write_file` (runtime/src/file_ops.rs:236) rejects content whose byte length exceeds `MAX_WRITE_SIZE`, 10 MiB (file_ops.rs:17). The limit applies to the full replacement payload because write_file rewrites the entire file. `ErrorKind::InvalidData`.

Source

Thrown at rust/crates/runtime/src/file_ops.rs:236

    });
    let selected = lines[start_index..end_index].join("\n");

    Ok(ReadFileOutput {
        kind: String::from("text"),
        file: TextFilePayload {
            file_path: absolute_path.to_string_lossy().into_owned(),
            content: selected,
            num_lines: end_index.saturating_sub(start_index),
            start_line: start_index.saturating_add(1),
            total_lines: lines.len(),
        },
    })
}

/// Replaces a file's contents and returns patch metadata.
pub fn write_file(path: &str, content: &str) -> io::Result<WriteFileOutput> {
    if content.len() > MAX_WRITE_SIZE {
        return Err(io::Error::new(
            io::ErrorKind::InvalidData,
            format!(
                "content is too large ({} bytes, max {} bytes)",
                content.len(),
                MAX_WRITE_SIZE
            ),
        ));
    }

    let absolute_path = normalize_path_allow_missing(path)?;
    let original_file = fs::read_to_string(&absolute_path).ok();
    if let Some(parent) = absolute_path.parent() {
        fs::create_dir_all(parent)?;
    }
    fs::write(&absolute_path, content)?;

    Ok(WriteFileOutput {
        kind: if original_file.is_some() {

View on GitHub (pinned to 08106b0c37)

Solutions

  1. Split the output into multiple files each under 10 MiB.
  2. Stream large content via the Bash tool (`cat > file <<'EOF'` chunks, or generate with a script) instead of one Write call.
  3. Check `content.len()` before building the call and trim what actually needs writing.

Example fix

# before
Write(file="snapshot.json", content=<12MiB string>)   # content is too large (12582912 bytes, max 10485760 bytes)

# after
Bash(command="generate_snapshot.py --out snapshot.json")   # producer writes directly
Defensive patterns

Strategy: validation

Validate before calling

const MAX_WRITE_SIZE: usize = 10 * 1024 * 1024; // must mirror file_ops.rs:17

if content.len() > MAX_WRITE_SIZE {
    // split into multiple files or write via bash heredoc chunks
}

Try / catch

match write_file(path, &content) {
    Err(e) if e.kind() == std::io::ErrorKind::InvalidData
        && e.to_string().contains("content is too large") => { /* chunk it or generate via script */ }
    other => other,
}

Prevention

When it happens

Trigger: Writing a generated bundle, snapshot, serialized dataset, or base64 blob larger than 10 MiB in a single Write tool call; concatenating outputs in memory then writing once.

Common situations: Agents materializing generated code bundles or fixtures; exporting session transcripts; embedding media as base64 in a source file.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of ultraworkers/claw-code@08106b0c37 (2026-08-18). Data as JSON: /api/errors/5c15d0e93171dd2f. Report an issue: GitHub.