Skip to main content
Glama

ctx-memory

LLMコーディングエージェント(Claude Code、Codex、Gemini CLI、OpenCode)向けの永続メモリ。

新しいセッションを開始すると、エージェントは前回取り組んだ内容(決定事項、触れたファイル、発生したエラー、学習した規約など)をすでに把握しています。クラウドへの送信やテレメトリはありません。すべては ~/.ctx-memory/store.db にあるローカルのSQLiteデータベースに保存されます。

仕組み

Session starts
      │
 Shell wrapper intercepts 'claude' (or codex/gemini/opencode)
      │
 MCP server starts alongside — injects prior context, exposes memory tools
      │
 During session: hooks fire on every tool call, messages buffered
      │
 Session ends (clean exit / Ctrl-C / crash)
      │
 Layer 1 → Layer 2 → Layer 3 pipeline runs
      │
      ├── Layer 1: extract weighted messages, events, decisions, errors, keywords
      ├── Layer 2: compress to ≤500-token digest, store in DB
      └── Layer 3: merge digest into project memory doc (markdown)

Next session: agent reads prior context automatically

Related MCP server: remem

インストール

npm install -g ctx-memory
ctx-memory setup

セットアップウィザードの動作:

  1. インストールされているツール(claude、codex、gemini、opencode)を検出します

  2. 統合するツールを尋ねます

  3. 各ツールのフック設定を書き込みます

  4. ~/.ctx-memory/bin/ にラッパーシンボリックリンクを作成します

  5. ~/.bashrc / ~/.zshrc を通じて ~/.ctx-memory/bin をPATHに追加します

シェルを再起動(または source ~/.bashrc を実行)すれば、通常通りツールを使用するだけでメモリ機能が自動的に有効になります。

コマンド

ctx-memory setup                        # interactive setup wizard
ctx-memory status                       # show configuration and stats
ctx-memory projects list                # list all projects
ctx-memory projects show <name>         # print full memory doc for a project
ctx-memory projects forget <name>       # reset memory (keeps sessions)
ctx-memory projects forget <name> --hard  # delete all sessions + data

MCPサーバー

MCPサーバーは各ツールセッションのサイドカーとして実行され、6つのツールを公開します。

ツール

説明

store_message

セッション終了時に処理するための会話メッセージをバッファリングする

store_event

ツール呼び出しイベント(ファイル編集、bashコマンドなど)を記録する

search_context

セマンティックな類似性やキーワードで過去のセッションを検索する

get_project_memory

プロジェクトメモリドキュメント全体を返す

list_sessions

目標と結果を含む最近のセッションを一覧表示する

end_session

セッションを終了し、第1層 → 第2層 → 第3層のパイプラインを実行する

MCPサーバーをClaude Codeでスタンドアロンで使用するには、~/.claude/settings.json に以下を追加してください:

{
  "mcpServers": {
    "ctx-memory": {
      "command": "node",
      "args": ["/path/to/ctx-memory/dist/src/mcp/index.js"]
    }
  }
}

アーキテクチャ

src/
  cli/        — setup wizard, status, projects commands
  db/         — SQLite schema + CRUD (projects, sessions, events, digests, memory)
  layer1/     — pure message/event processing → weighted Layer1Output
  layer2/     — digest compression to ≤500 tokens → Layer2Digest
  layer3/     — merge digest into ProjectMemory markdown
  mcp/        — MCP server (handlers + stdio entry point)
  wrapper/    — shell wrapper (intercepts tool invocation, manages session lifecycle)
  hooks/      — hook config writers for Claude / Gemini / OpenCode

主な制約:

  • すべての第1層/第2層/第3層関数は純粋関数であり、I/Oを行わず、例外をスローしません

  • ダイジェストは500トークン以下に維持されます

  • ベクトル検索には sqlite-vec を介した all-MiniLM-L6-v2 エンベディング(384次元)を使用します

  • 単一のSQLite DB、WALモード、外部キー制約有効

開発

npm run build       # tsc → dist/
npm run dev         # tsc --watch
npm run test:run    # vitest (single-shot, 476+ tests)
npm test            # vitest (watch mode)

DBパスのデフォルトは ~/.ctx-memory/store.db です。CTX_MEMORY_DB_PATH で上書き可能です。

ライセンス

MIT

Available Tools

6 tools
end_sessionC

Signal session end — runs Layer 1→2→3 pipeline, stores digest, updates project memory.

Inputs: outcome (required), project_id (required), session_id (required), exit_code.

get_project_memoryC

Return the full project memory document (architecture, conventions, recent work, known issues).

Inputs: project_id.

list_sessionsC

List recent sessions for a project with their goals and outcomes.

Inputs: limit, project_id.

search_contextB

Search past sessions for context relevant to a query. Uses embedding similarity, falls back to keyword search.

Inputs: query (required), limit, project_id.

store_eventC

Record a tool call event (file edit, bash command, etc.) for the current session.

Inputs: tool (required), session_id (required), args, result, +1 more.

store_messageC

Buffer a conversation message for session-end processing.

Inputs: role (required), index (required), content (required), session_id (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: session lifecycle (end_session), memory retrieval (get_project_memory, list_sessions, search_context), and data recording (store_event, store_message). No overlap in functionality.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern using snake_case, e.g., end_session, get_project_memory, store_event. The naming is predictable and uniform.

    Tool Count5/5

    With 6 tools, the server covers core memory management operations without bloat. The count is well-scoped for the domain of session context and project memory.

    Completeness5/5

    The tool surface covers the full typical lifecycle: recording events/messages, searching and retrieving context, listing sessions, and finalizing sessions with memory updates. No obvious gaps.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers