# Quick start: connect Claude Code and Codex

One command 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 Gateway.

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://context-mode.com/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 not measured 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: 2,000 requests, every feature, no card. When the free requests run out, nothing breaks: see [Plans and limits](https://context-mode.com/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://context-mode.com/context-saving), [Cage](https://context-mode.com/cage), [Memory](https://context-mode.com/memory), [Skills](https://context-mode.com/skills), [Search](https://context-mode.com/search), [Session resume](https://context-mode.com/session-resume) and the [context limit](https://context-mode.com/docs/context-limit). 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.

**Cage 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). Cage is a third check, on the gateway. It checks each call Codex makes, including `exec_command`, `apply_patch` and tool-server calls inside one exec call, before Codex runs it. Cage reads the call, not the program, so keep the sandbox on, for example in workspace-write. See [Cage docs](https://context-mode.com/docs/cage).

**Not done yet for Codex.**

- Codex cost is not measured, so we quote no Codex saving.
- Tool-schema trimming runs for Claude Code only, and part of the saving on Codex is not counted yet.
- Cage does not match Codex's `read_mcp_resource` and `list_mcp_resources` calls with Tool servers rules.

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

Each command runs as `npx @context-mode/cli <command>`. It needs Node 20.12 or later.

## FAQ

### Does it install a plugin or a background service?

No. It edits one config file per agent and keeps a backup of the old file.

### Can I see the change before it writes?

Yes. It shows the change and asks before it writes. `setup --dry-run` shows the change and writes nothing.

### Does my OpenAI API key work with Codex?

Yes, once Codex has it in its own login. Run `codex login --with-api-key`. A ChatGPT login works too.

### Does Cage replace the Codex sandbox?

No. Keep the sandbox on. Sandboxing and approvals limit what a command can touch; Cage decides which calls run at all.

### Do Claude Code and Codex share memory?

Yes. Both read the same memory store, skills and reply style through the gateway.

### How do I undo it?

Remove the lines it added, or restore the backup it left next to each file. [Steps](https://context-mode.com/docs/faq#leave).

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