# Cross-session history

History tools inspect local sessions without switching sessions or changing them.

## Browse one timeline or list sessions

```js
history_list({ before: 190, limit: 20 })
history_list({ session: "claude:target-prefix", after: 0 })
history_list({ session: "*" }) // Recent sessions, one representative each
history_list({ session: "pi:*", since: "2026-10-01", limit: 20 })
```

Omit `session` for the current session. For a single session, use exclusive integer seqs for `after` / `before` (`after: 0` starts at the beginning) and optional ISO 8601 `since` / `until`. Without `after` (or `since` alone), the newest eligible events are returned, still in ascending seq order. Follow the older/newer recipes to page with the same options. Use `roles` to see specific roles, or omit it to fold tool/context runs. Follow the expand recipe to see those events.

With a wildcard `session` (`*`, `pi:*`, `claude:prefix*`), `history_list` returns one representative event per session, preferring the first visible user prompt, then the latest assistant event, then the latest visible event. With `roles`, it returns the latest matching event. Role and ISO 8601 `since` / `until` filters apply before choosing representatives (`after` / `before` seq bounds are refused on wildcards). Wildcard overviews consider most recently modified sessions first (least recently modified first with `since`).

## Find passages

```js
history_search({ query: "deployment", context: 1 })
history_search({ session: "*", query: ["deployment", "rollback"], limit: 20 })
history_search({ session: "codex:*", query: "migration", roles: ["tool"], since: "2026-10-01", context: 1 })
```

- `query` is required, matching literal text case-insensitively; a list matches any of its non-empty terms, and an empty query returns no matches. All roles are searched by default, including tool arguments and output. `context: N` adds up to N neighboring visible events on either side of a hit, even outside the hit's filters. Neighbors are marked `search context`, and don't count toward `limit`.
- `since` and `until` are exclusive ISO 8601 times (local time without an offset). Untimed events are excluded by time bounds. `limit` counts from the newest end, or oldest end with `since`; default 20. Results are grouped by session, with seqs ascending inside each group. If more results are available, narrow by time, role, query or session pattern.
- Both `history_list` and `history_search` accept wildcard session patterns: `*` covers all available sessions, `pi:*` restricts to Pi, and `claude:prefix*` narrows the ID. All characters except `*` are literal.

## Read one event

```js
history_read({ session: "claude:full-session-id", seq: 42, offset_chars: 120 })
```

An explicit session is shown as `=== session <harness>:<full-id> ===` above list/search rows. Copy that full ID and the event's seq into `history_read`. If a preview header shows ` | offset_chars N`, use `offset_chars: N` to open that passage; a shortened preview ends with ` [truncated]`. Follow the continuation for more text. Without a session heading, omit `session` to read the current session. Seqs are local to a session.

All three tools accept a full ID or unique prefix, optionally qualified by `pi:`, `claude:`, `codex:` or `dsh:`. Exact IDs take precedence over prefixes. An unqualified ID checks the current harness first. If no match or several matches are found, use a longer or harness-qualified ID. `history_read` rejects wildcards. The three tools return plain text bounded to 32 KiB including notices and footers.

## Local discovery and limits

| Harness | Default source | Selection/decoding |
| --- | --- | --- |
| Pi | `~/.pi/agent/sessions/<workspace>/<timestamp>_<id>.jsonl` | Current session uses the native active branch. Offline current-format files follow persisted parent links from the last tree entry, preserving append seqs and inactive-branch holes. |
| Claude | `~/.claude/projects/<project>/<id>.jsonl` | The current session still requires its live, confirmed append head. Offline files account for logical compact links, prefer non-attachment graph leaves when available, and select the last remaining leaf in transcript order. Only that leaf's confirmed ancestors are exposed; a graph with no leaves still refuses. |
| Codex | `~/.codex/sessions/YYYY/MM/DD/rollout-...-<threadId>.jsonl(.zst)` | The same structural rollout/lineage decoder as current-session history; compressed files need Node >=22.15. Root `session_id` is not a child thread ID. |
| DSH | `ctx.sessionQuery.listSessions()` / `readSession(id)` | Available inside DSH only, over its live-preferred local session corpus. Other hosts cannot discover DSH files themselves. |

Filesystem discovery does not follow directory symlinks or recurse into Claude subagent stores. Missing roots are empty. Repeated native files for one qualified ID produce one descriptor (newest modified); the current live binding wins over its on-disk descriptor. Discovery and decoding never mutate transcript bytes or modification times. Unsupported/corrupt or unreadable selected transcripts return `history_unavailable` naming the session for single-session calls. Wildcard searches and overviews skip individual sessions that cannot load; an empty wildcard result is not proof that an event never happened. A gap in Claude history appears as a notice; it does not change event text or read offsets.

The default roots respect `PI_CODING_AGENT_DIR` (Pi agent directory), `CLAUDE_CONFIG_DIR` (Claude config directory), and `CODEX_HOME` (Codex home). For direct root overrides use absolute paths in `NOTESOUP_HISTORY_PI_ROOT`, `NOTESOUP_HISTORY_CLAUDE_ROOT`, and `NOTESOUP_HISTORY_CODEX_ROOT`; these name the **sessions**, **projects**, and **sessions** directories respectively, not notes storage. `NOTESOUP_HOME` only changes notes.

## Recent-session overview speed

Repeated wildcard overviews can reuse saved session summaries for unchanged offline transcripts. Changes to a transcript or its source history invalidate the saved summary; live sessions are read directly. This does not change results, previews or notices. A missing or unusable cache falls back to reading transcripts. Searches may still take time when many sessions match.
