@slicenfer/project-memory-adapter-claude-code
v0.3.1
Published
Claude Code adapter for Project Memory Runtime — hooks, event normalization, and session brief injection
Maintainers
Readme
Claude Code Adapter
Reference adapter spike for Claude Code.
If your app uses the official TypeScript @anthropic-ai/claude-agent-sdk, use
@slicenfer/project-memory-adapter-claude-agent-sdk instead. This package is
for Claude Code hook settings / shell-hook integration only.
Local manual test runbook:
- 中文:LOCAL-VALIDATION.zh-CN.md
- English: LOCAL-VALIDATION.md
Current scope is intentionally narrow:
- runtime-first local library
- stdin/CLI entrypoint for hook execution
- CLI-generated Claude hook settings for both local and user-level wiring
- controlled
capture_pathmapping SessionStartrecall injectionPostToolUsecapture normalizationStop/SessionEnd/PreCompactlifecycle capture- structured continuation checkpoints for
PreCompact / SessionEnd / PostCompact / StopFailure - structured Bash observation metadata plus local artifact refs
- local smoke tests only
Current trust boundary in this spike:
- plain message payloads are normalized as
import.transcript - only tool observations are upgraded to trusted
system.tool_observation claude_code.hook.*capture paths remain reserved for future real hook-envelope integration, and are not emitted by the current public message API
Not included in this spike:
- production hook packaging
- transcript persistence outside runtime
- broad tool coverage beyond the tested normalization rules
Primary integration points:
SessionStartPostToolUsePostToolUseFailureStopSessionEnd
Exports:
createClaudeCodeRuntime(config)ClaudeCodeAdapterdefaultClaudeProjectId(cwd)project-memory-claude-hookCLI
Notes:
createClaudeCodeRuntime()does not enableclaude_code.hook.*by default- future real hook-envelope integrations must opt in explicitly with
enable_claude_hook_capture_paths: true createClaudeCodeRuntime()rejects any manualclaude_code.hook.*allowlist unlessenable_claude_hook_capture_paths: trueis explicitly setdefaultClaudeProjectId(cwd)followsorigin > upstream > unique other remote, and falls back tolocal:<sha256(git_root)>only for local-only repos- if multiple non-priority remotes exist and no
origin/upstreamis present,defaultClaudeProjectId(cwd)fails closed and the caller must provideproject_id - session brief dedupe is persisted under the runtime data dir and keyed by
{project_id, workspace_id, session_id}, so it can suppress repeats across adapter instances without crossing project boundaries - shared global mode is supported through
resolveRuntimeLocation(), which routes byexplicit path > repo override > legacy local > global config - repo-local override file is
.claude/project-memory.jsonwithmode: "disabled" | "local"
CLI usage:
cat hook-envelope.json | project-memory-claude-hook --data-dir .memoryInstall local Claude settings for this repo:
node ./packages/adapters/claude-code/dist/cli.js install-settings \
--settings-file .claude/settings.local.jsonInstall global Claude settings into the user-level Claude config:
node ./packages/adapters/claude-code/dist/cli.js install-settings \
--target global \
--command 'project-memory-claude-hook'This writes managed hook entries for:
SessionStartPostToolUsePostToolUseFailureStopSessionEndPreCompactUserPromptSubmitPostCompactStopFailureSubagentStopPreToolUseSetup
By default the generated hook command is:
cd "$CLAUDE_PROJECT_DIR" && node ./packages/adapters/claude-code/dist/cli.js --data-dir "$CLAUDE_PROJECT_DIR/.memory/project-memory"If you want to override the managed command explicitly:
node ./packages/adapters/claude-code/dist/cli.js print-settings \
--command 'node ./packages/adapters/claude-code/dist/cli.js' \
--data-dir '$CLAUDE_PROJECT_DIR/.memory/project-memory'For user-level global installs, omit --data-dir so the hook can resolve
explicit path > repo override > legacy local > shared global storage at runtime.
If you only want the JSON snippet without writing .claude/settings.local.json:
node ./packages/adapters/claude-code/dist/cli.js print-settingsValidate that the local Claude settings still contain exactly one managed Project Memory hook per supported event:
node ./packages/adapters/claude-code/dist/cli.js validate-settings \
--settings-file .claude/settings.local.jsonOperational notes:
install-settingsis idempotent for the managed Project Memory hook entries- unrelated Claude hooks already present in
settings.local.jsonare preserved - the generated commands include a managed marker so later installs replace only Project Memory entries
SessionStartonly emitshookSpecificOutput.additionalContextwhen the recall packet contains meaningful active claims or open threadsSessionStartmay include a continuation checkpoint ahead of active claims when a recent checkpoint survives rehydration verification- default tool observations stay on the stable outcome contract only; experimental outcomes such as
human_approved,human_rejected, andclaim_supersededare intentionally not emitted - Bash observations persist the full raw payload as a local artifact ref under the runtime data dir while the runtime-facing event only keeps a compact summary plus digests
- current public message APIs still normalize to
import.transcript; trustedclaude_code.hook.*capture paths remain opt-in only
Current CLI support:
SessionStartPostToolUsePostToolUseFailureStopSessionEndPreCompactUserPromptSubmitPostCompactStopFailureSubagentStopPreToolUseSetup
