Azure / Azure/azure-dev

Route human-readable messages to stderr when --output json is active

Open
#7,389 1 comment 0 reactions 1 assignee Claimed by @spboyer View on GitHub
area/core-cli enhancement
Dominant language
Go
Stars
569
Forks
364
Avg merge
2d 19h
Merged PRs (30d)
136

Description

## Summary

When `--output json` is used, route all human-readable messages (status text, informational messages, spinner fallback text) to stderr so that stdout contains only valid, parseable JSON.

## Motivation

When users or LLM agents use `--output json`, they expect stdout to contain only valid JSON. Currently, status messages, spinner fallback text, and informational output can intermingle with JSON on stdout, making it harder to parse programmatically.

Routing human-readable messages to stderr when JSON output is requested keeps stdout clean for machine consumption while preserving visibility of status information on stderr. This is a common pattern in well-behaved CLI tools (e.g., `docker`, `kubectl`, `jq`).

## Implementation Notes

- In commands that support `--output json`, redirect non-JSON output to stderr
- This affects `Console.Message()`, `Console.ShowSpinner()`, and similar display methods
- JSON result objects should remain on stdout
- Consider adding an `OutputMode` concept to the Console that controls routing

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.