Skip to content

Commit 84b77ec

Browse files
committed
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.
1 parent aef85f8 commit 84b77ec

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

  • rust/crates/rusty-claude-cli/src

rust/crates/rusty-claude-cli/src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,27 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
578578

579579
if rest.is_empty() {
580580
let permission_mode = permission_mode_override.unwrap_or_else(default_permission_mode);
581+
// When stdin is not a terminal (pipe/redirect) and no prompt is given on the
582+
// command line, read stdin as the prompt and dispatch as a one-shot Prompt
583+
// rather than starting the interactive REPL (which would consume the pipe and
584+
// print the startup banner, then exit without sending anything to the API).
585+
if !std::io::stdin().is_terminal() {
586+
let mut buf = String::new();
587+
let _ = std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf);
588+
let piped = buf.trim().to_string();
589+
if !piped.is_empty() {
590+
return Ok(CliAction::Prompt {
591+
model,
592+
prompt: piped,
593+
allowed_tools,
594+
permission_mode,
595+
output_format,
596+
compact: false,
597+
base_commit,
598+
reasoning_effort,
599+
});
600+
}
601+
}
581602
return Ok(CliAction::Repl {
582603
model,
583604
allowed_tools,

0 commit comments

Comments
 (0)