Skip to content

Commit 64de72f

Browse files
scouzi1966claude
andcommitted
fix: suppress all output in single-prompt mode unless --verbose
In -s mode, redirect both stdout and stderr to /dev/null during model loading and generation. Only the final response prints to stdout. --verbose/-v overrides this and shows logs on stderr as before. Previously only stdout was redirected to stderr, so loading spinners, cache profiles, GPU info etc. still appeared in the terminal and polluted unix pipes. Closes #76 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0585f06 commit 64de72f

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

Sources/MacLocalAPI/main.swift

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,24 @@ struct MlxCommand: ParsableCommand {
700700

701701
let group = DispatchGroup()
702702
var output: Result<String, Error>?
703+
// In single-prompt mode, suppress ALL output (stdout + stderr) during model loading
704+
// and generation. Only the final response goes to stdout. --verbose overrides this.
703705
let stdoutFD = dup(STDOUT_FILENO)
704-
if stdoutFD == -1 || dup2(STDERR_FILENO, STDOUT_FILENO) == -1 {
705-
if stdoutFD != -1 { close(stdoutFD) }
706-
throw ValidationError("Failed to redirect single-prompt operational logs to stderr")
706+
let stderrFD = dup(STDERR_FILENO)
707+
let quietMode = !verbose && !veryVerbose && !vv
708+
if stdoutFD == -1 {
709+
throw ValidationError("Failed to save stdout for single-prompt mode")
710+
}
711+
if quietMode {
712+
let devNull = open("/dev/null", O_WRONLY)
713+
if devNull != -1 {
714+
dup2(devNull, STDOUT_FILENO)
715+
dup2(devNull, STDERR_FILENO)
716+
close(devNull)
717+
}
718+
} else {
719+
// Verbose: redirect stdout to stderr so only the response goes to stdout
720+
dup2(STDERR_FILENO, STDOUT_FILENO)
707721
}
708722
group.enter()
709723
Task {
@@ -757,11 +771,14 @@ struct MlxCommand: ParsableCommand {
757771
}
758772
group.wait()
759773
fflush(stdout)
760-
if dup2(stdoutFD, STDOUT_FILENO) == -1 {
761-
close(stdoutFD)
762-
throw ValidationError("Failed to restore stdout after single-prompt execution")
763-
}
774+
fflush(stderr)
775+
// Restore stdout (and stderr if we suppressed it)
776+
dup2(stdoutFD, STDOUT_FILENO)
764777
close(stdoutFD)
778+
if stderrFD != -1 {
779+
dup2(stderrFD, STDERR_FILENO)
780+
close(stderrFD)
781+
}
765782

766783
switch output {
767784
case .success(let text):

0 commit comments

Comments
 (0)