Show HN: ctx – Search the coding agent history already on your machine

Hacker News Top Tools

Summary

ctx is an open-source CLI tool that indexes coding agent sessions locally into SQLite, enabling fast search of past discussions, decisions, and failed attempts to save tokens and improve agent performance.

Coding agents don&#x27;t have long-term memory.<p>But you do have months of full-fidelity agent transcripts stored on your machine.<p>A simple solution that goes a long way: ingest those transcripts and logs into a structured SQLite database, then search them with ranked text match. Everything is fully local and doesn&#x27;t require anything fancy like a graph database or hosted memory service.<p>This is the idea behind ctx, a Rust CLI that handles the ingestion and searching.<p>We give our agents a skill that tells them to reference past sessions before working in an area. Usually we do this through an &quot;Agent History Research Subagent&quot; whose job is just to prepare a short brief covering any relevant history before the task begins.<p>A real example: sometimes our test suite runs would fail because disk was full on the runner. The correct approach was to run the cleanup runbook, but the root cause of the failure was not clear to the agents, so they would think it was a test regression and go down the wrong rabbit hole debugging. When the agent searched history, it realized this failure had been encountered before and found the right workaround immediately. That got the agent onto the right cleanup path, and later we improved the log output so the same failure would be clearer next time. It&#x27;s a boring story, but it&#x27;s real agent productivity.<p>Another nice use case is quickly generating session transcripts for sharing. You can exclude the noisy intermediate messages, so the transcript shows the important parts of the session more cleanly. Try attaching a session transcript to your next PR so your teammate and their agent can review the provenance and prompting behind the change.<p>If you&#x27;re up for an additional challenge, ask your agent to &quot;exhaustively review all agent history in this repo and find where the SDLC is struggling or isn&#x27;t agent-native&quot;. Using past sessions to recursively improve the agentic SDLC is a loop that we&#x27;re using a lot today.<p>If you try it out, please let us know what you think!
Original Article
View Cached Full Text

Cached at: 07/03/26, 08:16 PM

ctxrs/ctx

Source: https://github.com/ctxrs/ctx

You have months of coding agent history on your machine. Search it with ctx.

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

curl -fsSL https://ctx.rs/install | sh

Optional but recommended for agent sessions:

npx skills add ctxrs/ctx

For marketplace/plugin installs in Codex, Claude Code, Cursor, and raw Agent Skills, see Agent Skill Install.

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.

Token output per agent history search: ctx search 917 tokens, raw transcript search 45,734 tokens.

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.

Agent harnessSupport
Claude CodeSupported
CodexSupported
CursorSupported
PiSupported
OpenCodeSupported
Antigravity / Gemini CLISupported
Factory AI DroidSupported
Copilot CLISupported

How ctx compares

Agent memory tools usually save compact facts, summaries, vectors, or graph nodes. Those can help with stable preferences, but they are weak evidence when the next agent needs to know where a decision came from, what command failed, or what was rejected in the original conversation.

Graphify-style tools answer a different question. They map the current repository: files, symbols, imports, folders, and relationships. ctx searches the prior agent sessions that explain what happened while people and agents changed that repository.

ctx keeps retrieval tied to sessions and events, so another agent can inspect the source before using it. Read more about agent memory, Graphify-style codebase graphs, and grep or log search.

Explore the docs

PageWhat it covers
InstallInstall ctx, initialize local storage, and index discovered local history.
QuickstartSearch local history, inspect an event, open the session, and use JSON output.
Install the ctx skillInstall the agent-history search skill with the open skills installer.
Agent plugin installsInstall the ctx skill through Codex, Claude Code, Cursor, or a raw skill folder.
SDKsUse ctx agent history search from TypeScript, Python, Rust, Go, JVM, Swift, or .NET code.
Custom history pluginsBuild an advanced local adapter for agent formats ctx does not support natively.
CursorImport Cursor agent transcripts and ask Cursor to cite retrieved local history before editing.
How it worksUnderstand discovery, import, SQLite storage, search refresh, and cited retrieval.
Supported agentsSee which agent histories ctx can discover, import, and search today.
CLI referenceReview setup, status, sources, import, show, locate, search, SQL, MCP, and doctor.

Similar Articles