# Search docs: sessions, prompts and archived tool output

The gateway saves each turn of your Claude Code and Codex sessions as it passes. You search them in the console. Your agent searches the same store with `context-mode-search`, and reads archived tool output back byte for byte, except secrets and e-mail addresses, which are masked before storage.

## Key facts

What it is

A search over the prompts, commands and tool output that passed through the gateway, in the console and as a tool for your agent.

Who it is for

Developers who need an old fix, command or output from any session or machine.

Clients

Claude Code and Codex, in one history. Search covers archived tool output, and search over past prompts comes with Memory.

Measured result

Not a cost feature, and not measured on its own. For the gateway as a whole, see [Benchmarks](https://context-mode.com/docs/benchmarks#pooled).

Limits

The console searches the first 4,000 characters of each tool result; the agent can read the full output. Stored prompts have no automatic expiry yet.

## What is saved

Each request carries the conversation. The gateway appends the new turns to your account's store, grouped by workspace (a project and a worktree) and by session. Claude Code and Codex turns go to the same store. Client preamble, such as Codex's environment block, is stripped first.

text your messages and the agent's replies, the first 6,000 characters of each block

commands each tool call with its name and full input

tool results the first 4,000 characters in the turn; when the gateway shortens a result, the full output goes to the archive first

Sessions from before you connected the gateway are not in the store.

## Search in the console

Open **Search** in the sidebar at [console.context-mode.com](https://console.context-mode.com). Type at least 2 characters.

- Search runs over every workspace in your account that has saved turns. The line under the box says how many workspaces it searched and how many turns matched.
- Results arrive as each workspace answers. A workspace that fails is counted, and searching again retries it.
- Each hit shows your message and the reply, with the project, the date and your words marked. Several hits in one exchange show once.
- Each workspace shows its top 50 matching turns and the full count. Add a word to narrow it.
- Click a hit to open the reader: the exchange and four turns either side. **Show earlier** and **Show later** add six turns at a time. Esc closes it.

To open a session again in your terminal, see [Session resume](https://context-mode.com/docs/session-resume).

## The agent's search tool

The gateway adds `context-mode-search` to the tools of Claude Code and Codex requests and answers the call itself. Nothing runs on your machine. The tool has two modes.

- **Query.** With `q`, it returns the top matches from your archive, ranked by BM25, each with its `docid` and a snippet.
- **Read.** With `docid`, it returns the archived bytes as stored, one page at a time.

| Field | Meaning |
| --- | --- |
| q | Search words. Required in both modes. |
| k | How many matches to return. |
| docid | The archive id to read, for example from a Context Saving label. |
| offset | Byte offset to start the page at. |
| limit | Bytes per page. Default 60,000, maximum 120,000. |

A read answers with `total_bytes`, `offset`, `returned_bytes` and `next_offset`. The agent passes `next_offset` back until it is `null`. An id with nothing behind it answers `found: false`.

When [Context Saving](https://context-mode.com/docs/how-saving-works) shortens a result, the label it leaves names the call to make:

```
context-mode-search {"q":"full output","docid":"context-mode-toolcap-9f2c1b-184320","offset":0}
```

## How large output is stored

The archive is a SQLite database with a full-text index, one per account. A large output is split into pages of 512,000 characters under one docid. A read crosses pages, so `total_bytes` and `next_offset` cover the whole output. The test suite stores 5 MB and reads it back identical. On the deployed gateway, Context Saving labels paged back to the stored output byte for byte.

**Masking.** Before archived text is stored, the gateway replaces known secret formats with `[redacted-secret]` and every e-mail address with `[redacted-email]`. So a `git log` reads back with its author addresses masked. This keeps secrets out of the archive.

## Who can read it

- Each account has its own store. The console needs a sign-in, and a workspace from another account answers 403.
- Tool output the gateway archived stays readable with Memory off. Archived conversation needs [Memory](https://context-mode.com/docs/memory) on; with it off, those ids answer as not found.

## Compared with local history

| Tool | Where the history lives |
| --- | --- |
| Claude Code | A JSONL file per session under `~/.claude/projects` , on the machine that ran it. `claude --resume` picks from those files. |
| Codex | A rollout file under `~/.codex/sessions` , on the machine that ran it. `codex resume` opens it. |
| claude-mem and similar plugins | A database on your own machine. |
| Context Mode | The gateway, per account. Every machine and both clients in one search, and the agent reads the same archive. |

## Limits

- The console searches the first 4,000 characters of each tool result. The agent can read the full archived output.
- Full-text search covers the first page of a large output. Later pages are reached by docid and offset.

## FAQ

### Can I search sessions that ran on another machine?

Yes. The history is kept at the gateway, so every machine and both clients share it.

### Can my agent search it too?

Yes, with the `context-mode-search` tool. It reads archived tool output back byte for byte, except secrets and e-mail addresses, which are masked before storage.

### Is anything masked?

Yes. Secrets and e-mail addresses are masked before storage.

Compared with other tools: see the [landscape](https://context-mode.com/docs/landscape#sessions).

[Session resume →](https://context-mode.com/docs/session-resume) [Context Saving](https://context-mode.com/docs/how-saving-works) [Benchmarks](https://context-mode.com/docs/benchmarks)
