memory-runtime gives Codex, Claude, and Gemini a compact hot/cold memory layer
for project context.
It saves tokens without rewriting the user request, stays fail-open when memory providers are unavailable, and keeps host integrations replaceable.
Use it when you want:
- automatic project bootstrap for CLI agents
- local hot memory with optional Memory Palace cold memory
- safer recall for short references like
route A,this, orthat - explicit local skill governance without silent edits
- public-repo-friendly export tooling for sanitized memory assets
Quick links:
- Chinese quick start:
README_CN.md - Docker cold memory:
docs/COLD_MEMORY_DOCKER.md - Codex app integration:
docs/CODEX_APP.md - Configuration:
docs/CONFIGURATION.md - Setup guide:
docs/SETUP.md - Privacy and safe publishing:
docs/PRIVACY.md - Memory Palace project tools:
docs/MEMORY_PALACE_PROJECT_TOOLS.md - Public export workflow:
docs/PUBLIC_EXPORT.md - Troubleshooting:
docs/TROUBLESHOOTING.md - Changelog:
CHANGELOG.md
This repo is ready for public GitHub use as an 0.x GitHub-first runtime:
- hot memory is backed by local SQLite via
node:sqlite - cold memory can use a real Memory Palace backend
- Claude and Gemini wrappers are implemented
- Codex stays native and uses
AGENTS + hmctlfor memory integration - Codex can optionally enable the hot-only
memory-hotMCP without enabling the full runtime MCP - shell integration can be installed with one command
- cold-memory autostart is optional and fail-open
- ambiguous short references are anchor-expanded or cold-recall-suppressed
- local skill governance supports audit, explicit apply, rollback, and benchmark flows
The current distribution model is:
- clone from GitHub
- run locally
- install shell integration into
zshorbash - optionally audit, apply, rollback, and benchmark local skill governance
It is not an npm-published product yet.
The runtime is split into replaceable layers:
memory-core: contracts, token budget policy, routing ruleshot-memory-sqlite: fast local hot-state providercold-memory-memory-palace: cold-memory adapter for Memory Palacecold-memory-fixture: deterministic fixture adapter for tests and benchmarkshost-codex: Codex bootstrap and checkpoint integration surfacehost-claude: Claude-oriented bootstrap rendering surfacememory-hot-mcp: optional hot-only MCP for local SQLite state and continuitymcp-bridge: optional stdio bridge for inspection and promotion flows
CLI host
-> host adapter
-> memory-core
-> hot provider
-> cold provider
- high cohesion, low coupling
- fail-open behavior that never blocks normal development
- fast local bootstrap with strict latency and token budgets
- replaceable hot and cold memory providers
- ambiguous short references should recall less rather than recall wrong
- public-repo-friendly code with no bundled personal memory data
- Node.js
22+withnode:sqlitesupport - npm
10+ - at least one supported host CLI already installed: Codex, Claude, or Gemini
zshorbashif you want shell helpers such ashmctl- optional: a running Memory Palace backend for cold recall
- optional for Docker cold memory: Docker with
docker compose
- Clone the repo and install dependencies:
git clone https://github.com/Tom-Wang898/memory-runtime.git
cd memory-runtime
npm install- Install shell integration:
./scripts/install-shell-integration.sh --shell zshUse --shell bash if you want ~/.bashrc instead.
- Reload the shell:
source ~/.zshrc- Verify the shell helpers and routed context path:
codex --help
claude --help
gemini --help
hmctl primer --cwd "$(pwd)" --mode warm --json
hmctl continuity --cwd "$(pwd)" --json
hmctl context --cwd "$(pwd)" --query "continue with the current route" --json
hmctl bootstrap --cwd "$(pwd)" --mode warm --query "runtime smoke test" --jsonExpected:
codexstays the native host CLIhmctlis available as the memory sidecar commandhmctl primerreturns a compact primer and writes a cache filehmctl continuityreturns a compact active-state recovery packhmctl contextauto-routes between primer, continuity, and bootstraphmctl bootstrapreturns the fuller fallback payload for query-specific recallclaudeandgeminimay still be wrapped through shell integration
If you stop here, the runtime already works in hot-memory mode and will fail open if cold memory is unavailable.
The normal Codex path is:
- read a tiny cached primer
- use continuity for continuation-style queries
- only fall back to full bootstrap when the task needs more context
That matters because both primer and continuity are intentionally smaller than the full Codex bootstrap envelope:
- primer keeps only a short background line plus a few deduplicated points
- continuity keeps the current route, pinned constraints, next step, and active open loops
- primer is cached per project, so repeated project turns do not have to rebuild full context
- continuity is cached separately, so “continue / route A / next step” style turns do not need full bootstrap
- bootstrap still uses the same hot/cold runtime, but it is reserved for query-specific recall
Run this to compare the sizes:
npm run bench:tokensThat benchmark reports token estimates for:
- compact primer text
- continuity text
- full Codex bootstrap envelope
- naive JSON-sized context
- Optional: audit local skills without editing them:
hmctl skills-auditYou can also point it at one explicit tree:
hmctl skills-audit --root "$HOME/.codex/skills" --json- Optional: generate a safe mutation plan first:
hmctl skills-plan --root "$HOME/.codex/skills" --host codex- Optional: apply managed changes with an automatic snapshot:
hmctl skills-apply --root "$HOME/.codex/skills" --host codex- Optional: rollback from a snapshot:
hmctl skills-rollback --snapshot "$HOME/.memory-runtime/skill-governance/snapshots/<snapshot>.json"- Optional: export duplicate-skill decisions:
hmctl skills-duplicates --root "$HOME/.codex/skills" --decision-out /tmp/duplicate-decisions.json- Optional: apply duplicate decisions without deleting files:
hmctl skills-duplicates-apply --decision-file /tmp/duplicate-decisions.jsonYou can edit the exported decision file first.
Set action to skip if a duplicate group should remain untouched.
The duplicate report now includes per-path status and token metadata, and apply results include before/after deltas.
Duplicate groups are now ordered by review risk so the ugliest sets float to the top first.
- Optional: stage a sanitized public export from a private Codex or Memory Palace checkout:
hmctl public-export --list-profiles
hmctl public-export --profile codex-project-memory --source /path/to/codex --output /tmp/codex-public-export
hmctl public-export --profile memory-palace-project-tools --source /path/to/Memory-Palace --output /tmp/memory-palace-public-exportThat command only copies allowlisted files, replaces machine-specific paths with placeholders such as ${HOME} and ${CODEX_REPO_ROOT}, and fails if a private absolute path marker survives redaction.
See docs/PUBLIC_EXPORT.md for the full staging and mirror workflow.
Cold memory uses Memory Palace.
If you already run Memory Palace somewhere, set its base URL:
export MEMORY_RUNTIME_MP_BASE_URL="http://127.0.0.1:18000"If you want a stable cold-memory setup without cloning the full Memory Palace repo, use the backend-only installer:
./scripts/install-memory-palace-docker.sh
source ~/.memory-runtime/env.shThat path:
- deploys the official GHCR backend image only
- generates a local API key by default
- enables the
projectsdomain needed bymemory-runtime - writes shell exports to
~/.memory-runtime/env.sh
If you want memory-runtime to auto-start a local Memory Palace backend, also set:
export MEMORY_RUNTIME_MP_AUTOSTART=1
export MEMORY_RUNTIME_MP_BACKEND_ROOT=/absolute/path/to/Memory-Palace/backendAutostart only attempts to run when:
MEMORY_RUNTIME_MP_AUTOSTART=1- the base URL is a loopback address
- the backend root contains both
main.pyand.venv/bin/python
If any of those checks fail, the runtime degrades gracefully and continues.
Docker deployments are treated differently:
- the wrapper does not try to start or stop Docker for you
- use
install-memory-palace-docker.shonce, then keepMEMORY_RUNTIME_MP_AUTOSTART=0 - if you want the full Dashboard and SSE stack, use the official Memory Palace repo
See:
docs/COLD_MEMORY_DOCKER.mddocs/CONFIGURATION.mddocs/SETUP.mddocs/PRIVACY.md
The shell installer injects a managed block into your shell rc file and wires:
hmctlmemory_runtime_bridgememory_runtime_primeclaudegemini
It leaves codex native.
Codex MCP support is split on purpose:
memory-hotcan be enabled for local SQLite hot memorymemory-palacecan be enabled for explicit durable cold memory- the full
memory-runtimeMCP should stay disabled on the startup path
The installed sidecar path:
- warms compact primer files in the background when you enter a real project directory
- lets native Codex route reads through
hmctl contextor explicitprimer / continuity / bootstrap - keeps
hmctl continuityavailable for continuation-style turns without full bootstrap cost - keeps full
hmctl bootstrapavailable when the task needs richer context - prefers project hot-layer memory from
projects://<slug>/digest/currentandprojects://<slug>/anchors/currentwhen the cold backend provides them - keeps the raw user prompt intact
- avoids polluting hot memory with synthetic wrapper summaries
- keeps heavy consolidation out of the synchronous startup path
Claude and Gemini wrappers still exist for users who want wrapped shell flows on those hosts, but native Codex should not depend on them.
The skill audit companion:
- scans local skill trees only when you call it
- reports token-heavy and host-coupled skills
- supports explicit apply and rollback with snapshots
- supports explicit duplicate review and quarantine decisions
- does not auto-edit private skill directories unless you run
skills-apply
Run the full verification suite:
npm run check:allOptional benchmarks:
npm run bench:bootstrap
npm run bench:tokens
npm run bench:skills-governanceUseful runtime commands:
hmctl context --cwd "$(pwd)" --query "continue" --json
hmctl continuity --cwd "$(pwd)" --json
hmctl compact --cwd "$(pwd)" --dry-run
hmctl bootstrap --cwd "$(pwd)" --mode warm --query "debug query" --json
hmctl checkpoint --cwd "$(pwd)" --summary "checkpoint summary"
hmctl inspect --cwd "$(pwd)"
hmctl metrics --cwd "$(pwd)"docs/ARCHITECTURE.mddocs/COLD_MEMORY_DOCKER.mddocs/CODEX_APP.mddocs/DATA_CONTRACTS.mddocs/CONFIGURATION.mddocs/SETUP.mddocs/PRIVACY.mddocs/MEMORY_PALACE_PROJECT_TOOLS.mddocs/PUBLIC_EXPORT.mddocs/SAFETY.mddocs/SOCIAL_PREVIEW.mddocs/TROUBLESHOOTING.mddocs/OPEN_SOURCE.mddocs/RELEASE.mddocs/SKILL_GOVERNANCE.md
