Scripting with --json
Every command takes --json. The output is then exactly one JSON document on stdout, uncolored, with no spinner or hint lines. Errors are JSON too, so a script can parse stdout and nothing else.
Shapes
| Command | Prints |
|---|---|
gates --json | { version, signedIn, user, linkedProjectId } |
whoami --json | { user: { id, email, name }, apiUrl, workspaces: [{ id, name, role }] } |
projects --json | [{ id, name, key, workspaceId, … }] |
link --json | { projectId, name, file } |
env keys --json | { projectId, keys: { development, preview, production } } |
init --json | { project, environment, sdkKey, installCommand, providerSnippet, usageSnippet, packageManager, sdkInstalled } |
flags --json | [{ id, key, name, enabled, defaultValue, rollout: { percentage, ruleCount }, createdAt, updatedAt }] |
flags create, kill, restore | The full flag: { id, key, name, enabled, defaultValue, environments: { <env>: { revision, rules } } } |
flags rollout --json | { key, environment, revision, rules: [{ id, priority, percentage, value, conditions }] } |
skill install --json | { skill: [paths], mcp: [paths] } |
rollout.percentage in a flag list is a number when the environment has one percentage rule and null otherwise; ruleCount tells the two null cases apart.
Exit codes and errors
0 on success, 1 on any error. With --json an error is one document on stdout:
hint, when present, is a command the person can run. Without --json the same two things go to stderr as ✗ message and an indented hint line. The message is the API’s own, so a 404 says which thing was not found and a 401 says the session is gone.
In CI
Authenticate with the environment instead of a browser:
--project replaces the link, so the job does not need .gates.json checked out, though it may use it. npx pins nothing; to pin, add @withgates/cli to the job’s devDependencies and call gates.
A kill in a deploy pipeline is the pattern the exit code is for:
For agents
An agent that can run commands should prefer the CLI with --json over the MCP server: same account, same actions, and the output is the API’s. The agent skill tells it how. An agent that cannot run commands gets the same actions over MCP.