History stays local. ai-hist export writes the slice you select as NDJSON — one stored record per line — for your own programs to consume.
Select
{
"all_sources": false,
"sources": ["claude", "codex"],
"sessions": [],
"kinds": ["history", "session_event", "tool_call", "file_edit", "presence"],
"excluded_sessions": []
}sourcesandsessionsform a union. Setall_sources: trueto take every source.kindsis always explicit.- A session in
excluded_sessionsis left out, along with any relationship that names it.
Export from the CLI
ai-hist export --selection selection.json > history.ndjson
ai-hist export --selection selection.json --out history.ndjsonRecords go to stdout and errors to stderr. With --out, the file is replaced only after the export completes.
Each record carries:
| Field | Meaning |
|---|---|
payload | The stored row's columns. |
record_id | A stable SHA-256 of the row's key, the same id the change feed uses. |
revision | The row's change-feed revision. |
origin_id | The store's change-feed epoch. |
Export from the SDK
import { exportHistory } from 'ai-hist';
for await (const record of exportHistory(selection, { dbPath })) {
await consume(record);
}The iterator reads one consistent snapshot — the store exactly as it stood when the export began, whatever is written while it runs. For paged consumers, use beginHistoryExport, readHistoryExportPage, and closeHistoryExport; an abandoned snapshot expires after an hour.