Local-first long-term memory for Codex sessions, backed by SQLite and exposed through MCP.
It records Codex hook events, imports existing Codex JSONL history, redacts visible secrets by default, and lets Codex search previous sessions through memory tools.
Codex is great inside one session, but useful context often disappears between sessions:
- previous project decisions
- commands that fixed an issue
- terminal output from old debugging sessions
- earlier prompts and assistant responses
- session-level storage and token usage
This package turns local Codex history into searchable memory.
- SQLite-backed local memory
- one-command setup with
codex-memory setup - Codex hook capture
- existing history/session import
- MCP tools for search, recent records, sessions, stats, session info, and deletion
- quiet hooks by default
- optional detailed capture for tool calls and terminal output
- FTS5 full-text search
- visible secret redaction by default
- raw payload storage disabled by default
- optional token counting with
tiktoken
py -m pip install -e .[dev]
codex-memory setup --globalRestart Codex after setup.
setup creates the config/database, imports existing Codex history, installs quiet hooks, enables Codex hooks, and registers the MCP server.
For macOS/Linux, use python instead of py:
python -m pip install -e .[dev]
codex-memory setup --globalOptional token support:
python -m pip install -e .[dev,tokens]codex-memory setup --global
codex-memory import
codex-memory recent --limit 20
codex-memory search "sqlite migration"
codex-memory session-info <session-id>
codex-memory delete-session <session-id> --yes
codex-memory stats
codex-memory uninstall --globalUseful setup flags:
codex-memory setup --global --skip-import
codex-memory setup --global --detailed
codex-memory setup --global --no-stopUse --detailed only when you want live per-tool capture. The default mode records session starts, user prompts, and assistant final messages without noisy per-step hook status messages.
After setup, Codex can use these tools:
memory_recent- latest recordsmemory_search- keyword search with optional filtersmemory_by_date- records for a date or time rangememory_sessions- known Codex sessionsmemory_get_session- records from one sessionmemory_session_info- record counts, estimated storage, and token usagememory_delete_session- delete a session and its records; requiresconfirm=truememory_stats- aggregate database stats
List-style responses default to format="toon"; most tools also accept format="json".
Example prompts for Codex:
Search my memory for the last discussion about the SQLite schema.
Find previous terminal output mentioning pytest failures.
Show session info for this session before deleting it.
Default database:
~/.codex/memories/codex-memory.sqlite
Default config:
~/.codex/memories/codex-memory.toml
Default config:
raw_payloads = false
max_visible_chars = 200000Environment overrides:
CODEX_HOMECODEX_MEMORY_DBCODEX_MEMORY_CONFIGCODEX_MEMORY_RAW_PAYLOADS
The default behavior is conservative:
- memory stays local in SQLite
- visible text is redacted before storage
- raw hook payloads are not stored unless
raw_payloads = true - long records are truncated by
max_visible_chars - edit/write/apply_patch-style tool content is summarized instead of storing full patches
The redactor covers common token/password/API-key patterns, but it is not a formal security boundary. Avoid pasting secrets into Codex if you do not want them stored anywhere.
Codex does not see the tools:
codex-memory setup --globalThen restart Codex.
Hooks are not recording:
codex-memory statsHook failures are fail-open and logged at:
~/.codex/memories/codex-memory-hook.log
py -m pip install -e .[dev]
pytestPackage metadata is in pyproject.toml.
- semantic search
- memory summaries/facts layer
- purge/export commands
- encrypted database option
- PyPI publishing
- CI workflow
Add a license before wider adoption. MIT or Apache-2.0 are good defaults.