Skip to content
Gates

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.

gates flags --env production --json | jq '.[] | select(.enabled == false) | .key'

Shapes

CommandPrints
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, restoreThe 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:

{ "error": "A flag with this key already exists", "hint": null }

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:

export GATES_TOKEN=…        # from ~/.config/gates/credentials.json after `gates login`
export GATES_API_URL=…      # only for a self-hosted API
npx @withgates/cli flags rollout new-checkout --env production --percent 25 --project $PROJECT_ID --json

--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:

gates flags kill checkout-v2 --json >/dev/null || echo "kill failed, do it from the dashboard" >&2

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.