# Pi now runs through Context Mode: same Pi, with memory and skills

October 28, 2026 Agents 8 min read

Thank you to the Pi team at earendil-works for an open, configurable agent, and thank you to the Pi community. Pi keeps its provider settings in its own `models.json`, so connecting it needs no plugin and no fork. Today one command points Pi at Context Mode. You keep Pi, your model and your own API key. Every request then gets Saving, Memory, Skills, Instructions and Recall. Install Pi the way its makers do it, then run the Context Mode command.

## TL;DR

- **Install Pi its own way first:** `npm install -g @earendil-works/pi-coding-agent`, or `curl -fsSL https://pi.dev/install.sh | sh`.
- **Give Pi your own key:** an Anthropic or OpenAI API key, with Pi's `/login`, or as `ANTHROPIC_API_KEY` / `OPENAI_API_KEY`.
- **Connect it:** `npx @context-mode/cli setup --agent pi`. It sets the route in `~/.pi/agent/models.json` for Pi's Anthropic and OpenAI providers. It writes no API key.
- **Quit Pi and run it again.** The console shows these turns as Pi.
- **What you get:** Saving, Memory, Skills, Instructions, Recall, Search and Active Context on every Pi request. They are not measured on Pi yet.
- **Limits:** a Claude subscription (Pro/Max) cannot be used in Pi. Protect is recorded on Pi; enforcement is not verified. Undo with `npx @context-mode/cli disconnect --agent pi`.

## How to connect Pi to Context Mode

This post answers one question: how do you connect the Pi coding agent to Context Mode? Five steps. The first two are Pi's own. Pick a step to see the exact command and what it prints.

Step

Install Key Setup Restart Check

```
$ npm install -g @earendil-works/pi-coding-agent
# or: curl -fsSL https://pi.dev/install.sh | sh
```

Pi's own installer, from [earendil-works/pi](https://github.com/earendil-works/pi).

```
$ pi
# in Pi, type /login and add your Anthropic or OpenAI API key
# or: export ANTHROPIC_API_KEY=...
# or: export OPENAI_API_KEY=...
```

Pi sends your own provider key. Context Mode never writes it.

```
$ npx @context-mode/cli setup --agent pi
Pi uses your own provider key: an Anthropic or OpenAI API key, stored with Pi's own /login or set as ANTHROPIC_API_KEY / OPENAI_API_KEY. Setup writes no key.
Pi: ~/.pi/agent/models.json
  set providers.anthropic.baseUrl = https://gateway.contextmode.ai
  set providers.anthropic.headers.x-cm-device-key
  set providers.anthropic.headers.x-cm-client
  set providers.anthropic.compat.sendSessionAffinityHeaders
  set providers.openai.baseUrl = https://gateway.contextmode.ai/v1
  set providers.openai.headers.x-cm-device-key
  set providers.openai.headers.x-cm-client
Write these changes? y
Backup of the original: models.json.cm-setup-bak-<timestamp>
Set baseUrl, headers and compat of Pi's anthropic and openai providers: Pi's own documented models.json keys.
```

It shows each key, asks first, makes a backup, and never prints your key. Your terminal shows the full path of your home folder.

```
# quit Pi, then
$ pi
```

Pi reads models.json at start, so a running session keeps the old route.

```
$ npx @context-mode/cli setup --agent pi --check
Pi: configured (~/.pi/agent/models.json)
$ npx @context-mode/cli doctor
```

Then ask Pi anything. Your request shows on the console as Pi within a minute.

### 1. Install Pi its own way

Use the command Pi's makers give in [their repository](https://github.com/earendil-works/pi). Pick one:

```
npm install -g @earendil-works/pi-coding-agent     # or: curl -fsSL https://pi.dev/install.sh | sh
```

### 2. Give Pi your own API key

Pi needs your own provider key: an Anthropic or OpenAI API key. Store it with Pi's own `/login`, or set `ANTHROPIC_API_KEY` / `OPENAI_API_KEY`. Context Mode setup never writes this key. Pi sends it, and the gateway passes it on to the provider.

### 3. Run the Context Mode command

```
npx @context-mode/cli setup --agent pi
```

It needs Node 20.12 or later. If this terminal is not signed in yet, run `npx @context-mode/cli` first: it signs you in and gives this terminal a device key (`cmdk_…`), stored in `~/.context-mode/credentials.json`. The gateway removes the device key before a request goes to the provider.

### 4. Quit Pi and run it again

Pi reads `models.json` at start. Quit it, run `pi` again, and ask it anything. Your request shows on the console as **Pi**.

### 5. Check it

`npx @context-mode/cli setup --agent pi --check` tells you if Pi is set up, and writes nothing. `npx @context-mode/cli doctor` checks the config, the gateway and the device key. `npx @context-mode/cli status` shows who is signed in, and each agent's setup.

## What setup writes in Pi's models.json

Setup changes only Pi's own `~/.pi/agent/models.json` (or `$PI_CODING_AGENT_DIR/models.json`). Comments in the file stay. These are the keys it owns:

```
{ "providers": {
  "anthropic": { "baseUrl": "https://gateway.contextmode.ai",
                 "headers": { "x-cm-device-key": "<your device key>", "x-cm-client": "pi" },
                 "compat": { "sendSessionAffinityHeaders": true } },
  "openai":    { "baseUrl": "https://gateway.contextmode.ai/v1",
                 "headers": { "x-cm-device-key": "<your device key>", "x-cm-client": "pi" } }
} }
```

The Anthropic base URL has no `/v1`, because Pi adds it. Every other provider, model and key in the file stays. Setup writes no API key, and does not touch `auth.json` or `settings.json`.

How setup behaves:

- It shows the key-level change and asks before it writes.
- It copies the file to `<file>.cm-setup-bak-<timestamp>`, then writes atomically.
- It writes nothing if the file does not parse.
- If one of Pi's providers already goes to another address, it names it and asks before it replaces it. `disconnect` puts the old one back.
- `--dry-run` shows the change and writes nothing. `--yes` skips the question.

## Or connect Pi with your other agents in one command

Do you use more than one coding agent? Run the CLI with no arguments. It signs you in, lists the apps it finds (found ones checked), and sets up the ones you pick. Pi is in that list. It is not part of `--agent all`, which covers Claude Code and Codex.

```
$ npx @context-mode/cli
# pick Pi (and any other app) in the list, press Enter
Pi           connected (workspace …)
Console: https://console.contextmode.ai
Ready

Next:
  1. Restart Pi: quit it and run `pi` again (it reads models.json at start).
  2. Ask it anything. Now and then a line that starts with "⚡ context-mode" shows under the answer.
  3. Check it worked: your request shows on https://console.contextmode.ai within a minute.
  Not there, or an error in the agent? Run: npx @context-mode/cli doctor
```

The CLI's after-setup text still says "⚡ context-mode". The line itself now starts with "⏺ contextmode ·". Each app gets one check request through the gateway before you see `Ready`. The same picker covers Claude Code, Claude Desktop, Codex, Codex Desktop, T3 Code, OpenCode and Pi. Read [one gateway for seven coding agents](https://contextmode.ai/blog/seven-coding-agents-one-gateway) for the full list.

## Does Pi work with a gateway?

Yes. Pi lets you set a `baseUrl` and headers for each provider in its own `models.json` ([Pi's models.json docs](https://github.com/earendil-works/pi/blob/6c384aa30f619d7b28963f2bab24d8dacbe73cb6/packages/coding-agent/docs/models.md)). Context Mode uses only those keys. There is no plugin, no wrapper and no fork. We checked it on Pi 1.4.0, with the real `pi` binary: a request goes to `POST /v1/messages?beta=true` (Anthropic) or `POST /v1/responses` (OpenAI), with the device key and `x-cm-client: pi`, and the console names it Pi.

On the wire, Pi gets the same work as Claude Code and Codex. A test sends the same captured request as Pi and as Claude Code (Anthropic) or Codex (OpenAI), and the provider gets the same bytes each time. So the context cut and Recall run on Pi the same way they run on the others.

## Which login works in Pi with Context Mode?

Setup checks which login Pi uses before it writes. Pick yours.

Your login

Anthropic API key OpenAI API key Claude Pro/Max ChatGPT login

```
providers.anthropic → https://gateway.contextmode.ai
# Claude models in Pi go through Context Mode
```

Routed. Pi sends your key; setup never writes it.

```
providers.openai → https://gateway.contextmode.ai/v1
# OpenAI models in Pi go through Context Mode
```

Routed. Pi sends your key; setup never writes it.

```
Pi: your Anthropic login (auth.json) is a Claude subscription token. Anthropic does not allow a subscription to be used through another product, so Pi's Anthropic provider is left alone.
To route Claude models too, use an Anthropic API key (Pi's /login, pick API key, or ANTHROPIC_API_KEY) and run setup again.
Anthropic answers a Claude subscription used from another app with "Third-party apps now draw from your extra usage, not your plan limits" (400). That answer comes from Anthropic, not from contextmode. Use an Anthropic API key, or add extra usage at claude.ai/settings/usage.
```

Not routed. This is Anthropic's rule, not ours. Setup sets up only OpenAI and tells you why.

```
openai-codex # Pi's ChatGPT login: not touched
```

Setup does not touch Pi's ChatGPT login. Use an OpenAI API key to route OpenAI models.

## What you get in Pi

The gateway does not switch features on or off by app. These run on every Pi request. We measure savings on Claude Code, not on Pi, so this post gives no savings number for Pi. Pick a feature to see what it does.

Feature

Saving Memory Skills Instructions Recall Protect

```
$ pi -p "run the tests and fix the failing one"
# the test run prints every result
# the model gets the failing test, its error and the summary line
# the passed results stay out of the context
⏺ contextmode · … one short line on what was kept out
```

Large tool output (logs, fetched pages, big files) stays out of the model's context. The "⏺ contextmode" line shows in `pi -p`. Works on every request; not measured on Pi.

```
Monday, in Pi:
"We use pnpm in this repo, not npm."
Thursday, a new Pi session in the same folder:
"Add the date library."
pnpm add ...
```

Rules, decisions and preferences come back in later sessions. Stored for Pi, by project folder. Not measured live on Pi.

```
You, in Pi:
"use release-notes for this sprint"
# the release-notes skill loads for this turn
```

Import skills once, for example from GitHub. They run from the gateway, so there is nothing to install on each machine. Works on every request; not measured on Pi.

```
// Console: Settings → Instructions
Keep answers short.
Never touch code or technical terms.
```

Write your rules once in the console. Every Pi request carries them, on every machine.

```
You, in Pi, late in a long session:
"what did we decide about the quota check this morning?"
# the agent reads the decision back from the archive
```

Long history is archived, not lost. The agent reads older work back when it needs it. Works on every request; not measured on Pi.

```
$ git push origin main
# Claude Code, Codex: blocked by your rule
# Pi: recorded in Activity; blocking not verified
```

Protect is enforced on Claude Code and Codex. On Pi, the gateway records the call in Activity; blocking is not verified, so do not count on it to stop a command in Pi.

| Feature | In Pi | Measured on Pi |
| --- | --- | --- |
| [Saving](https://contextmode.ai/docs/how-saving-works) | Yes, every request | No (measured on Claude Code) |
| [Thinking in Code](https://contextmode.ai/thinking-in-code) | Yes, every request | No |
| [Memory](https://contextmode.ai/docs/memory) | Yes, stored for Pi | No |
| [Skills](https://contextmode.ai/docs/skills) | Yes, every request | No |
| [Instructions](https://contextmode.ai/docs/instructions) | Yes, every request | No |
| [Recall](https://contextmode.ai/docs/recall) and [Search](https://contextmode.ai/docs/search) | Yes, every request | No |
| [Active Context](https://contextmode.ai/docs/active-context) | Yes, every request | No |
| [Protect](https://contextmode.ai/docs/protect) | Recorded only; enforcement not verified | No |
| [Session resume](https://contextmode.ai/docs/session-resume) | No | Not applicable |
| "⏺ contextmode" line | Shows in `pi -p` ; the interactive screen is not verified | No |

## Memory for Pi

A new Pi session does not know what you told an earlier one. With Context Mode, what you told Pi last week comes back: "use pnpm", "we deploy on Fridays only", "no default exports". Memory stores these for Pi, by the folder you run Pi in. It keeps each Pi session apart by the session id Pi sends. Setup turns on `sendSessionAffinityHeaders` for Pi's Anthropic provider, so Pi sends that id. When a value changes, the old one is closed, not deleted. Read [how Memory works](https://contextmode.ai/docs/memory).

## Say this plainly

- **A Claude subscription (Pro/Max login) cannot be used in Pi.** This is Anthropic's rule for third-party apps, not ours, and Pi's own maintainers say the same. Use an Anthropic API key, or turn on extra usage at claude.ai/settings/usage.
- **If Pi is signed in with a Claude subscription,** setup leaves Pi's Anthropic provider alone, says so, and sets up only OpenAI.
- **If Anthropic refuses a request,** Context Mode shows Anthropic's own words and says who refused it.
- **Pi's ChatGPT login** (`openai-codex`) is not touched.
- **Protect** is recorded on Pi; enforcement is not verified. It is enforced on Claude Code and Codex.
- **The "⏺ contextmode" line** shows in `pi -p`. In Pi's interactive screen it is not verified.
- **Session resume** does not work for Pi.

## How to undo it

```
npx @context-mode/cli disconnect --agent pi
```

The file goes back as it was. A backup comes first, and it works offline. Check any time with `npx @context-mode/cli status`: who is signed in, and each agent's setup.

## Start now

Install Pi, add your API key, then run one command. [Open the Console](https://console.context-mode.com/login) to see your workspace.

```
npm install -g @earendil-works/pi-coding-agent     # or: curl -fsSL https://pi.dev/install.sh | sh
npx @context-mode/cli setup --agent pi
```

- Console: [console.contextmode.ai](https://console.contextmode.ai) ([start free](https://console.context-mode.com/login))
- CLI: `npx @context-mode/cli`
- Docs: [Quick start](https://contextmode.ai/docs/quick-start) and [the CLI](https://contextmode.ai/docs/cli)

The other apps, each with its makers' own install: [Claude Desktop](https://contextmode.ai/blog/claude-desktop-context-mode), [the ChatGPT desktop app](https://contextmode.ai/blog/codex-desktop-context-mode) and [T3 Code](https://contextmode.ai/blog/t3-code-context-mode). Context Mode is under the Elastic License 2.0 (ELv2).

[Get started free](https://console.context-mode.com/login) [All posts](https://contextmode.ai/blog)
