From 84b77ece4dae963f49badfbb3bcd634977de8d52 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Thu, 9 Apr 2026 20:36:14 +0900 Subject: [PATCH] fix(cli): pipe stdin to prompt when no args given (suppress REPL on pipe) When stdin is not a terminal (pipe or redirect) and no prompt is given on the command line, claw was starting the interactive REPL and printing the startup banner, then consuming the pipe without sending anything to the API. Fix: in parse_args, when rest.is_empty() and stdin is not a terminal, read stdin synchronously and dispatch as CliAction::Prompt instead of Repl. Empty pipe still falls through to Repl (interactive launch with no input). Before: echo 'hello' | claw -> startup banner + REPL start After: echo 'hello' | claw -> dispatches as one-shot prompt 159 CLI tests pass, fmt clean. --- rust/crates/rusty-claude-cli/src/main.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/rust/crates/rusty-claude-cli/src/main.rs b/rust/crates/rusty-claude-cli/src/main.rs index 4daa3de..41777a1 100644 --- a/rust/crates/rusty-claude-cli/src/main.rs +++ b/rust/crates/rusty-claude-cli/src/main.rs @@ -578,6 +578,27 @@ fn parse_args(args: &[String]) -> Result { if rest.is_empty() { let permission_mode = permission_mode_override.unwrap_or_else(default_permission_mode); + // When stdin is not a terminal (pipe/redirect) and no prompt is given on the + // command line, read stdin as the prompt and dispatch as a one-shot Prompt + // rather than starting the interactive REPL (which would consume the pipe and + // print the startup banner, then exit without sending anything to the API). + if !std::io::stdin().is_terminal() { + let mut buf = String::new(); + let _ = std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf); + let piped = buf.trim().to_string(); + if !piped.is_empty() { + return Ok(CliAction::Prompt { + model, + prompt: piped, + allowed_tools, + permission_mode, + output_format, + compact: false, + base_commit, + reasoning_effort, + }); + } + } return Ok(CliAction::Repl { model, allowed_tools,