diff --git a/cli/src/index.ts b/cli/src/index.ts index 5525755514..6dcf12edcc 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -775,6 +775,12 @@ program // Always check for piped stdin content const stdinInput = await readStdinIfPiped() + // Error if stdin was piped but empty (e.g., `echo "" | cline`) + if (stdinInput === "") { + printWarning("Empty input received from stdin. Please provide content to process.") + exit(1) + } + // If no prompt argument, check if input is piped via stdin let effectivePrompt = prompt if (stdinInput) { diff --git a/cli/src/utils/piped.ts b/cli/src/utils/piped.ts index f03adcecaa..c046a71d1d 100644 --- a/cli/src/utils/piped.ts +++ b/cli/src/utils/piped.ts @@ -40,7 +40,10 @@ export async function readStdinIfPiped(): Promise { process.stdin.on("end", () => { clearTimeout(timeout) - resolve(data.trim() || null) + // Return empty string (not null) when stdin was piped but empty + // This allows callers to distinguish between "no piped input" (null) + // and "empty piped input" ("") for proper error handling + resolve(data.trim()) }) process.stdin.on("error", () => {