Main project · 秋刀魚
Sanma
Claude Code that doesn't forget. Sanma gives Claude Code a structured project memory that persists across sessions, compactions and restarts.
Python · Claude Code hooks · Sonnet 4.6 · Haiku 4.5
Problem
When a session grows past the context window, automatic compaction discards earlier turns without notice, and the model gradually loses the premise of the discussion. After switching sessions, you have to re-explain yesterday's decisions. Architecture choices, rejected options and open questions become hard to find in the chat history.
How it works
Claude Code runs two hooks automatically every turn. The Stop hook reads the latest exchange and outputs diff operations that add, replace or delete facts. Sanma's code validates these operations and applies them to a per-chat knowledge tree on disk. The UserPromptSubmit hook injects a compact topic index of that tree with no model call and near-zero latency.
When the main model needs a stored fact, it runs a search command, and Sanma returns the matching details verbatim. Sanma uses a pull architecture. The main model is the only party that knows what it needs, so it reads the table of contents and requests exact facts itself.
Data model
Sanma stores a three-level tree: sun (top-level topic) → planet (subtopic) → satellite (detail). A planet's mass increases each time the conversation returns to it. The injected index shows each mass, so the model can see which subjects the chat has discussed before. HAMIB uses the same data model, and both come from the same technical report.