From c724f244543a51aad7a066393980c92ed9995c2e Mon Sep 17 00:00:00 2001 From: Lakshman Patel Date: Mon, 7 Sep 2026 12:01:22 +0530 Subject: [PATCH] fix: honor --quiet in print-mode usage footer Align the one-shot text-mode usage footer with exec's existing footer by suppressing it under --quiet, so machine-parseable output stays clean. --- cmd/chat_print.go | 4 ++-- cmd/chat_print_usage_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/chat_print.go b/cmd/chat_print.go index aef907a6..e26c4337 100644 --- a/cmd/chat_print.go +++ b/cmd/chat_print.go @@ -189,9 +189,9 @@ func writePrintUsageEvent(sessionID string, usage *engine.StreamUsage) { // printTextUsageFooter renders a muted token/elapsed summary to stderr after a // one-shot text-mode run. It writes to stderr so stdout stays pure for scripts, -// and is skipped entirely when no usage event was received. +// and is skipped entirely when no usage event was received or --quiet is set. func printTextUsageFooter(usage *engine.StreamUsage, started time.Time) { - if usage == nil { + if usage == nil || IsQuiet() { return } parts := []string{fmt.Sprintf("%d in ยท %d out", usage.PromptTokens, usage.CompletionTokens)} diff --git a/cmd/chat_print_usage_test.go b/cmd/chat_print_usage_test.go index 28220278..da19d3ed 100644 --- a/cmd/chat_print_usage_test.go +++ b/cmd/chat_print_usage_test.go @@ -85,4 +85,19 @@ func TestPrintTextUsageFooter(t *testing.T) { t.Errorf("expected no output for nil usage, got: %q", got) } }) + + t.Run("skips output when quiet is set", func(t *testing.T) { + old := quietFlag + quietFlag = true + defer func() { quietFlag = old }() + got := captureStderr(t, func() { + printTextUsageFooter(&engine.StreamUsage{ + PromptTokens: 100, + CompletionTokens: 50, + }, started) + }) + if got != "" { + t.Errorf("expected no output under --quiet, got: %q", got) + } + }) }