Skip to content

Commit a387257

Browse files
committed
fix: skip stdin read when positional message provided
`!process.stdin.isTTY` alone is too broad — it matches not just "someone piped input in" but also "the parent process inherited stdin from somewhere upstream and never closed its end." In the second case, `Bun.stdin.text()` waits forever for an EOF that never arrives. The process sits at 0% CPU with no session created, no log activity, no error — a silent hang. This surfaces in every subprocess invocation pattern that passes a positional message and inherits stdin: Claude Code's Bash tool, Python `subprocess.run(..., stdin=None)`, CI runners, plugin hosts that don't pin stdin to `/dev/null`. Downstream callers have been working around it with `stdio: "ignore"` on spawn (see e.g. altimate-opencode-plugin `plugins/altimate-code/index.ts:28`), but anything that forgets to do that still hits the wedge. Fix: only read stdin when no positional `message` was provided. Matches conventional CLI semantics (positional overrides stdin) and unblocks every subprocess caller. Pipe-only invocations without a positional arg continue to work unchanged. Closes #934
1 parent 146acea commit a387257

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

  • packages/opencode/src/cli/cmd

‎packages/opencode/src/cli/cmd/run.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,16 @@ export const RunCommand = cmd({
430430
message = [extractedParts.join("\n\n"), message].filter(Boolean).join("\n\n")
431431
}
432432

433-
if (!process.stdin.isTTY) message += "\n" + (await Bun.stdin.text())
433+
// Only read stdin when no positional message was provided. The original
434+
// unconditional `!isTTY` guard matched a non-TTY parent process even when
435+
// it inherited (but never closed) stdin — `Bun.stdin.text()` would then
436+
// wait forever for an EOF that never arrives, producing a silent 0% CPU
437+
// hang for any subprocess / CI / agent caller that passed a positional
438+
// message. Positional-overrides-stdin matches conventional CLI semantics;
439+
// pipe-only invocations without a positional arg still work as before.
440+
if (!process.stdin.isTTY && message.trim().length === 0) {
441+
message += "\n" + (await Bun.stdin.text())
442+
}
434443

435444
if (message.trim().length === 0 && !args.command) {
436445
UI.error("You must provide a message or a command")

0 commit comments

Comments
 (0)