rtk-ai/rtk · error

hook stdin exceeds byte limit

Error message

hook stdin exceeds {} byte limit

What it means

Hook handlers (copilot, gemini, vibe, claude, trae, codex) read the hook payload from stdin with a hard cap (STDIN_CAP bytes) to keep RTK fast and memory-light. `read_stdin_limited` reads STDIN_CAP+1 bytes; if more than STDIN_CAP bytes arrive, the payload is oversized and the hook aborts with this error rather than truncating silently.

Solutions

  1. Reduce the payload sent to the hook (configure the tool to send a trimmed payload or disable transcript forwarding).
  2. Use `rtk proxy` / call the underlying command directly if you need unfiltered, unbounded output instead of the hook path.
  3. Raise STDIN_CAP in src/hooks/hook_cmd.rs and rebuild if your workload legitimately needs bigger payloads (source change).
Defensive patterns

Strategy: validation

Validate before calling

let payload = read_hook_payload_source(); // however the tool builds it
if payload.len() > STDIN_CAP {
    eprintln!("hook payload {} bytes exceeds cap {}", payload.len(), STDIN_CAP);
    std::process::exit(1);
}

Try / catch

match rtk_hook_run("claude").err() {
    Some(e) if e.to_string().contains("exceeds") && e.to_string().contains("byte limit") => {
        eprintln!("hook payload too large; trim the forwarded transcript/output");
    }
    _ => {}
}

Prevention

When it happens

Trigger: A hook integration pipes a payload larger than STDIN_CAP into rtk's hook subcommand — e.g. `rtk hook claude` invoked by the Claude Code / Copilot / Gemini hook system when the transcript or tool output it forwards exceeds the configured byte limit.

Common situations: Hooks configured to forward full transcripts or very large tool outputs; a tool version change that sends bigger payloads than RTK's cap; accidentally feeding a file into the hook via stdin (`cat huge.json | rtk hook claude`).

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19). Data as JSON: /api/errors/f27562393e9202a4. Report an issue: GitHub.

Appendix: source

Thrown at src/hooks/hook_cmd.rs:25

use super::decision::{self, HookDecision};
use super::permissions::{self, PermissionVerdict};
use anyhow::{Context, Result};
use serde_json::{Value, json};
use std::io::{self, Read, Write};

use crate::core::tracking::HookOutcome;
use crate::core::utils::strip_leading_bom;

const STDIN_CAP: usize = 1_048_576; // 1 MiB

fn read_stdin_limited() -> Result<String> {
    let mut input = String::new();
    io::stdin()
        .take((STDIN_CAP + 1) as u64)
        .read_to_string(&mut input)
        .context("Failed to read stdin")?;
    if input.len() > STDIN_CAP {
        anyhow::bail!("hook stdin exceeds {} byte limit", STDIN_CAP);
    }
    Ok(input)
}

// ── Copilot hook (VS Code + Copilot CLI) ──────────────────────

/// Format detected from the preToolUse JSON input.
enum HookFormat {
    /// VS Code Copilot Chat / Claude Code: `tool_name` + `tool_input.command`, supports `updatedInput`.
    /// If using the PreToolUse pascal case form, Copilot CLI also remaps its native `bash`/`powershell`
    /// runtime tool to `tool_name: "Bash"` for this schema and honors its `updatedInput`, live-verified
    /// on Linux+Windows 11 with Copilot CLI 1.0.73+ by rewriting a marker command end-to-end
    /// see <https://github.com/rtk-ai/rtk/pull/3179#issuecomment-5088268495>.
    VsCode { command: String },
    /// GitHub Copilot CLI's native schema: camelCase `toolName` + `toolArgs` (JSON string),
    /// supports `modifiedArgs` for transparent rewrite. `rtk init --copilot` no longer
    /// registers this schema (Copilot CLI honors the PascalCase `VsCode` schema on its
    /// own — registering both caused a redundant second hook invocation per tool call,

View on GitHub (pinned to 0924356b4c)