# Quick start: connect Claude Code and Codex

Connect your coding agent in one command. It signs you in and connects Claude Code and Codex. You keep your agent, your model and your provider account.

## Key facts

What it is

One command, `npx @context-mode/cli`, that signs you in and writes one config change per agent.

Who it is for

Anyone connecting Claude Code or Codex to Context Mode.

Clients

Claude Code, in `~/.claude/settings.json`, and Codex, in `~/.codex/config.toml`.

Measured result

Not measured on its own. For the gateway as a whole, see [Benchmarks](https://contextmode.ai/docs/benchmarks#pooled).

Limits

Needs Node 20.12 or later. Codex sends a credential only from its own login, so an `OPENAI_API_KEY` that is only exported in your shell is not sent. Codex cost is measured per request; no Codex A/B yet.

```
npx @context-mode/cli
```

It does five things:

1. Signs you in, in the browser, if this terminal is not signed in yet.
2. Finds Claude Code and Codex on this machine.
3. Asks which of them to connect.
4. Writes each one's config and keeps a backup of the old file.
5. Sends one test request per agent, prints one line for each, then prints the console address.

Start free: 1,000 requests, every feature, no card. When the free requests run out, nothing breaks: see [Plans and limits](https://contextmode.ai/docs/plans-and-limits). Your own Claude or OpenAI account still pays the model.

Restart Claude Code, or start a new Codex session. Then open [the console](https://console.context-mode.com) to watch each request's tokens, cost and saving.

## What it writes

Claude Code, in `~/.claude/settings.json` under `env`:

```
"ANTHROPIC_BASE_URL": "https://gateway.context-mode.com",
"ANTHROPIC_CUSTOM_HEADERS": "x-cm-device-key: cmdk_…",
"ENABLE_TOOL_SEARCH": "true"
```

Claude Code turns tool search off for any base URL that is not Anthropic's and then sends every tool in full. `ENABLE_TOOL_SEARCH` turns it back on.

Codex, in `~/.codex/config.toml`:

```
model_provider = "context-mode"

[model_providers.context-mode]
name = "context-mode"
base_url = "https://gateway.context-mode.com"
wire_api = "responses"
requires_openai_auth = true
http_headers = { "x-cm-device-key" = "cmdk_…" }
```

Codex sends a credential only from its own login. A ChatGPT login and an API key both work. An `OPENAI_API_KEY` that is only exported in your shell is not sent, so the CLI tells you to run `codex login --with-api-key`.

## Codex

Codex gets the same gateway as Claude Code: [Context Saving](https://contextmode.ai/context-saving), [Protect](https://contextmode.ai/protect), [Memory](https://contextmode.ai/memory), [Skills](https://contextmode.ai/skills), [Search](https://contextmode.ai/search), [Session resume](https://contextmode.ai/session-resume) and [Active Context](https://contextmode.ai/docs/active-context). Both clients share one store per account, so a fact you state in one is there in the other, and `codex resume` can open a session that started in Claude Code.

**Protect and the Codex sandbox.** OpenAI's Codex docs say sandboxing and approvals are different controls that work together: the sandbox defines technical boundaries, and the approval policy decides when the agent must stop and ask before crossing them ([Codex sandboxing](https://developers.openai.com/codex/concepts/sandboxing.md), read 2026-10-01). Protect is a third check, on the gateway. It checks each call Codex makes, including `exec_command`, `apply_patch`, tool-server calls and the tool-server resource calls `read_mcp_resource`, `list_mcp_resources` and `list_mcp_resource_templates`, alone or inside one exec call, before Codex runs it. Protect reads the call, not the program, so keep the sandbox on, for example in workspace-write. See [Protect docs](https://contextmode.ai/docs/protect).

**Codex cost.** The gateway reads the token counts OpenAI returns at the end of each Codex response: input, cached input, output and reasoning. It prices them at OpenAI's list price ([OpenAI pricing](https://developers.openai.com/api/docs/pricing), read 2026-10-09). With a ChatGPT login you pay for a plan, not per token, so the console shows this as equivalent API cost. A model with no listed price shows no dollar amount.

**Codex saving.** The console counts the tokens the gateway kept out of a Codex request when it can count them on both sides, for example a large tool output, and prices them at the model's input price, or at its cached-input price when Codex's own cache would have held them. It does not count the tools and instructions the gateway adds, because OpenAI does not publish how it counts them. So the Codex saving shown is a lower bound.

**Codex A/B.** We have not run a paired Codex A/B, so we quote no Codex saving percentage.

## The device key

Sign-in gives this terminal a device key. It is stored in `~/.context-mode/credentials.json` and never printed. If you switch Claude or OpenAI accounts, the key stays, so your data stays in one workspace. The gateway removes the header before a request goes to Anthropic or OpenAI.

## What the CLI promises

- It shows the change and asks before it writes.
- It copies the old file to `<file>.cm-setup-bak-<timestamp>` first.
- It never replaces a different base URL or Codex provider unless you say so.
- Run it again with nothing to change, and it writes nothing.

## Commands

| Command | What it does |
| --- | --- |
| npx @context-mode/cli | Sign in and connect agents |
| login | Sign in this terminal |
| setup --agent claude\|codex\|all | Write agent config again. `--dry-run` shows the change, `--check` only reports. |
| status | Who this terminal is signed in as, and each agent's setup |
| doctor | Check config, the gateway and the device key |
| logout | Sign this terminal out and revoke its device key |
| disconnect | Take Context Mode out of Claude Code and Codex |

Each command runs as `npx @context-mode/cli <command>`. It needs Node 20.12 or later. Every option, exit code and file change is in the [CLI reference](https://contextmode.ai/docs/cli).

[Open the console](https://console.context-mode.com) [What it is](https://contextmode.ai/docs)
