ctx is an open-source CLI for fast local search across your past coding agent sessions.
Coding agents usually start from zero. They can inspect the current repo, but they often cannot recover the discussions, decisions, failed attempts, commands, and test results from earlier work.
Those sessions are full of useful context:
- decisions, constraints, intent, and rejected approaches from you
- bug investigations, refactors, file paths, commands, patches, and notes from previous agents
ctx indexes those logs into SQLite on your machine, then gives current and future agents a CLI for finding the prior discussion, command, or failed attempt before they repeat it.
Install and set up ctx
macOS, Linux, and FreeBSD:
curl -fsSL https://ctx.rs/install | sh
Windows PowerShell:
irm https://ctx.rs/install.ps1 | iex
or prompt your agent:
Please install and set up ctx CLI (see github.com/ctxrs/ctx)
50x more token-efficient than raw transcript search
By structuring agent history into sessions, events, metadata, and indexed fields, then returning ranked cited matches, agents can access meaningful history with far fewer tokens than raw search. Results vary by query and corpus, but raw search is often so token-heavy that it can be effectively the same as not having usable history.
How it works
Your past agent sessions are stored in local provider history files. ctx discovers supported sources, imports the real persisted records, and stores normalized session, event, and touched-file metadata in a local SQLite database optimized for retrieval.
ctx is written in Rust and stores a local SQLite index, so searches are fast, scriptable, and do not require a background service.
The index is local and private by default. Transcript text is preserved rather than hiding local paths or secret-shaped strings, so review copied output before sharing it outside the machine.
# Index all of your existing local agent sessions
ctx setup
# Your agent can search prior work with normal language
ctx search "failed migration"
# Search sessions/events that touched a file
ctx search --file crates/foo/src/lib.rs
# Or search multiple terms
ctx search --term "failed migration" --term rollback --term "cursor rename"
# Advanced: inspect exact local index data with read-only SQL
ctx sql "SELECT provider, COUNT(*) AS sessions FROM ctx_sessions GROUP BY provider"
# Results include matching sessions, snippets, and ctx IDs
# evt_01h... ses_01h... codex "migration expected the old cursor name" ...
# Print the matching part of the old transcript
ctx show event <ctx-event-id> --window 3
# Or print a compact transcript of the original session
ctx show session <ctx-session-id>
Those IDs let your current agent recover as much context from previous sessions as it needs.
ctx does not send your prompts, transcripts, or indexed history to a cloud service, call model APIs, require API keys, or write into your source repositories.
The installed binary also includes local docs and man-page generation:
ctx docs search "upgrade"
ctx docs show cli-reference
ctx docs man --print ctx
Official installer-managed binaries support signed self-upgrades:
ctx upgrade status
ctx upgrade check
Source builds and package-manager installs remain unmanaged and do not self-upgrade.
For the full pipeline, see How ctx works. For a quick first run, see Quickstart.
Supported agent histories
Support means ctx can discover or read that harness's persisted local history and import it into the local search index. Use ctx sources --json on your machine to see which sources are currently importable.