Show HN: ctx – 搜索你电脑中已有的编码代理历史记录
Show HN: ctx – Search the coding agent history already on your machine

原始链接: https://github.com/ctxrs/ctx

**ctx** 是一款基于 Rust 开发的开源命令行工具,旨在通过检索过往会话内容,帮助编程智能体(Coding Agents)找回“记忆”。智能体在执行任务时往往倾向于从零开始,这导致它们经常重复之前的错误或忽略既定的决策。**ctx** 通过将本地的智能体记录(包括讨论内容、失败尝试和执行指令)索引到私有、高性能的 SQLite 数据库中,有效解决了这一问题。 **主要功能包括:** * **高效性:** 通过将数据结构化为会话、事件和元数据,实现了精准检索,其 Token 利用效率比直接搜索原始记录高出 50 倍。 * **隐私性:** 所有索引和搜索操作均在本地完成。数据不会上传至云端,也无需任何 API 密钥。 * **无缝集成:** 支持 Cursor、Claude Code 和 Codex 等主流智能体平台。它允许智能体通过自然语言搜索历史记录,从而查找特定的决策、被否决的方案或针对文件的更改。 * **开发者友好:** 该工具提供强大的命令行界面,用于检查已索引的会话、通过 SQL 进行查询,并通过 SDK 集成到各种编程环境中。 通过使用 **ctx**,开发者可以确保智能体能够基于过往工作持续进步,而非重复劳动,从而显著提高生产力和上下文保持能力。

**ctx** 是一款基于 Rust 的新型命令行工具,旨在通过将现有的本地智能体(agent)会话记录和日志编入结构化的 SQLite 数据库,为编程智能体提供“长期记忆”。 与依赖复杂的图数据库或托管式记忆服务不同,*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.

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

Optional but recommended for agent sessions:

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.

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 harness Support
Claude Code Supported
Codex Supported
Cursor Supported
Pi Supported
OpenCode Supported
Antigravity / Gemini CLI Supported
Factory AI Droid Supported
Copilot CLI Supported

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.

Page What it covers
Install Install ctx, initialize local storage, and index discovered local history.
Quickstart Search local history, inspect an event, open the session, and use JSON output.
Install the ctx skill Install the agent-history search skill with the open skills installer.
Agent plugin installs Install the ctx skill through Codex, Claude Code, Cursor, or a raw skill folder.
SDKs Use ctx agent history search from TypeScript, Python, Rust, Go, JVM, Swift, or .NET code.
Custom history plugins Build an advanced local adapter for agent formats ctx does not support natively.
Cursor Import Cursor agent transcripts and ask Cursor to cite retrieved local history before editing.
How it works Understand discovery, import, SQLite storage, search refresh, and cited retrieval.
Supported agents See which agent histories ctx can discover, import, and search today.
CLI reference Review setup, status, sources, import, show, locate, search, SQL, MCP, and doctor.
联系我们 contact @ memedata.com