Capture
An event becomes memory. When a session ends, the transcript is classified sentence by sentence and what matters is appended as typed events, with the evidence and the session it came from.
extraction/pipeline.pyCogniKernel is an event-sourced memory layer for Claude Code and Codex. It captures decisions, constraints, abandoned approaches and architectural knowledge, then injects the right context back into every coding session. Small encoders do the work on your CPU: no extra LLM, no API keys, nothing leaves your machine.
pip install "cognikernel[embedding]"
Fig. 1 — An illustrative project; gold marks recall for the current prompt
A model's weights are frozen, so its only memory is the context window. When a session ends, everything it learned about your project goes with it. Step through three sessions on the same question.
Illustrative. The measured numbers, including where memory doesn't pay off, are in Benchmarks.
A long session's window fills with stale tool output and superseded instructions until quality degrades.
The moment a session ends, its understanding is gone. The next one pays the "getting up to speed" cost again.
The approach abandoned on Tuesday returns on Thursday, because nothing recorded why it failed.
Each is a primitive of the memory system. They compose the way system calls compose: small, orthogonal, observable. Each card names where it lives in the code.
An event becomes memory. When a session ends, the transcript is classified sentence by sentence and what matters is appended as typed events, with the evidence and the session it came from.
extraction/pipeline.pyLink memories together. find_related unions semantic neighbours with import-graph neighbours, so a change surfaces what it touches. The codebase skeleton is ranked with PageRank.
find_related · symbols/Surface only what's relevant. BM25 full-text search and dense embeddings are fused with Reciprocal Rank Fusion, then ranked by authority and fitted to the token budget.
recall · retrieval/hybrid.pyMerge duplicate knowledge. Each claim has a decision key, and the latest wins. A fine-tuned cross-encoder catches paraphrased reversals. Superseded claims are marked, never deleted.
delta/supersede.py · supersession_xencReplay project evolution. show --as-of rewinds memory to any date or commit and shows exactly what it believed then. why traces a claim to its source, its rank, and what it replaced.
cognikernel show --as-of · cognikernel whyObserve, extract, consolidate, store, retrieve, assemble, inject. One side of the orbit captures, the other recalls, and the event-sourced store sits at the centre. Select a stage, or let it cycle.
Fig. 2 — The memory loop
Injects the canonical block: constraints, decisions, dead ends, the open work item and an AST skeleton of the codebase.
advisorySurfaces memory relevant to what you just typed. It needs two kinds of evidence, and skips anything already in context.
advisoryRefuses re-reading a file already read this session. On Write and Edit it surfaces a past "don't do X" just in time.
just-in-time strict opt-inExtracts and persists what this session decided, tried and ruled out, through the deterministic pipeline.
side-effectCLAUDE.md again.Fig. 3 — Four points of contact, in session order
WARNING, returns cleanly, and the session continues. Silence never reads as success: cognikernel doctor names any degraded subsystem.Deterministic and inspectable at every stage. Memory is typed, not loose text, and nothing is stored that can't be traced back to the session it came from.
A choice is made in a session, with its reason: "use Redis, the counts must be shared across workers."
At session end, salience_v2 types the sentence and it's appended as a typed event, with evidence and provenance.
Same decision key, latest wins. Restatements merge into one record (×N). Superseded claims are marked, never deleted.
One SQLite store per project, shared by Claude Code and Codex. The single source of truth about what the project knows.
Ranked by authority, fitted to the token budget and injected into the next session, closing the loop.
Fig. 4 — Event-sourced memory pipeline
A choice that was made. A later restatement with the same key supersedes it.
A rule that must not be broken. Ranked ahead of everything else when the block is fitted to its budget.
A preference or convention, graded by how strongly it was stated.
A dead end, kept in the graveyard with the reason it failed, so it isn't tried again.
Each ring is a session. Select one to see what memory believed at that point, the way cognikernel show --as-of does. One key, ratelimit.backend, changes its mind once and is never confused about it again.
Fig. 5 — One project, four sessions, rewound with --as-of
A compact, budgeted Markdown block. Hard constraints are ranked ahead of everything else, and the order is deterministic so the prompt cache keeps hitting. Hover a note to find its section.
Project, session number and a state version, so the agent knows how much history sits behind the block.
Ranked ahead of everything else. (×3) means three sessions stated the same rule and it was consolidated into one record.
The open work item, carried over with its origin: (S3 · 09-12) means session 3, September 12.
The hottest files, backed by an AST skeleton of classes, methods and imports, so getting oriented costs fewer reads.
Abandoned approaches with the reason they failed, so the agent doesn't spend a session rediscovering it.
Ranked by authority, recency and centrality, each tagged with the session that made it.
Rendered from the block template in injection/template.py. The project is illustrative and the skeleton is truncated.
The block arrives before your first prompt. The agent starts from the open work item and the decisions already made, instead of re-reading the codebase to find out where it was.
Most memory tools send your transcript to another LLM and ask it to "summarize what mattered." CogniKernel treats extraction as classification, so two small encoders run on your CPU in milliseconds.
For every sentence in the transcript: is this worth keeping, and what type is it? A fine-tuned SetFit classifier on a bge-small backbone, exported to ONNX.
Does a new fact replace a stored one (a decision changed, a constraint relaxed), or is it a different decision in the same area? It reads both claims together and scores the probability that one supersedes the other.
| CogniKernel | LLM-summarizer memory | Hand-written CLAUDE.md | |
|---|---|---|---|
| Extra model API calls | None, encoders run locally | One or more per session | None |
| API keys | None | Required | None |
| Session content leaves the machine | No | Yes | No |
| Captured automatically | Yes, at session end | Yes | No, you write it |
| Contradictions resolved | Latest wins by decision key | Depends on the prompt | Only if you edit it |
| Read by Codex too | Yes, shared store over MCP | Varies | No, Codex doesn't load it |
| Deterministic | Yes, same input, same block | No | Yes |
Each model is scored against a frozen evaluation set mined from real project stores that training never sees. Because "is this a decision?" is genuinely ambiguous at the margin, the bar is how well two independent human labelers agree with each other, not a naive 100%.
init configures the fine-tuned path; install-heads fetches the ~270 MB of sha256-verified weights. Skip it and CogniKernel still works on a deterministic lexical fallback, and doctor tells you which path is active.
A three-arm comparison: CogniKernel, Claude Code's native auto-memory, and no memory, with real agent sessions on four multi-session projects. Same prompts, same order, same model.
docs/benchmark.md.Reads before the first line of code: the cost of working out where you are. Fewer is better.
| Project | CK | Auto | Δ |
|---|
CogniKernel's price-weighted session cost relative to auto-memory. Left of zero is cheaper.
| Project | Reads Δ | Raw tokens Δ | Weighted Δ |
|---|
Token figures corrected 2026-09-10: an earlier version counted usage once per transcript line instead of once per API response. Reads and recall scores were unaffected.
Never pure vector search. Exact terms matter in code, so BM25 leads and embeddings vote.
find_related unions semantic neighbours with import-graph neighbours.A memory layer that fails quietly is worse than none. Every failure path is tested and visible.
doctor --strictPer-subsystem health (schema, FTS5, embeddings, symbols, worker queue) with a non-zero exit when degraded.import-linter layer contracts, guarded by a meta-test so a typo can't silently switch them off.The store is keyed on the project, not the tool. A decision made in Codex reaches the next Claude Code session's block, and the other way round.
Fig. 6 — Shared kernel, two orbits
Stoprecall over MCPcodex-syncPaths are alias-aware: C:\repo and /mnt/c/repo resolve to the same store. init writes .mcp.json, .codex/config.toml and AGENTS.md without clobbering what's there.
Python 3.11 or newer. Run the setup once per project, from its root. No service to provision, no vendor between you and your project's history.
The [embedding] extra adds dense retrieval and the runtime for the fine-tuned encoders. Recommended.
Registers the project and installs hooks and MCP for Claude Code and Codex.
$ cognikernel init .$ cognikernel install-heads # ~270 MB, one-time, sha256-verifiedConfirms every subsystem is wired up, and names the fix for anything that isn't.
$ cognikernel doctor .-- subsystem health ----------------------------------------- [OK] config : global + project config parse clean [OK] schema : v22 (current) [OK] fts5 : available (lexical retrieval active) [OK] embedding : model loaded [OK] salience_head : installed, loads from ~/.cognikernel/models/salience_v2 [OK] supersession_head: installed, loads from ~/.cognikernel/models/supersession_xenc [OK] symbols : python ast + typescript OK [OK] worker_queue : no dead-letters (0 retryable) [OK] codex : sessions dir present (14 rollouts) — cross-platform capture active status : OK
Line formats match doctor; the counts are illustrative. Skipped install-heads? Those lines say not installed and name the command. That's informational, never a --strict failure.
The block arrives on its own. These are for looking inside, asking why, or targeting recall yourself.
No project code or conversation is uploaded. Extraction, consolidation, storage, retrieval and model inference run locally against a SQLite database. With the recommended [embedding] extra, CogniKernel may download the local embedding model during initialization, and install-heads can download the fine-tuned weights; both paths fail open to lexical operation when unavailable.
No. It's a deterministic sanitize → classify → consolidate pipeline. Two small fine-tuned encoders (~130 MB ONNX each, milliseconds on CPU) score salience and detect supersession. The only LLM involved is the coding agent you already run.
No. Retrieval is lexical-first (SQLite FTS5 BM25) with optional dense embeddings fused in through Reciprocal Rank Fusion. Memory is stored as typed events with provenance, not as loose text chunks.
install-heads?Everything still works on a deterministic keyword and lexical fallback. It's weaker: it can miss decisions phrased outside its trigger vocabulary, and paraphrased corrections. cognikernel doctor tells you which path is active.
Claude Code gets the full loop: session block, per-prompt recall, PreToolUse guardrails and capture on Stop. Codex gets the shared block and MCP recall, with capture pulled by codex-sync. CI runs on Ubuntu (Python 3.11 and 3.12) and Windows; WSL paths resolve to the same store as their Windows equivalents.
Hooks are fail-open and advisory by default. New projects start with the advisory read gate, which only refuses re-reading a file already read in the same session. Strict mode, which also refuses first reads of files in the skeleton, is opt-in with hook_policy = "strict".
cognikernel show prints the store. cognikernel why <#id or words> explains where a claim came from, why it ranks where it does, and what it replaced. show --as-of <date|commit> shows what memory believed at that point. cognikernel reset clears it.
Development is on hold until further notice. v0.1.3 is the current release and stays current. It's stable, tested in CI and Apache-2.0 licensed, so you can use it, fork it or build on it.
Install it once, keep working the way you already do, and let the next session start where this one left off.