Updates are paused · v0.1.3 is the current release and stays current until work resumes
Open-source memory infrastructure

Memory for coding agents.Context for every decision.

CogniKernel 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]"
License
Apache-2.0
Runtime
Python 3.11+
Storage
Local SQLite
Hard constraint Decision Soft constraint Abandoned Recalled

Fig. 1 — An illustrative project; gold marks recall for the current prompt

Section 01 — The problem

Every session starts from zero.

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.

Without memoryfiles read: 12
With CogniKernelfiles read: 12

Illustrative. The measured numbers, including where memory doesn't pay off, are in Benchmarks.

Within a session

Context rot

A long session's window fills with stale tool output and superseded instructions until quality degrades.

Between sessions

Cold starts

The moment a session ends, its understanding is gone. The next one pays the "getting up to speed" cost again.

Across weeks

Repeated mistakes

The approach abandoned on Tuesday returns on Thursday, because nothing recorded why it failed.

Section 02 — Capabilities

Five operations, one kernel.

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.

01

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.

Stop hook · extraction/pipeline.py
02

Connect

Link 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.

MCP find_related · symbols/
03

Retrieve

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.

MCP recall · retrieval/hybrid.py
04

Consolidate

Merge 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_xenc
05

Timeline

Replay 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 why
Section 03 — Architecture

One loop around one kernel.

Observe, 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

SessionStart

Session block

Injects the canonical block: constraints, decisions, dead ends, the open work item and an AST skeleton of the codebase.

advisory
Why it matters: no "let me re-read the codebase to remember where we were."
UserPromptSubmit

CK-1 recall

Surfaces memory relevant to what you just typed. It needs two kinds of evidence, and skips anything already in context.

advisory
Why it matters: ask about a subsystem and the prior decision rides in with your prompt, unasked.
PreToolUse

Read/Edit gate

Refuses 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-in
Why it matters: the warning lands as an edit is about to break a past decision, not three files later.
Stop

Capture

Extracts and persists what this session decided, tried and ruled out, through the deterministic pipeline.

side-effect
Why it matters: you never hand-write memory into CLAUDE.md again.

Fig. 3 — Four points of contact, in session order

Fail-openIf memory is unavailable or errors, each hook logs at WARNING, returns cleanly, and the session continues. Silence never reads as success: cognikernel doctor names any degraded subsystem.
Section 04 — Memory model

How a decision becomes durable knowledge.

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.

  1. I

    Decision

    A choice is made in a session, with its reason: "use Redis, the counts must be shared across workers."

  2. II

    Event

    At session end, salience_v2 types the sentence and it's appended as a typed event, with evidence and provenance.

  3. III

    Consolidation

    Same decision key, latest wins. Restatements merge into one record (×N). Superseded claims are marked, never deleted.

  4. IV

    Kernel

    One SQLite store per project, shared by Claude Code and Codex. The single source of truth about what the project knows.

  5. V

    Retrieval

    Ranked by authority, fitted to the token budget and injected into the next session, closing the loop.

Fig. 4 — Event-sourced memory pipeline

Decision

A choice that was made. A later restatement with the same key supersedes it.

"use Redis for the rate limiter"
Constraint · hard

A rule that must not be broken. Ranked ahead of everything else when the block is fitted to its budget.

"never log webhook payloads in full"
Constraint · soft

A preference or convention, graded by how strongly it was stated.

"prefer dataclasses over dicts"
Abandoned

A dead end, kept in the graveyard with the reason it failed, so it isn't tried again.

"in-process cache → counts drift"
Section 05 — Project evolution

Time is an orbit, not a line.

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

Section 06 — The injected block

What the agent sees at session start.

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.

SessionStart · additionalContext

      

HeaderWhere you are

Project, session number and a state version, so the agent knows how much history sits behind the block.

HardNever violate

Ranked ahead of everything else. (×3) means three sessions stated the same rule and it was consolidated into one record.

ThreadActive thread

The open work item, carried over with its origin: (S3 · 09-12) means session 3, September 12.

SkeletonWhere to look

The hottest files, backed by an AST skeleton of classes, methods and imports, so getting oriented costs fewer reads.

GraveyardDo not retry

Abandoned approaches with the reason they failed, so the agent doesn't spend a session rediscovering it.

DecisionsKey decisions

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.

In a session

Picks up where the last one stopped.

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.

~/code/relay — claude
Section 07 — The fine-tuned models

Classification, not generation.

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.

salience_v2
Decides what gets remembered

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.

Decision Hard Soft Abandoned Noise
Kind
SetFit classifier
Runtime
ONNX on CPU
Latency
Milliseconds
supersession_xenc
Decides what gets replaced

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.

P(supersede) ≥ threshold → mark superseded Below → keep both
Kind
Cross-encoder
Threshold
Precision-calibrated
Deletes
Never
salience_v2 on a transcript · illustrative
"Let's go with Redis for the limiter, since the counts have to be shared across workers."Decision
"Never write the raw webhook body to the logs, it carries customer PII."Hard
"The in-process cache didn't work: each worker kept its own count."Abandoned
"Now let's run the full test suite."Noise · narration
"Summary: 13/13 tests pass."Noise · answer line
CogniKernelLLM-summarizer memoryHand-written CLAUDE.md
Extra model API callsNone, encoders run locallyOne or more per sessionNone
API keysNoneRequiredNone
Session content leaves the machineNoYesNo
Captured automaticallyYes, at session endYesNo, you write it
Contradictions resolvedLatest wins by decision keyDepends on the promptOnly if you edit it
Read by Codex tooYes, shared store over MCPVariesNo, Codex doesn't load it
DeterministicYes, same input, same blockNoYes
Evaluation

Held-out data, not vibes.

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%.

Fail-open

Optional, on by default.

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.

Section 08 — Benchmarks

Measured, including where it loses.

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.

Read this first
Internal, directional, single-evaluator. Four projects, one agent model, one run per arm, no confidence intervals. Built to resist self-flattery, but not an independent study. Full method in docs/benchmark.md.
4of 4
projects needed fewer orientation reads than with native auto-memory.
§3 · passive effects
0.90
recall score when Codex read a store that Claude Code built. Flat memory scores 0: Codex can't read it.
§1 · 13.5 of 15 probes
100%vs 33%
of abandoned approaches recalled on Relay. Auto-memory re-proposed dead ends the project had ruled out.
§2 · graveyard probes
0.1.3
the current release on PyPI. Apache-2.0, tested in CI on Linux and Windows.
Open source

Orientation reads

Reads before the first line of code: the cost of working out where you are. Fewer is better.

CogniKernelNative auto-memory

Weighted cost vs. auto-memory

CogniKernel's price-weighted session cost relative to auto-memory. Left of zero is cheaper.

Adverse findings

Where it doesn't win.

  • Small, re-readable projects. On Taskflow and Toolbelt, auto-memory scored higher on cross-session recall. When a project is cheap to re-read, structured memory adds little.
  • Against no memory at all, it isn't always cheaper. On Relay, the project where it beats auto-memory by the widest margin, CogniKernel cost 23% more than the no-memory arm, from the round trips its own tools add.
  • Where it repays its overhead: projects that pile up several evolving decisions and several abandoned approaches. Relay had three supersession chains and three graveyard entries, and it's the only project where CogniKernel leads on every dimension.

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.

Section 09 — Retrieval

Lexical first, dense as a signal.

Never pure vector search. Exact terms matter in code, so BM25 leads and embeddings vote.

01
Hybrid coreSQLite FTS5 BM25 ∪ optional dense embeddings, fused with Reciprocal Rank Fusion.
02
prohibition_searchA type-restricted pool, so a "do not do X" rule can't be crowded out by similar-sounding prose.
03
Skeleton graphAn AST symbol graph ranked by PageRank. find_related unions semantic neighbours with import-graph neighbours.
04
Golden records at readLatest-wins reconciliation at query time, so recall returns one answer per key.
Section 10 — Reliability

Degrades legibly, never silently.

A memory layer that fails quietly is worse than none. Every failure path is tested and visible.

01
Atomic migrationsEach numbered migration applies its body and version bump in one transaction. Safe to crash mid-script.
02
Idempotent replayA re-run worker job can't double-count evidence or drift decay.
03
doctor --strictPer-subsystem health (schema, FTS5, embeddings, symbols, worker queue) with a non-zero exit when degraded.
04
Enforced architectureimport-linter layer contracts, guarded by a meta-test so a typo can't silently switch them off.
05
CI promotion gateLint plus the full suite, including failure-injection tests, on Ubuntu (3.11, 3.12) and Windows.
Section 11 — Cross-platform

Two agents, one kernel.

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

Claude Code

  • ●Session block at start
  • ●Per-prompt recall (CK-1)
  • ●PreToolUse guardrails
  • ●Capture on Stop

Codex

  • ●Block and recall over MCP
  • ●Pull capture with codex-sync
  • ●Drained automatically at Claude's session start
  • ○No per-prompt or per-tool hooks

Paths 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.

Section 12 — Get started

One install. Then it remembers.

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.

1

Install

The [embedding] extra adds dense retrieval and the runtime for the fine-tuned encoders. Recommended.

2

Set up the project

Registers the project and installs hooks and MCP for Claude Code and Codex.

$ cognikernel init .
$ cognikernel install-heads # ~270 MB, one-time, sha256-verified
3

Verify

Confirms every subsystem is wired up, and names the fix for anything that isn't.

$ cognikernel doctor .
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.

That's it. Start a Claude Code session in the project. Decisions are captured when it ends and injected as a compact block the next time you start.
Section 13 — Reference

CLI and MCP tools.

The block arrives on its own. These are for looking inside, asking why, or targeting recall yourself.

Section 14 — Questions

Answered plainly.

Does any of my code or conversation leave my machine?

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.

Is this another LLM summarizing my transcripts?

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.

Is it a vector database wrapper?

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.

What happens if I skip 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.

Which agents and platforms are supported?

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.

Will it slow my sessions down or block my edits?

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".

How do I see what it remembered, or why?

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.

What does "updates are paused" mean for me?

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.

Stop paying for the same context twice.

Install it once, keep working the way you already do, and let the next session start where this one left off.