Inside Claude Code's PreCompact and SessionStart Hooks: Deterministic Memory Injection Without RAG Noise A developer built claude-code-memory, an agent memory system that uses Claude Code's native SessionStart, PreCompact and Stop lifecycle hooks to inject a deterministic, bounded slice of a SQLite-backed bitemporal knowledge graph and AST-compacted source files instead of vector RAG. The SessionStart handler builds a query hint from the hook payload and retrieves a subgraph at depth=2 and limit=15, while PreCompact pairs graph facts with ASTCompactor summaries of up to six files, all truncated to a 6000-character budget and returned via Claude Code's hookSpecificOutput contract. The approach separates valid time from transaction time and tags critical constraints as invariants, so stale design docs are not resurfaced after a migration. Most agent memory systems fail for the same reason: they treat every context window problem as a vector search problem. When an agent starts a session or hits a context compaction boundary, dumping top-k cosine similarity chunks into the prompt introduces stale architectural assumptions, partial code snippets, and high token overhead. In claude-code-memory , we took a different route. Instead of embedding chunks and hoping retrieval ranks the right paragraph, the system uses Claude Code's native lifecycle hooks SessionStart , PreCompact , and Stop to inject a deterministic, bounded slice of a SQLite-backed bitemporal knowledge graph and AST-compacted source files. Vector RAG is probabilistic and stateless with respect to time. If a team migrates from REST to gRPC on Tuesday, a semantic search on Wednesday will still surface Monday's REST design docs because the wording matches the query. A bitemporal graph separates valid time when a fact is true in the codebase from transaction time when the database recorded it , and marks critical constraints as invariants. Combining that graph with lifecycle hooks gives three concrete properties: SessionStart or right before the conversation history is summarized PreCompact . max chars = 6000 by default so memory never crowds out the active task. .claude/memory.db . When Claude Code fires a SessionStart hook, handle hook in claude code memory/hooks.py reads the incoming JSON payload and constructs a query hint by joining non-empty values from four payload keys: prompt , query , custom instructions , and reason . It then opens BitemporalGraph at .claude/memory.db and calls retrieve subgraph query hint, depth=2, limit=15 . The returned edges are serialized inside a