DocsGetting started
Claude Code
One command, and Claude Code checks memory before it acts and saves what it learns — without you asking.
Setup
memorylayer namespace set <project-name> # optional, keeps this project's memories apartmemorylayer setup --ide claude --yesSafe to re-run: it updates its own marked block and leaves the rest of your CLAUDE.md alone. Undo it all with memorylayer setup --remove --ide claude --yes.
What setup adds
MCP server
Lets Claude Code start MemoryLayer. Nothing else works without it.
~/.claude.jsonHooks13 scripts · 16 events
Run on their own at set moments in a session.
~/.claude/hooks/~/.claude/settings.jsonWhat each hook does ↓Rules
Always-on instructions Claude reads every session.
~/.claude/CLAUDE.mdRead an excerpt ↓Skill
A /memorylayer reference card; the project copy wins.
~/.claude/skills/memorylayer/.claude/skills/memorylayer/
Hooks
A hook is a script Claude Code runs by itself at a set moment, the way a linter runs on save. Tap one to see what it does.
When a session starts
SessionStartSets the namespace and loads the skill- Resolves the namespace from
~/.memorylayer/namespaces.jsonand exportsMEMORYLAYER_NAMESPACE, so every Bash command sees it - Names the session after the project folder and watches
package.json,go.mod,Cargo.tomland friends - Reloads the /memorylayer skill and reports whether the code index is up to date
~/.claude/hooks/memorylayer_session_start.js- Resolves the namespace from
CwdChangedFollows you into another project- Re-resolves the namespace for the new directory and updates
MEMORYLAYER_NAMESPACE
~/.claude/hooks/memorylayer_cwd_changed.js- Re-resolves the namespace for the new directory and updates
Every prompt
UserPromptSubmitPuts memory in front of Claude before it answers- First turn: loads your
rule,constraintandguidememories from every namespace, as content rather than a reminder - Every turn: tells Claude to recall from the project namespace and which tool fits the question
- Ingest guard: skips re-indexing when the git commit hasn't changed
~/.claude/hooks/memorylayer_user_prompt_submit.js- First turn: loads your
Around every tool call
PreToolUseMemory first, then filescan block- The first Read, Grep, Glob or Bash of a turn is denied until
recall()orcode()has run - The retry is always allowed, so a turn can't get stuck when memory has nothing
- Before Edit or Write it asks for
code(impact)and a check for known errors
~/.claude/hooks/memorylayer_pre_tool_use.js- The first Read, Grep, Glob or Bash of a turn is denied until
PostToolUseLifts the gate and nudges good habits- After
recallorcode: marks memory as consulted, which opens the PreToolUse gate for the turn - After edits: reminds Claude to track errors as one memory each, open → fixed
~/.claude/hooks/memorylayer_post_tool_use.js · memorylayer_mark_used.js- After
PostToolUseFailureTurns a failed tool call into an error memory- Checks whether the error is already known, opens
[error][open]if not, and closes it as[error][fixed]once solved
~/.claude/hooks/memorylayer_post_tool_use_failure.js- Checks whether the error is already known, opens
When Claude finishes a reply
StopCheck the claims, save the learnings- Reminds Claude to run
verify()on facts it just stated and to save anything new - Fires at most once per turn, so short replies don't get nagged
- StopFailure fires every time — each failure is worth an error memory
~/.claude/hooks/memorylayer_stop.js- Reminds Claude to run
When the context fills up
PreCompact · PostCompactSave before the trim, reload after- Before: asks Claude to write down decisions and open errors — nothing else survives the trim
- After: loads priority memories straight back in, because the reminder to recall was trimmed too
~/.claude/hooks/memorylayer_compact.js
Subagents and tasks
SubagentStart · SubagentStopSeed the helper, keep what it found- Start: gives the subagent the memories that match its task, since it begins with none of the conversation
- Stop: asks Claude to keep any fix, pattern or decision the subagent surfaced
~/.claude/hooks/memorylayer_subagent.jsTaskCreated · TaskCompletedRecall past attempts, save the outcome- Seeds the task with matching memories, then saves the result and closes related error memories
~/.claude/hooks/memorylayer_task.jsTeammateIdleCheap upkeep while an agent waits- Suggests
consolidate({ action: "ripple" })or an explore pass — optional, skipped when there's nothing open
~/.claude/hooks/memorylayer_teammate_idle.js- Suggests
When the session ends
SessionEndThe closing checklist- Runs in the background so exit isn't delayed: save guides, close errors, record the index, run
consolidate()
~/.claude/hooks/memorylayer_session_end.js- Runs in the background so exit isn't delayed: save guides, close errors, record the index, run
Every hook reads or writes one store~/.memorylayer/memories.db
CLAUDE.md rules
An excerpt of the managed block — the full text is on Agent rules.
## Error lifecycle- Hit error → recall(tags=["error"], query="<error>") — check if known- New error → remember({ tags: ["error","open"], priority: 7 })- Fix found → update SAME memory → tags: ["error","fixed","solution"] ## Before any Edit/Write1. code(impact, symbolName, depth=2) — callers, callees, test files2. recall(tags=["error"], query="<symbol>") — known issues ## Ingest rules- git SHA unchanged (hook tells you) → SKIP ingest entirely- Repo >500 files → ASK USER first, suggest sub-directoryWhich namespace is active
MemoryLayer walks up from the current directory and uses the closest match in ~/.memorylayer/namespaces.json.
memorylayer namespace get # what's active herememorylayer namespace list # every folder → namespace mappingSomething missing or wrong? Email support@memorylayer.in or open an issue.