Running a platform from the command line
JSON on every command, explicit writes, the organisation named on each change, one public gateway and versioned writes make a CLI safe for agents to operate.
JSON on every command, explicit writes, the organisation named on each change, one public gateway and versioned writes make a CLI safe for agents to operate.
Coding agents optimise for finishing the task, not your scope, so drift builds up. Write scope as a contract, turn criteria into tests and verify continuously.
An agent plans the query; a Rust engine with no model computes each figure and returns a certificate tracing it to the records, checking access on every read.
A recurring report. A slow review. A prototype that needs to work in the real world.
We run the Company Twin and the customer servers beneath it through two command-line tools: the Twin CLI (which reaches an organisation's Twin through one public gateway) and Fleet (which observes and deploys every server). We chose the terminal because it's the one interface people and coding agents both use well, provided you build it for programs from the start. Every command answers in JSON, every change has to be asked for by name, and every call that mutates state has to name the organisation it's targeting instead of relying on a saved default. That's what makes a coding agent a safe operator, not merely a fast one.
Using the same commands for our own engineering board that customers run against their Twins turned out to be the fastest way to flush out real operational edge cases, from stale-read overwrites to two agents racing for the same reference number.
Key takeaways
Coding agents such as Claude Code and Codex already live in a terminal. They read help text, run a command, parse what comes back and decide what to do next. A web interface forces them to drive a browser; a custom agent API leaves us maintaining a second contract. A CLI with structured output gives people and agents the same front door, so every improvement helps both.
The Twin CLI is a public package. It signs in through the browser with OAuth, and one sign-in covers every organisation that identity can use: no SSH, no tunnel, no API key to paste and no tenant ID to hunt down. The first thing an agent runs is the capability manifest:
twin help --json # every command, its options, limits and examples, for an agent to readtwin organisations --json # which organisations this sign-in can usetwin channels --assert-org "Acme Ltd" --jsonThe JSON help is written for a model to consume directly: exact flags, filter operators, limits and examples, so the agent isn't guessing from prose. When something fails, the CLI prints a stable error object to standard error with the server's problem detail and validation paths, giving the agent enough to explain what went wrong instead of shrugging at "Bad Request".
Three rules carry almost all of the safety weight.
--json. Long-running questions can stream their lifecycle as one JSON object per line (submitted, queued, running, completed), carrying only stable identifiers until the end so an agent can report progress without burning tokens on repeated payloads. A local timeout doesn't cancel the server's work; the agent resumes waiting on the same query ID instead of kicking off a duplicate.--allow-write and a sign-in carrying the write scope. A read can never turn into a write because an agent misread a flag.--org or --assert-org picks the organisation for one command; an environment variable sets it for a process. Neither alters the saved default, so two agents working for different organisations on the same machine can't trip over each other. Any mutating command that omits an organisation is refused, and --assert-org goes one step further: it fails before the call even starts unless the resolved organisation matches the one named.That last rule came the hard way. An agent relying on remembered context will eventually be wrong about which organisation it's in, usually late in a long session or after another process switches the default. Putting scope on the command itself takes memory out of the equation.
The CLI, the SDK, MCP clients and our desktop app all reach an organisation exclusively through the public gateway. None of them speaks to the control plane directly, giving us one place to authenticate, rate-limit and audit, and one list of what outside clients can do.
That list is a single operation table in our contracts package. Each entry holds the full definition: route and method, required OAuth scope, rate class, read or write flag, request and response schemas, the SDK method it maps to and, where exposed to outside models, its MCP tool name. The OpenAPI description and the SDK are generated or checked directly against it. Today it holds more than 260 operations, of which about 120 need the write scope.
Two tests keep the surfaces honest. One inspects the CLI's command sources and the operation table directly (with no mocks) and fails if the CLI can emit a request the gateway's route matcher won't accept. It caught a command that had been quietly hitting control-plane paths, which worked fine on a developer's laptop and would have broken for every customer. The other verifies that every public operation maps to a real SDK method in a gateway-served namespace, and never into a control-plane-only one. Known gaps sit in explicit allow-lists that the tests require to shrink: the moment the gateway serves a route, its entry has to leave the list.
Every write follows the same three-step loop: read the current state, write only what changes alongside the version you read, and read the result back.
twin channels --channel clients --record rec_123 --json # returns values and "version": 3 cat > patch.json <<'JSON'{ "expectedVersion": 3, "values": { "nextAction": "Schedule review" } }JSON twin channels --channel clients --record rec_123 \ --update-record patch.json --assert-org "Acme Ltd" --allow-write --json twin channels --channel clients --record rec_123 --json # confirm: version 4, the new valueValues are merged rather than replaced, so a patch can't wipe a field it didn't mention. A stale version comes back as 409 Conflict. Creating a record takes an idempotency key: repeating the key with the same body after a dropped response returns the original record and its receipt, while reusing it with different content raises a conflict. An agent that loses its connection mid-write can retry cleanly without creating a duplicate, and an agent that muddles two writes gets stopped. Deletion is archiving under the same version check, keeping the audit history intact.
The read-back step feels redundant right up until the first time a write is accepted by one layer and altered by another. We treat any consequential write as unfinished until an independent read confirms it.
Yes, and for automation you usually should. Asking a question in prose invokes the Twin's agent, which fits open-ended work. When a script already knows the shape of the answer it needs, it can skip the model altogether:
twin graph catalogue --json # entities and measures this person can readtwin graph query '{"measures":["invoice_amount_total"],"by":["currency"]}' --jsontwin graph search "late delivery" --jsontwin query --intent-file aggregate.json --json # a typed query over a channel's own dataThe graph commands query the organisation's graph the exact same way the Twin's own agent does, with every table pinned by a certificate (covered in certified answers from a Rust graph engine). They're strictly read-only and enforce the caller's data roles and channels. Typed queries over a channel's data are compiled server-side into parameterised SQL after validating access and every field against the schema; raw SQL isn't accepted. Our standing answer and invariant suites run through these commands, which is why they need no model and cost nothing to run after every release.
Each customer runs on its own server with a full copy of the stack. Fleet is the CLI that inspects and updates all of them, built on the same conventions as the Twin CLI.
| Command | What it does | The rule |
|---|---|---|
| status | Reads, for every service on every server, the release each running process actually loaded, its health and its queues | Fails closed: an unreachable server or a query that couldn't run is reported as unknown, never as healthy |
| deploy --dry-run | Plans a rollout locally, with no credentials | A plan is free; a change isn't |
| request | Submits a deployment for the governed runner to carry out | Short-lived, request-bound assertion; agents never hold deploy credentials |
| status --deployment-id | Follows one rollout to its terminal result | A filed request isn't a delivery |
Exit codes carry the verdict so scripts don't have to parse text: a converged, healthy fleet exits 0; drift, an unfinished rollout or failing health exits 1; invalid input exits 64. Status reads the loaded release straight from each running process rather than from symlinks, because an un-restarted service looks current on disk when it isn't.
Production changes happen only through a governed runner. An agent submits intent (the commit, the targets and the services), and submission is idempotent. A new request returns created: true; repeating the same key and payload returns replayed: true along with the existing rollout and its result, queuing no duplicate work. If a submission's response drops, the agent reuses the key to see what happened; changing the payload under the same key fails with a conflict. The release path behind this is set out in one customer per server.
Our engineering board is a channel data set inside our own Twin: one record per piece of work, holding fields for status, owner, who it's waiting on and the question a person needs to answer, plus comments for the history. The agents writing most of our code keep it up to date using the exact same twin channels commands a customer would run.
An agent claims a record by setting its owner and session, posts findings in comments as it goes, and whenever a human decision is needed, sets the waiting-on field to that person and writes the question with its recommendation first. Mentioning them in a comment notifies them in the app and in Slack. Every update passes the record's version and reads back afterwards; when something notable ships, the agent posts a short summary to the channel feed and mentions the people affected.
Dogfooding the CLI surfaced problems a demo would never hit. Two agents creating records at the exact same moment once grabbed the same reference number; the fix was a creation loop that takes the next free number and stops only once the server confirms creation. Version checks catch the parallel case of an agent writing from a stale read, turning a silent overwrite of a colleague's edit into a visible conflict. Because our own agents and our customers' agents run the same commands, every fix lands for both.
If you're putting coding agents to work on operations, the interface they hold matters more than the model behind them. We'd start with the commands your team already runs and make them safe for an agent before trying to make the agent smarter.
Making operations safe for agents
Most of this is plumbing, and that's rather the point. Our piece on the last mile problem for AI coding agents looks at keeping their work inside scope; this is the operational half. For how every interface reaches the Twin without widening access, see one Twin, many interfaces.
The CLI is public: sign in through your browser and wire your own terminal agents straight into your Company Twin. Install the Twin CLI →