Skip to Content

Appendix A中文

A Map of the claude-mem Source

A quick reference to file paths, organized by module, based on v13.35.0. Every path in these tables has been checked against that version’s source tree. The right-hand column gives the chapters that cover each file most.

Entry Points and Configuration

FilePurposeChapters
plugin/hooks/hooks.jsonHook registration for Claude Code (8 events)5
plugin/hooks/codex-hooks.jsonHook registration for Codex CLI18
plugin/.mcp.jsonMCP server registration9
plugin/.claude-plugin/plugin.jsonPlugin metadata12
src/shared/SettingsDefaultsManager.tsEvery CLAUDE_MEM_* setting and its default2
src/shared/paths.tsPaths for the data directory, database, and so on2
transcript-watch.example.jsonExample transcript schemas for Codex and DSH18
docker-compose.ymlDeployment stack for the Server runtime16
docs/ip-boundary.mdThe line between open source and areas reserved for the commercial edition17

The Hook Command Layer

FilePurposeChapters
src/cli/hook-command.tsSingle hook entry point: buffers stderr, always exits 04, 5
src/shared/hook-io.tsHook discipline for stdout, stderr, and exit codes5
src/shared/hook-constants.tsTimeout and exit-code constants5
src/cli/types.tsThe NormalizedHookInput structure18
src/cli/adapters/7 platform adapters (claude-code, codex, cursor, kimi, windsurf, antigravity-cli, raw)18
src/cli/handlers/index.tsRegistry of the 9 handlers4
src/cli/handlers/context.tsSessionStart: reads context-cache and injects it5, 8
src/cli/handlers/session-init.tsUserPromptSubmit: registers this turn’s prompt5
src/cli/handlers/observation.tsPostToolUse: writes the spool and returns immediately5
src/cli/handlers/file-context.tsPreToolUse: file context and the File Read Gate5, 8
src/cli/handlers/memory-search.tsAdds claude-mem results when the host searches its native memory20
src/cli/handlers/summarize.ts, session-end.tsStop / SessionEnd wrap-up5

The Handoff Layer

FilePurposeChapters
src/shared/hook-spool.tsHook side: one file per event, written atomically4, 6
src/services/worker/hook-spool-drain.tsWorker-side pickup; exactly-once handoff via hook_spool_consumed6
src/shared/context-cache.tsCache of pre-rendered startup context4, 8

The Worker

FilePurposeChapters
src/services/worker-service.tsWorker entry point and CLI dispatch6
src/services/worker-shutdown.tsrunShutdownSequence: hard deadline and successor process6
src/services/infrastructure/GracefulShutdown.tsSix-step graceful shutdown6
src/services/infrastructure/ProcessManager.tsStarting and stopping processes6
src/shared/worker-spawn-gate.tsspawn.lock, preventing duplicate launches6
src/services/server/init-phase.tsStartup phases for /api/ready6
src/services/worker/http/middleware.tsHost check (DNS rebinding), CORS, restrictions on where deletes may come from6, 17
src/services/worker/http/shared.tsEntry checks: privacy-tag stripping, project exclusion, and more10, 17
src/services/worker/SessionManager.tsSession lifecycle6
src/services/worker/SessionMessageBuffer.tsIn-memory buffer (replaces v12’s persistent queue)6
src/services/worker/agents/ResponseProcessor.tsProcessing and storing the observer’s output10
src/shared/observer-recycle.tsGenerational recycling of the observer session6

The Observer

FilePurposeChapters
src/sdk/prompts.tsObserver prompts (with a cache-friendly prefix)10
src/sdk/hardened-options.tsThe observer’s six layers of restriction10, 17
src/sdk/parser.tsObservation XML parsing and error tolerance10
src/utils/tag-stripping.tsStripping <private> and other tags10
src/utils/redaction.tsAutomatic redaction (11 built-in rules)17
FilePurposeChapters
src/services/sqlite/SessionStore.tsTable creation, migrations, writes, dedup, and reinforcement7
src/services/sqlite/SessionSearch.tsFTS5 search7
src/services/sqlite/tool-uses.tsThe tool_uses raw-evidence table8, 10
src/services/worker/DatabaseManager.tsDatabase and Chroma collection management7
src/services/worker/SearchManager.tsSearch entry point7, 9
src/services/worker/search/SearchOrchestrator.tsRouting: Chroma first, SQLite to fill gaps7
src/services/sync/ChromaSync.tsVector sync7
src/services/reinforcement/ACT-R reinforcement history and ranking7, 10, 20

Context and MCP

FilePurposeChapters
src/services/context/ContextBuilder.tsAssembles startup context8
src/services/context/ContextBudget.tsThe 10,000-character budget and trimming order8
src/servers/mcp-server.tsMCP server (24 tools)9
src/servers/mcp-tool-visibility.tsHides tools per runtime9
src/services/worker/knowledge/Knowledge Agent: corpus building, prime, query11

The Server Runtime

FilePurposeChapters
src/storage/postgres/schema.tsPostgres tables and composite foreign keys16
src/server/routes/v1/ServerV1PostgresRoutes.ts/v1/* routes, retry and cancel, deletion16, 17
src/server/services/IngestEventsService.tsTransactional outbox16
src/server/jobs/job-id.ts, ServerJobQueue.tsDeterministic job IDs, BullMQ settings16
src/server/generation/ProviderObservationGenerator.tsGeneration worker: lockOutbox, tenant recheck16
src/server/middleware/postgres-auth.ts, rate-limit.tsAPI key authentication, rate limits, and quotas16, 17
src/services/hooks/runtime-selector.ts, server-client.tsHow hooks choose a runtime, and fallback rules16

Multiple Hosts and Sync

FilePurposeChapters
src/services/transcripts/Declarative transcript watcher18
src/integrations/opencode-plugin/, pi-extension/, dsh-plugin/Native plugins18
openclaw/src/index.tsOpenClaw plugin18
src/services/sync/CloudSync.tsCloud sync push19
src/services/sync/SyncApply.ts, SyncClient.tsCloud sync pull and apply19
src/services/sync/CanonicalContent.tsCanonical JSON and stable document IDs19
workers/sync-hub/src/do/SyncHub.tsThe hub: one ordered log per user19
src/services/telemetry/scrub.tsTelemetry property allowlist17

Skills

There are 22 skills under plugin/skills/. Those directly about memory are mem-search, knowledge-agent, learn-codebase, smart-explore, timeline-report, weekly-digests, cloud-sync, and mode-creator. make-plan, do, handoff, standup, and others are workflow skills built on top of memory. Chapter 2 introduces them grouped by purpose.

Quick Reading Paths

The write path:

hooks.json → hook-command.ts → handlers/observation.ts → shared/hook-spool.ts → worker/hook-spool-drain.ts → SessionMessageBuffer.ts → sdk/prompts.ts → agents/ResponseProcessor.ts → sqlite/SessionStore.ts

The read path:

handlers/context.ts → shared/context-cache.ts → context/ContextBuilder.ts → ContextBudget.ts servers/mcp-server.ts (mem_search) → worker/SearchManager.ts → search/SearchOrchestrator.ts