# Coding agents

> The two routes a Claude Code or Codex run can take, how to choose one, and how models and budget apply.

`nexus claude` and `nexus codex` start the real Claude Code and Codex. Nothing else about the agents changes: same
terminal, same commands, same arguments. Each run takes one of two routes:

| Route | Model calls go | Metered, budgeted, checked against policy | Recorded in Nexus |
| --- | --- | --- | --- |
| **Your own plan** (the default) | Straight to Anthropic or OpenAI, on your Claude Pro/Max or ChatGPT plan | No | The session, and the usage the agent reports |
| **Gateway** | Through Nexus Gateway, on your organization's provider key | Yes | The session, and every call's spend |

With nothing saved, a run uses your own plan. See [Choose a route](#choose-a-route) to change that.

## Set up

For the Gateway route, follow [Claude Code through Nexus Gateway](/docs/guides/claude-code) or
[Codex through Nexus Gateway](/docs/guides/codex). Those pages are generated from each agent's recipe: the limits to
read first, the steps, the check, and what Nexus changes for a run.

For your own plan, install the agent yourself (Nexus never installs it), [sign in](/docs/authentication) with
`nexus auth login` so the session is recorded, and sign the agent in to your plan once: `claude auth login` (not
`--console`, which bills the API), or `codex login` with ChatGPT.

## Run

```sh
nexus claude                                       # Claude Code, interactive
nexus claude -p "hello" --model claude-opus-5-5    # arguments go to Claude Code unchanged
nexus codex exec "hello"                           # Codex likewise
nexus claude --team platform                       # this session's spend goes to the platform team
```

Arguments after Nexus's own flags (`--json`, `--team`) go to the agent unchanged; put them after `--` to pass a flag
Nexus would otherwise read, such as `nexus claude -- --help` for Claude Code's own help. The exit code is the agent's.

`codex exec` refuses to run outside a git repository or a directory Codex trusts. Run it inside a repository, or add
`--skip-git-repo-check`: `nexus codex exec --skip-git-repo-check "hello"`.

Nexus prints one line before the agent starts and a short summary after it exits, and nothing in between. The line
names the route. With `--json`, one JSON summary on stdout at the end.

## Choose a route

```sh
nexus claude --api                     # this run through Gateway (--subscription for your plan)
nexus agents use claude gateway        # always, everywhere you sign in to Nexus
export NEXUS_CLAUDE_AUTH=gateway       # this shell (NEXUS_CODEX_AUTH for Codex)
```

A flag wins over the variable, and the variable over your saved route. `--via gateway` and `--via subscription` work
too.

**On your own plan**, the agent keeps its own login and calls its provider directly. Gateway never sees those calls, so
there is no metering, budget or spend for them (`nexus spend` shows nothing); which model it starts on still follows
your [model policies](#models). Nexus still records the
session and turns on the agent's own usage report for the run, with prompts redacted, so the session shows the tokens,
models and list-price estimate the agent reports. Your plan pays; Nexus charges nothing.

**Owners and admins can turn the plan route off** for the organization with `nexus org settings set agentSubscriptions
false`, or the Agents on personal plans switch in Nexus UI, under Settings › Policy. Then `--subscription` is refused
with `subscriptions_disabled`, and plain `nexus claude` and `nexus codex` go through Gateway instead.

## Antigravity

`nexus agy` starts Google's Antigravity (`agy`). It runs only on your own Google AI plan. Its calls go straight to
Google, and Nexus records the session.

```sh
curl -fsSL https://antigravity.google/cli/install.sh | bash   # install agy
nexus agy                                                     # agy signs in on its first start
nexus agy -- --conversation <id>                              # resume a conversation
```

`--api` is not available: `nexus agy --api` fails with `route_unsupported`. Run `nexus agy --subscription` instead.
`--model auto` is not available either; name a model by `agy`'s own id. `nexus agy` does not start while
`~/.gemini/antigravity-cli/settings.json` sets `modelProvider`. Remove that key to run on your plan. When your
organization turns off agents on personal plans, `nexus agy` does not start.

## Cursor

Run Cursor in Nexus Desktop or with the Rust CLI on macOS and Linux.
Install the Cursor CLI and run `cursor-agent login` to sign in to your Cursor plan.

```sh
nexus cursor-agent
nexus cursor-agent -- --resume <id>
```

In Desktop, Cursor starts in Accept edits. Select Plan only to ask Cursor for a plan.
Nexus waits for Cursor to confirm the mode before sending your first prompt.
Cursor sends model calls directly. Nexus records the session. Usage totals are unavailable.
Your organization must allow agents on personal plans.

## Sessions

What Nexus changes for a Gateway run is on each agent's page. On either route, each run opens a session, which you can see in Nexus UI with its person, agent, model, duration and status, and
closes it with the exit code however the agent ends.

## Models

When you don't name a model, Nexus passes the default that a [model policy](/docs/concepts/models-and-policies) sets for the agent (the agent's own,
else your team's or your organization's). With no such policy it passes none, and the agent starts on the model it picks for itself: the one its own release and
settings choose, which is not necessarily Nexus's default below and can change when you update the agent.
`nexus claude --model auto` asks Nexus to choose: the policy default, else Nexus's own (Claude Opus 5.5 for Claude
Code, GPT-5.3-Codex for Codex). This choice is a policy lookup on both routes, your own plan
included: if no model is allowed for `--model auto`, the run stops before the agent starts.

On the Gateway route, every call the agent makes is also checked against your organization's
[model policies](/docs/concepts/models-and-policies): the organization's, your team's and the agent's own, where a deny
always wins. A refused model never reaches the
provider and is answered with `403` `model_not_allowed` in the provider's own error format, so the agent shows it like
any provider error. Owners and admins set the agent's rule:

```sh
nexus policy set agent/claude --allow "anthropic/claude-opus-*,anthropic/claude-haiku-*" --default anthropic/claude-opus-5.5
nexus policy test --agent claude --model claude-haiku-5-5      # would it be allowed, and by which rule?
```

Claude Code also calls a small Haiku model in the background. A rule that refuses it refuses those calls too; the
policy test warns you when a rule would.

## Budget

On the Gateway route, every call reserves its maximum cost before it is sent: the request's size as input, plus the
most output it may produce. A long session with a large output limit reserves a lot per call, so the organization's budget must cover
the largest call its agents make, or the call is refused with `402` in the provider's own error format. See
[the ledger](/docs/concepts/ledger).

## Calling the agent gateway yourself

The same pass-through is an API: [`POST /v1/anthropic/v1/messages`](/docs/api/agent-gateway#anthropic-messages) and
[`POST /v1/openai/v1/responses`](/docs/api/agent-gateway#openai-responses) take the providers' own requests and
answer their own responses, streaming included. Authenticate with a Nexus token as `Authorization: Bearer` or
`x-api-key`; your Nexus key is never sent to the provider.
