Skip to content

Claude Code tutorial

Claude Code forgets everything when a session ends. Decisions made, dead ends explored, project conventions discovered — all of it is re-derived (or worse, contradicted) next time. agent-store fixes this with a store that lives inside the repo: the agent records what it learns as it works, and every later session starts from a compact summary of that memory instead of a blank slate.

This tutorial wires the two together end to end: setup, teaching the agent via CLAUDE.md, injecting context at session start, and a worked two-session example.

Setup

Initialize a store at the project root. init adds its instructions block only to a CLAUDE.md that already exists, so create one first if the project has none (touch leaves an existing file as it is):

$ touch CLAUDE.md
$ agent-store init
Initialized .agent-store/
Installed .agents/skills/agent-store/SKILL.md
Installed .agents/skills/agent-store-patterns/SKILL.md
Installed .agents/skills/agent-store-pipelines/SKILL.md
Installed .claude/skills/agent-store/SKILL.md
Installed .claude/skills/agent-store-patterns/SKILL.md
Installed .claude/skills/agent-store-pipelines/SKILL.md
Added instructions block to CLAUDE.md

Three things happened, all Claude Code-relevant:

  1. .agent-store/ was created (and gitignored) — the SQLite database.
  2. Three skills were installed into .claude/skills/, where Claude Code discovers them automatically. They teach the agent how to create records, query, and read context — no prompting needed.
  3. A managed instructions block was appended to CLAUDE.md. Without the file, the last line reads No AGENTS.md or CLAUDE.md found; ... instead: create it and re-run init. In a repo with skills but no block, Claude Code may write what it learns into a new CLAUDE.md instead of the store.

Commands find the store by walking up from the current directory, so they work from any subdirectory of the project.

The CLAUDE.md block

init manages this block between <!-- agent-store:start/end --> markers and never touches the rest of the file. Re-running init after an upgrade updates the block if you have not edited it; an edited block is kept and reported (delete it and re-run init to get the current wording):

<!-- agent-store:start -->
## agent-store
This project keeps its cross-session memory in agent-store, a queryable record store in `.agent-store/`.
- At session start, run `agent-store ctx` to see recorded decisions, tasks and notes. Run `agent-store init` only if it reports that no store was found.
- Record decisions, tasks and handoff notes in the store rather than in this file, e.g. `agent-store create decision area=<topic> choice=<what> reason=<why>` or `agent-store create task title=<what> status=pending`.
- Look things up with `agent-store find <query>` (e.g. `agent-store find kind=decision area=auth`); the installed `agent-store` skills have the full workflow.
<!-- agent-store:end -->

With it, the agent reads the store at session start and records decisions and tasks there. To make that stricter, add your own conventions outside the managed block:

## Project memory
- At the start of each session, run `agent-store ctx` before doing anything else.
- When you make a nontrivial technical decision, record it:
  `agent-store create decision area=<topic> choice=<what> reason=<why>`.
- Before deciding anything, check for prior art: `agent-store find kind=decision area=<topic>`.
- Track multi-session work as `task` records (`title`, `status`); set `status=done` when finished.

Injecting context at session start

agent-store ctx prints a Quick Context summary capped at 8192 bytes — record counts by kind, fields per kind, hooks, and the most recently updated records — sized to be pasted into a prompt. Claude Code's SessionStart hook can inject it automatically so every session opens already knowing the project's memory. In .claude/settings.json:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "agent-store ctx 2>/dev/null || true"
          }
        ]
      }
    ]
  }
}

Stdout from a SessionStart hook is added to the agent's context. The || true guard keeps sessions starting cleanly in repos without a store (ctx exits nonzero with error: no agent-store found there).

Note the two hook systems are different things: Claude Code hooks fire on agent lifecycle events and are configured in .claude/settings.json; agent-store hooks fire on store mutations and are managed with agent-store hook add/ls/rm. They compose — for example, mirror task changes into a log file the agent (or you) can tail:

$ agent-store hook add set kind=task -- 'echo "$AGENT_STORE_ID $AGENT_STORE_FIELD: $AGENT_STORE_OLD_VALUE -> $AGENT_STORE_NEW_VALUE" >> .agent-store/task-changes.log'
ev9c7i

Worked example: memory across two sessions

Session 1 — the agent evaluates HTTP clients, picks one, and records the decision plus the follow-up work:

$ agent-store create decision area=http choice=reqwest reason="no openssl dep"
8idetm

$ agent-store create task title="Migrate HTTP client to reqwest" status=pending
jia3eg

$ agent-store link jia3eg implements 8idetm
Linked jia3eg implements 8idetm

The session ends. The context window is gone; the records are not.

Session 2 — days later, with the SessionStart hook above, the new session opens with this already in context:

Quick Context
Records: 2
Record kinds:
  decision: 1
    fields: area, choice, reason
  task: 1
    fields: status, title
    status: pending=1
Links: 1
  implements: 1
Hooks: 0
Schedules: none
Latest activity: 2026-10-23T02:36:12.333Z
Recent records:
  jia3eg task status=pending title='Migrate HTTP client to reqwest'
  8idetm decision area=http choice=reqwest reason='no openssl dep'

The agent sees pending work and the reasoning behind it without being told. When it needs detail, it queries — asked "should we use openssl?", it can check prior art instead of re-litigating:

$ agent-store find kind=decision area=http
8idetm decision area=http choice=reqwest reason='no openssl dep'

It finishes the migration and closes the loop:

$ agent-store set jia3eg status=done
Updated jia3eg

Any unambiguous ID prefix works (agent-store set jia status=done), so recalled IDs from ctx output are cheap to reuse.

Troubleshooting

  • error: no agent-store found; run 'agent-store init' first — no .agent-store/ in the current directory or any ancestor. Run init at the project root, or check you're inside the right project.
  • The agent isn't using the store — confirm the managed block is in CLAUDE.md (re-run agent-store init if not) and the skills exist under .claude/skills/. Nudging conventions (see the CLAUDE.md section above) help far more than the minimal block alone.
  • ctx output looks truncated — by design: it's capped at 8192 bytes, dropping oldest records first. Use find with a query for anything the summary doesn't surface.
  • Session-start hook shows nothing — run agent-store ctx manually in the project to check it succeeds, and verify the hook with claude → /hooks or by inspecting .claude/settings.json. Hook config changes apply to new sessions.
  • agent-store hooks don't fire on Windows — hook commands run via bash -c; install Git Bash or WSL so bash is on PATH. See Hooks.
  • Cloned an untrusted repo? — a committed store can ship hooks, which are arbitrary shell commands. Inspect agent-store hook ls (or delete .agent-store/) before running mutation commands. See SECURITY.md.

See also: Claude Code, Codex and Cursor — which files each agent reads and the fresh-repo step; Concepts — the mental model behind records, links, queries, and ctx; Skills and agent integration — what init installs; Hooks — store-mutation hooks in depth; FAQ — data format, concurrency, privacy, and limits.