显示HN:Ctx – 一份可在Claude Code和Codex上使用的/简历
Show HN: Ctx – a /resume that works across Claude Code and Codex

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

## ctx:Claude & Codex 的本地上下文管理 **ctx** 是一款本地优先的工具,用于管理与 Claude 和 Codex 的对话,提供持久上下文、分支和搜索等功能——所有这些都不需要 API 密钥。它将数据存储在本地 SQLite 数据库和文件中,从而实现离线访问和完全控制。 **主要特点:** * **持久上下文:** 无缝恢复或分支对话,保留确切的聊天记录。 * **安全分支:** 从现有对话创建新的工作流,而不会影响原始对话。 * **索引搜索:** 快速找到已保存工作流和会话中的相关上下文。 * **上下文整理:** 钉住、排除或删除已保存的条目,以优化未来的模型输入。 * **本地优先:** 完全在本地运行,使用 SQLite 和文件——无需云依赖。 **入门:** 克隆仓库 ([https://github.com/dchu917/ctx.git](https://github.com/dchu917/ctx.git)) 并运行 `./setup.sh`。 使用 `/ctx start`、`/ctx resume` 和 `/ctx branch` (Claude) 或 `ctx start`、`ctx resume`、`ctx branch` (Codex) 等命令管理工作流。 网页界面 (`ctx web --open`) 允许详细查看和编辑上下文。 **使用场景:** 非常适合希望在多个会话中保持一致的上下文、试验不同的对话分支以及高效检索过去交互的开发者。

## Ctx:用于AI编码代理的持久工作流 Ctx是为Claude Code和Codex设计的一种新型本地技能,旨在改善编码会话期间的长期上下文管理。它作为对原生`/resume`功能的更有组织的替代方案,将工作流(包括会话、笔记和待办事项)存储在本地SQLite数据库中,允许用户在不同的AI代理之间无缝继续项目。 主要功能包括恢复工作流、搜索过往项目、分支用于并行任务以及维护指向特定会话日志的稳定链接。与依赖于提供方端存储的提示缓存不同,Ctx将所有内容保存在本地,无需API密钥或后端。 创建者最初为个人使用而构建Ctx,发现它更适合管理多个正在进行的项目。它可以通过单个命令(`./setup.sh`)轻松安装,并通过Claude中的`/ctx [命令]`或Codex中的`ctx [命令]`进行访问。开发者对建议持开放态度,包括潜在的导出/导入功能以共享工作流。
相关文章

原文

Local context manager for Claude Code and Codex.

Keep exact conversation bindings, resume work cleanly, branch context without mixing streams, and optionally inspect saved workstreams in a local browser frontend.

Claude Code chat          Codex chat
      |                      |
      v                      v
   /ctx ...               ctx ...
          \              /
           v            v
      +----------------------+
      | workstream: feature-audit |
      |   claude:  abc123    |
      |   codex:   def456    |
      +----------------------+
                 |
                 +--> feature-audit-v2 branch
  • Exact transcript binding: each internal ctx session can bind to the exact Claude and/or Codex conversation it came from.
  • No transcript drift: later pulls stay on that bound conversation instead of jumping to the newest chat on disk.
  • Safe branching: start a new workstream from the current state of another one without sharing future transcript pulls or hijacking the source conversation.
  • Indexed retrieval: saved workstreams, sessions, and entries are indexed for fast ctx search lookup.
  • Curated loads: pin saved entries so they always load, exclude saved entries so they stay searchable but stop getting passed back to the model, or delete them entirely.
  • Local-first: no API keys, no hosted service, plain SQLite plus local files.

Clone the repo and do the standard project-local setup:

git clone https://github.com/dchu917/ctx.git
cd ctx
./setup.sh

This is the main development-friendly install path.

It does the following:

  • creates ./.contextfun/context.db
  • writes ./ctx.env
  • installs a repo-backed ctx shim into ~/.contextfun/bin
  • links local skills into ~/.claude/skills and ~/.codex/skills

Use this when:

  • you want the repo checked out locally
  • you want ctx to use a project-local DB by default
  • you are developing or editing the repo itself
  1. Clone and set it up:
git clone https://github.com/dchu917/ctx.git
cd ctx
./setup.sh
  1. Start a new workstream:

Claude Code:

/ctx start feature-audit --pull

Codex or your terminal:

ctx start feature-audit --pull
  1. Know what --pull means:
  • ctx start feature-audit --pull creates the workstream and pulls the existing context from the current conversation into it.
  • ctx start feature-audit creates the workstream starting from that point only. It does not backfill the earlier conversation.
  1. Come back later and continue or branch:

Claude Code:

/ctx resume feature-audit
/ctx branch feature-audit feature-audit-v2

Codex:

ctx resume feature-audit
ctx branch feature-audit feature-audit-v2

Claude Code:

  • /ctx: show the current workstream for this repo, or tell you that none is set yet.
  • /ctx list: list saved workstreams, with this repo first when applicable.
  • /ctx search dataset download: search saved workstreams and entries for matching context.
  • /ctx start my-stream --pull: create a new workstream and pull the existing context from the current conversation into it before continuing.
  • /ctx resume my-stream: continue an existing workstream and append new context from this conversation to it.
  • /ctx rename better-name: rename the current workstream.
  • /ctx rename better-name --from old-name: rename a specific workstream without switching to it first.
  • /ctx delete my-stream: delete the latest saved ctx session in that workstream.
  • /ctx curate my-stream: open the saved-memory curation UI for that workstream.
  • /ctx branch source-stream target-stream: create a new workstream seeded from the current saved state of another one.
  • /branch source-stream target-stream: Claude shortcut for the same branch operation.

Codex:

  • ctx: show the current workstream for this repo, or tell you that none is set yet.
  • ctx list: list saved workstreams.
  • ctx list --this-repo: list only workstreams linked to the current repo.
  • ctx search dataset download: search saved workstreams and entries for matching context.
  • ctx search dataset download --this-repo: search only workstreams linked to the current repo.
  • ctx web --open: open the optional local browser UI for browsing, searching, and copying continuation commands.
  • ctx start my-stream: create a new workstream starting from this point only.
  • ctx start my-stream --pull: create a new workstream and pull the existing context from the current conversation into it first.
  • ctx resume my-stream: continue an existing workstream.
  • ctx resume my-stream --compress: continue an existing workstream with a smaller load pack.
  • ctx rename better-name: rename the current workstream.
  • ctx rename better-name --from old-name: rename a specific workstream without switching to it first.
  • ctx delete my-stream: delete the latest saved ctx session in that workstream.
  • ctx curate my-stream: open the saved-memory curation UI for that workstream.
  • ctx branch source-stream target-stream: create a new workstream seeded from the current saved state of another one.

Codex note:

Codex does not currently support repo-defined custom slash commands like /ctx list, so in Codex you should use the installed ctx command with subcommands. When ctx start, ctx resume, or ctx branch load context, they print a short summary of what the workstream is, the latest session being targeted, and the most recent items. They also include an explicit hint that in Codex you can inspect the full command output with ctrl-t, and in Claude you can expand the tool output block, plus guidance for the agent to summarize briefly and ask how you want to proceed instead of pasting the full pack back.

Clone the repo and install a shared global setup from that clone

git clone https://github.com/dchu917/ctx.git
cd ctx
./setup.sh --global

This runs the same quickstart entrypoint, but installs the pinned global release into ~/.contextfun instead of wiring the current clone as the live runtime.

Install globally without cloning first

curl -fsSL https://raw.githubusercontent.com/dchu917/ctx/main/scripts/install.sh | bash

This installs a pinned tagged release into ~/.contextfun, including the ctx binary, the Python package, the default DB, and the self-contained Claude/Codex skills.

Install the bootstrap skill first with skills.sh

npx skills add https://github.com/dchu917/ctx --skill ctx -y -g

This installs the ctx bootstrap skill first, not the CLI binary directly. After that, the bundled skills/ctx/scripts/ctx.sh wrapper can run ctx install or auto-install the global CLI into ~/.contextfun on first use.

Bootstrap an agent shell without a full manual clone flow

Global shell bootstrap:

source <(curl -fsSL https://raw.githubusercontent.com/dchu917/ctx/main/scripts/agent_bootstrap.sh)

Project-local shell bootstrap:

source <(curl -fsSL https://raw.githubusercontent.com/dchu917/ctx/main/scripts/agent_setup_local_ctx.sh)

These are best for Claude Code or Codex terminals.

Advanced manual wiring after cloning

Repo-backed ctx shim:

bash scripts/install_shims.sh

Skill links only:

bash scripts/install_skills.sh

Override skill directories if needed:

CODEX_SKILLS_DIR=/custom/codex/skills \
CLAUDE_SKILLS_DIR=/custom/claude/skills \
bash scripts/install_skills.sh

Use ctx curate <workstream> to review the saved entries that feed future loads for a workstream:

The terminal UI lets you scroll saved entries, inspect a preview, and change how each entry behaves in future packs:

  • j / k or arrow keys move through entries
  • Enter toggles a larger preview
  • p pins an entry so it always loads, even in compressed mode
  • x excludes an entry from future loads, but keeps it saved and searchable
  • a restores the default load behavior
  • d marks an entry for deletion, then y confirms the delete
  • q exits

Notes:

  • This changes ctx memory only. It does not edit or delete the original Claude/Codex chat.
  • If you are in a non-interactive shell, use ctx web --open and manage entries from the browser detail page instead.
  • ctx delete --interactive <workstream> opens the same curation UI.
  • See docs/usage.md and docs/architecture.md for deeper detail on load controls.

Use ctx clear to delete whole workstreams together with their linked sessions and saved entries:

ctx clear --this-repo --yes
ctx clear --all --yes

Notes:

  • --this-repo deletes only workstreams linked to the current repo.
  • --all deletes workstreams across the entire current ctx DB.
  • --yes is required for the actual delete. Without it, ctx prints what would be removed and exits without deleting anything.
  • This clears ctx-managed memory, attachments, and current-workstream pointers for the deleted workstreams. It does not delete the original Claude/Codex chat files.

ctx is a context layer, not a sandbox. See SECURITY.md for the threat-model summary and docs/maintenance.md for operational notes.

Do I need API keys?

Can multiple repos share the same context DB?

  • Yes. Set ctx_DB to a shared path such as ~/.contextfun/context.db.

Does deleting a ctx session delete the actual Claude/Codex chat?

  • No. It only deletes the internal ctx session and its stored attachments.

MIT. See LICENSE.

联系我们 contact @ memedata.com