gc — agents,
shell scripts, dashboard tools, smoke tests, CI — pass --json on commands that
support it, so callers read JSON fields instead of parsing tables, status text,
or progress messages. Human-readable output stays the default for interactive
use.
Quick Start
Use--json on supported commands:
Stdout And Stderr
When--json is passed, stdout is reserved for machine-readable output.
Supported JSON commands should not write human progress lines, tables, banners,
debug text, or summaries to stdout. Important command results belong in JSON
fields, not copied prose.
Stderr remains available for operational diagnostics. A caller should not need
stderr to understand the successful result shape, but stderr may still contain
human-readable details that help debug failures.
Common Result Shape
Newer JSON commands use a common success envelope:city_name, city_path, controller,
agents, rigs, and summary.
Action commands usually include a command field and an action field:
Failure Handling
Use the process exit code as the first success/failure signal (as in Quick Start): parse stdout only after a successful exit, and capture stderr separately for diagnostics. Many failures write to stderr without a command-specific JSON failure record, so don’t assume every--json command
emits a structured failure payload.
JSON Schema requests are different: if a requested schema is unavailable, gc
returns a structured failure payload on stdout and exits nonzero:
JSONL Framing
gc writes complete JSON records followed by newlines. For most bounded
commands, stdout has exactly one record.
Some streaming commands can emit multiple records. Their result schema may use
the x-gc-jsonl extension to describe record counts:
x-gc-jsonl is absent, treat the command as a single-record command.
When it is present:
minRecordsis the minimum number of records. If omitted, the minimum is0.maxRecordsis the maximum number of records. If omitted, there is no maximum.{}means zero or more records.{ "minRecords": 1 }means one or more records.{ "minRecords": 0, "maxRecords": 1 }means zero or one record.{ "minRecords": 1, "maxRecords": 1 }means exactly one record, explicitly.
Discover Schemas
Use--json-schema to discover a command’s JSON contract without running the
command’s normal behavior:
= or as the next argument:
json_supported: false:
Validate Output
Tools can combine--json and --json-schema=result to validate command
output. Start by fetching the schema and command result:
jq command only confirms that stdout is parseable JSON. Use a JSON Schema
validator when you need contract enforcement. Keep validation at command
boundaries rather than writing ad hoc field checks throughout an agent or
script.
For streaming commands, validate each JSONL record against the result schema:
jq; use a schema validator when
you need full schema checking.
Supported Surface
The JSON rollup added or standardized coverage across the main automation surface, including:- city lifecycle and status commands.
- agent and rig inspection/routing commands.
- session list, action, log, and mutation commands.
- mail and trace inspection commands.
- convoy, converge, formula, order, graph, service, and skill commands.
- runtime drain/nudge commands.
- schema discovery for supported commands.
gc <command> --json-schema to confirm whether a command declares
JSON support.
Passthrough Commands
Some commands pass arguments through to another CLI. For example,gc bd ...
routes to the bead CLI in the correct city or rig context.
Passthrough commands are not native gc JSON contracts. If the downstream tool
supports JSON, it owns that output shape. Gas City should not represent
passthrough output with a fake “anything is valid” schema.
For compatibility, local pack-defined commands can still pass their own --json
handling through when they do not declare schemas. Set
GC_JSON_CONTRACT_STRICT=1 in tests or CI when you want missing local command
schemas to fail instead of passing through.
Pack-Defined Commands
Pack-defined commands can be scripts or external programs, so Gas City does not automatically make arbitrary pack command output JSON-safe. Pack command schemas live next to the command implementation:commands/review/pr/.
schemas/failure.schema.json is optional. Use it only when the command has
meaningful command-specific failure fields beyond the shared default failure
shape.
Same Output On Every Route
A read command such asgc session list can answer from two places: the city’s
running supervisor API, or a direct read of the city’s own files and bead
stores. A supervisor-hosted city reads through the API by default. Either way,
the command prints a JSON document of the same shape, the one its result
schema declares:
A few values can still differ between the routes for the same city state:
gc session list: for a session that recorded no provider, the API route prints the city’s[workspace]provider, while the direct read leavesproviderout.gc session peek: the two routes resolve a session name through different alias rules, so a name can resolve on one route and not on the other.gc rig status: rows for unlimited pools (agents withoutmax_active_sessions) can list different instances.gc status: a rig’spathcan be relative on one route and absolute on the other.gc beads listandgc convoy liston a city that splits its bead storage can read a different set of stores on each route.gc mail countandgc mail checkcan count a named session’s mail across its earlier incarnations differently.
GC_NO_API=1 forces the direct read of a local
city, and --city-url, --city-name, GC_CITY_URL and contexts read a remote
city through its API. Picking a route doesn’t change the shape. The one
exception is gc beads list and gc beads show --format=json: for a remote
city they wrap the result in {"beads"|"bead", "_cache_age_s"}, and for a
local city they print the bare array or object.
Compatibility Notes
JSON output is an automation contract:schema_versionchanges only for a breaking change inside a command’s schema: a removed, renamed or retyped key, or a changed meaning. Adding an optional key is not breaking.- Every change to what a command prints, including a change on one route only, gets an Upgrading Note in the changelog.
- the command and invocation.
- the old shape.
- the new shape.
- whether the change is additive or intentionally incompatible.
- the rationale for making the change in that PR.
Related Reference
Use the generated CLI Reference for exact command flags. Use Events for thegc events JSONL event contract.
Use Schemas for published non-CLI schema artifacts such as OpenAPI,
events, and city config.