Summary
The CLI already supports machine-readable output via --json, but it only works when the flag is passed explicitly on each invocation. There is currently no environment-level way to make JSON the default for unattended callers.
For agents, wrappers, and automation, that is brittle: forgetting --json on a single command switches stdout back to human-oriented output such as tables, pretty-printed text, or colored messages.
Because authsome is intended to be used by agents to manage credentials, this is not just a convenience issue. Predictable machine-facing output is part of the CLI's core product contract.
Current behavior
ContextObj stores a json_output boolean used across commands.
common_options() only sets that flag from the explicit --json Click option and otherwise defaults it to False.
- When
json_output is enabled, commands emit the existing versioned JSON envelope via ContextObj.print_json(...), for example:
{
"v": 1,
"status": "ok"
}
- Error handling also already respects
json_output and returns structured JSON with error and message keys.
There is no support today for AUTHSOME_JSON or any equivalent environment variable.
Why this matters
Automation often configures environment once and then invokes many CLI commands. Requiring --json every time is repetitive and easy to miss, especially when a higher-level agent or tool shells out to authsome in multiple places.
For an agent-oriented credential CLI, an environment variable would make JSON output opt-in at the process/session level and reduce accidental fallbacks to human-readable stdout.
Proposed behavior
Support an environment variable such as AUTHSOME_JSON that enables JSON mode globally.
When AUTHSOME_JSON is set to a truthy value such as 1, true, yes, or on:
- the CLI should behave as if
--json was passed
ContextObj.json_output should default to True
- existing JSON payload shapes, including the
"v": 1 envelope, should remain unchanged
- existing structured JSON error behavior should remain unchanged
If the variable is unset, current behavior should remain unchanged.
Scope
Primary implementation area:
src/authsome/cli/context.py
Likely touch points:
common_options() for resolving the default value
- tests covering representative commands and error handling
- docs for CLI flags and environment variables
Non-goals / clarifications
- This issue is about making structured stdout the default when requested via environment.
- It does not require suppressing stderr warnings or verbose logs. Commands that currently write warnings to stderr may continue to do so.
- It does not require replacing the existing
--json flag; the flag should continue to work as it does today.
Acceptance criteria
AUTHSOME_JSON is recognized as a global opt-in for JSON mode.
- With the variable set, commands produce the same stdout they would produce under explicit
--json.
- The existing
{"v": 1, ...} JSON envelope is preserved.
- JSON error responses continue to use the current
error / message structure.
- Behavior is unchanged when the variable is not set.
- Tests cover at least one success path and one error path with
AUTHSOME_JSON enabled.
- Relevant CLI/environment-variable docs are updated.
Summary
The CLI already supports machine-readable output via
--json, but it only works when the flag is passed explicitly on each invocation. There is currently no environment-level way to make JSON the default for unattended callers.For agents, wrappers, and automation, that is brittle: forgetting
--jsonon a single command switches stdout back to human-oriented output such as tables, pretty-printed text, or colored messages.Because
authsomeis intended to be used by agents to manage credentials, this is not just a convenience issue. Predictable machine-facing output is part of the CLI's core product contract.Current behavior
ContextObjstores ajson_outputboolean used across commands.common_options()only sets that flag from the explicit--jsonClick option and otherwise defaults it toFalse.json_outputis enabled, commands emit the existing versioned JSON envelope viaContextObj.print_json(...), for example:{ "v": 1, "status": "ok" }json_outputand returns structured JSON witherrorandmessagekeys.There is no support today for
AUTHSOME_JSONor any equivalent environment variable.Why this matters
Automation often configures environment once and then invokes many CLI commands. Requiring
--jsonevery time is repetitive and easy to miss, especially when a higher-level agent or tool shells out toauthsomein multiple places.For an agent-oriented credential CLI, an environment variable would make JSON output opt-in at the process/session level and reduce accidental fallbacks to human-readable stdout.
Proposed behavior
Support an environment variable such as
AUTHSOME_JSONthat enables JSON mode globally.When
AUTHSOME_JSONis set to a truthy value such as1,true,yes, oron:--jsonwas passedContextObj.json_outputshould default toTrue"v": 1envelope, should remain unchangedIf the variable is unset, current behavior should remain unchanged.
Scope
Primary implementation area:
src/authsome/cli/context.pyLikely touch points:
common_options()for resolving the default valueNon-goals / clarifications
--jsonflag; the flag should continue to work as it does today.Acceptance criteria
AUTHSOME_JSONis recognized as a global opt-in for JSON mode.--json.{"v": 1, ...}JSON envelope is preserved.error/messagestructure.AUTHSOME_JSONenabled.