Skip to content

[Code Quality] Eliminate raw fmt.Print* usage in CLI commands with console formatters #11510

@github-actions

Description

@github-actions

Description

Several CLI command files use raw fmt.Printf and fmt.Println directly without routing to stderr or using console formatters. This breaks pipeline conventions (output to stdout instead of stderr), provides no color/styling, and has no TTY detection (colors leak into pipes/redirects).

Background

Identified during Console Output Analysis on 2026-01-23 (discussion #11476). While the codebase has excellent console formatting infrastructure with Lipgloss, Huh, and Bubble Tea, approximately ~20 raw fmt.Print calls* exist in CLI code that bypass this system.

Current state: Raw fmt usage in ~10 CLI files
Impact: Inconsistent output, breaks pipeline conventions, no TTY detection
Comparison: Most CLI code properly uses console formatters

Files Affected

Primary files (with call counts):

  • pkg/cli/file_tracker.go - 9 locations
  • pkg/cli/commands.go - 4 locations
  • pkg/cli/copilot-agents.go - 4 locations
  • pkg/cli/git.go - 1 location
  • pkg/cli/mcp_secrets.go - multiple locations
  • pkg/cli/mcp_list_tools.go - multiple locations

Suggested Changes

Standard Replacement Pattern

Before:

fmt.Printf("Created %s: %s\n", fileType, targetPath)

After:

fmt.Fprintln(os.Stderr, console.FormatSuccessMessage(
    fmt.Sprintf("Created %s: %s", fileType, targetPath)))

For Verbose Output with TTY Detection

if verbose {
    if tty.IsStderrTerminal() {
        fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Processing..."))
    } else {
        fmt.Fprintln(os.Stderr, "Processing...")
    }
}

For List Output

Before:

for _, file := range allFiles {
    fmt.Printf("  - %s\n", file)
}

After:

for _, file := range allFiles {
    fmt.Fprintln(os.Stderr, console.FormatListItem(file))
}

Success Criteria

  • All raw fmt.Printf and fmt.Println calls in CLI commands replaced with console formatters
  • Output routed to stderr (except JSON output which goes to stdout)
  • TTY detection added to verbose output paths
  • Consistent styling with rest of CLI
  • Colors don't leak into pipes/redirects
  • make agent-finish passes

Priority

Medium - Improves consistency and user experience

Estimated effort: Medium (2-3 hours across multiple files)

Source

Extracted from Console Output Analysis discussion #11476

Analysis quote:

"### ⚠️ Issue #1: Raw fmt.Print Usage Without stderr*

Problem: Several CLI files use fmt.Printf and fmt.Println directly without routing to stderr or using console formatters.

Impact:

  • Output goes to stdout instead of stderr (breaks pipeline conventions)
  • No color/styling applied (inconsistent with rest of CLI)
  • No TTY detection (colors leak into pipes/redirects)"

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 6, 2026, 2:07 PM UTC

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions