{"record":{"id":"f27562393e9202a4","repo":"rtk-ai/rtk","slug":"hook-stdin-exceeds-byte-limit","errorCode":null,"errorMessage":"hook stdin exceeds {} byte limit","messagePattern":"hook stdin exceeds (.+?) byte limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/hooks/hook_cmd.rs","lineNumber":25,"sourceCode":"use super::decision::{self, HookDecision};\nuse super::permissions::{self, PermissionVerdict};\nuse anyhow::{Context, Result};\nuse serde_json::{Value, json};\nuse std::io::{self, Read, Write};\n\nuse crate::core::tracking::HookOutcome;\nuse crate::core::utils::strip_leading_bom;\n\nconst STDIN_CAP: usize = 1_048_576; // 1 MiB\n\nfn read_stdin_limited() -> Result<String> {\n    let mut input = String::new();\n    io::stdin()\n        .take((STDIN_CAP + 1) as u64)\n        .read_to_string(&mut input)\n        .context(\"Failed to read stdin\")?;\n    if input.len() > STDIN_CAP {\n        anyhow::bail!(\"hook stdin exceeds {} byte limit\", STDIN_CAP);\n    }\n    Ok(input)\n}\n\n// ── Copilot hook (VS Code + Copilot CLI) ──────────────────────\n\n/// Format detected from the preToolUse JSON input.\nenum HookFormat {\n    /// VS Code Copilot Chat / Claude Code: `tool_name` + `tool_input.command`, supports `updatedInput`.\n    /// If using the PreToolUse pascal case form, Copilot CLI also remaps its native `bash`/`powershell`\n    /// runtime tool to `tool_name: \"Bash\"` for this schema and honors its `updatedInput`, live-verified\n    /// on Linux+Windows 11 with Copilot CLI 1.0.73+ by rewriting a marker command end-to-end\n    /// see <https://github.com/rtk-ai/rtk/pull/3179#issuecomment-5088268495>.\n    VsCode { command: String },\n    /// GitHub Copilot CLI's native schema: camelCase `toolName` + `toolArgs` (JSON string),\n    /// supports `modifiedArgs` for transparent rewrite. `rtk init --copilot` no longer\n    /// registers this schema (Copilot CLI honors the PascalCase `VsCode` schema on its\n    /// own — registering both caused a redundant second hook invocation per tool call,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/hooks/hook_cmd.rs#L7-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"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`).","solutions":["Reduce the payload sent to the hook (configure the tool to send a trimmed payload or disable transcript forwarding).","Use `rtk proxy` / call the underlying command directly if you need unfiltered, unbounded output instead of the hook path.","Raise STDIN_CAP in src/hooks/hook_cmd.rs and rebuild if your workload legitimately needs bigger payloads (source change)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let payload = read_hook_payload_source(); // however the tool builds it\nif payload.len() > STDIN_CAP {\n    eprintln!(\"hook payload {} bytes exceeds cap {}\", payload.len(), STDIN_CAP);\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":"match rtk_hook_run(\"claude\").err() {\n    Some(e) if e.to_string().contains(\"exceeds\") && e.to_string().contains(\"byte limit\") => {\n        eprintln!(\"hook payload too large; trim the forwarded transcript/output\");\n    }\n    _ => {}\n}","preventionTips":["Configure editor hooks to send minimal payloads (disable full-transcript forwarding).","Never pipe arbitrary files into `rtk hook <tool>`.","When upgrading the editor/agent tool, verify the hook payload size still fits RTK's stdin cap."],"tags":["hooks","stdin","payload-size","cli"],"backgroundTag":"payload-too-large","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}