Shared project memory for Claude Code, Codex, and OpenCode.
Kernel gives Claude Code, Codex, and OpenCode a small shared memory layer for a project. It installs session hooks that read recent context at startup and write high-signal session notes plus estimated token usage at shutdown.
Kernel is intentionally small: no server, no database, no background daemon, and no runtime dependencies. Each project gets a local .kernel/MEMORY.md file that agents can share through their native hook systems.
| Layer | Technology | Why it is here |
|---|---|---|
| Runtime | Node.js | Portable CLI and hook execution across local agent tools |
| Language | TypeScript | Strict, typed source for maintainable hook parsing |
| CLI | kernel bin |
One command to initialize project memory and register hooks |
| Storage | Markdown + JSONL | Human-readable memory and append-only local token estimates |
| Hooks | Claude Code, Codex, OpenCode | Native startup/shutdown integration without a daemon |
| Testing | Vitest | Fast unit tests for scanners, hook input parsing, memory, and registry behavior |
| Local Models | Ollama | Token-free Claude Code/OpenCode experiments with local models such as Gemma |
| Packaging | npm | Public distribution through kernel-agent-memory |
| Hosting | GitHub | Public source, issues, and release history |
- Shared memory store — human-readable
.kernel/MEMORY.md - SessionStart context — injects the five most recent memories into new agent sessions
- SessionEnd capture — extracts decision, implementation, fix, architecture, avoid, and code-snippet lines
- Local token tracking — appends estimated usage to
.kernel/token-log.json - Agent hook registration — updates Claude Code, Codex, and OpenCode hook surfaces while preserving existing settings
- Zero runtime dependencies — offline-first and project-local
- Codex hook registration has been verified with a real Codex CLI smoke test.
- Codex session capture works even when the hook payload does not include a transcript path; Kernel discovers the matching
~/.codex/sessions/**/*.jsonlfile by session id or project cwd. - OpenCode write-back reconstructs assistant messages from local
~/.local/share/opencode/storageJSON files. - Claude Code startup injection uses
SessionStartadditionalContext; OpenCode startup injection uses its chat system transform hook. - Live Claude Code and OpenCode conversation tests depend on those CLIs and the selected model provider being available locally. For token-free Claude Code testing, use Ollama as shown below.
npm install kernel-agent-memoryBuild the CLI:
npm run buildInstall hooks for the current user and create .kernel/MEMORY.md in the current project:
npm link
kernel initAfter publishing, users can run it without cloning:
npx kernel-agent-memory initCreate a scratch project, install hooks, run Codex once, then inspect the shared memory file:
mkdir /tmp/kernel-smoke
cd /tmp/kernel-smoke
npx kernel-agent-memory init
codex exec --skip-git-repo-check -C "$PWD" \
"Reply exactly: Decided: kernel smoke test memory works."
cat .kernel/MEMORY.mdYou should see a codex memory entry containing the Decided: line.
If you have Claude Code installed but want to route it through a local Ollama model, launch it through Ollama's Claude Code integration:
ollama launch claude --model gemma4:e4b --yes -- \
-p "Reply with the Kernel project context you received. Do not inspect files."OpenCode can be launched through Ollama in the same style:
ollama launch opencode --model gemma4:e4bWatch TypeScript files for changes:
npm run devnpm testVerify TypeScript without emitting files:
npm run typecheckKernel consists of:
- CLI —
kernel initcreates project memory and registers hooks. - Memory Store —
.kernel/MEMORY.mdstores timestamped entries by agent. - Session Scanner — deterministic regex heuristics extract useful snippets from transcripts.
- Token Log —
.kernel/token-log.jsonstores newline-delimited usage estimates. - Hook System — SessionStart/SessionEnd integration with Claude Code, Codex, and OpenCode.
None. Kernel runs entirely offline.
Optional variables used by hooks:
KERNEL_PROJECT_ROOT— project directory to read/write; defaults toprocess.cwd()AGENT_TYPE— agent label stored with memory and token entriesKERNEL_MODEL,CLAUDE_MODEL, orOPENAI_MODEL— model label for token entries
- Claude Code: installs
SessionStartandStopcommand hooks in~/.claude/settings.json. Claude passes JSON on stdin withcwdandtranscript_path; Kernel returnshookSpecificOutput.additionalContextat startup and parses the transcript at shutdown. - Codex: installs
SessionStartandStopcommand hooks in~/.codex/hooks.json, and enablesfeatures.codex_hooks = truein~/.codex/config.toml. Kernel also discovers Codex JSONL transcripts from~/.codex/sessionswhen Codex does not pass a transcript path directly. - OpenCode: installs a global plugin at
~/.config/opencode/plugins/kernel-memory.js. Kernel injects memory through OpenCode'sexperimental.chat.system.transformhook and reconstructs assistant text from local~/.local/share/opencode/storageJSON files when the session becomes idle.
.
├── src/ # TypeScript source files
│ ├── cli.ts # CLI entry point
│ ├── agent-registry.ts # Agent config hook registration
│ ├── memory.ts # File-based memory store
│ ├── session-scanner.ts # Transcript snippet extraction
│ ├── token-log.ts # Local token usage log
│ └── hooks/ # SessionStart and SessionEnd commands
├── dist/ # Compiled JavaScript (generated)
├── .kernel/ # Kernel runtime directory (generated)
│ ├── MEMORY.md
│ ├── token-log.json
├── package.json
├── tsconfig.json
├── VERSION.md
└── README.md
- MCP memory tools for explicit agent reads/writes
- Dashboard for token and memory trends
- More agent adapters as hook APIs stabilize
- SQLite backend and cross-project memory index
MIT
