Summary
codebase-memory-mcp already implements Codex SessionStart hook (#330) and Claude Code PreToolUse hook, but has no PreToolUse/PostToolUse hooks for Codex CLI. Codex now supports the same lifecycle hooks as Claude Code, and deserves the same proactive graph integration.
Problem
Codex CLI now supports PreToolUse/PostToolUse hooks similar to Claude Code. Currently:
- Claude Code gets PreToolUse hook: Intercepts Grep/Glob, injects graph context via
hook-augment subcommand
- Codex only gets SessionStart: A static reminder that doesn't provide dynamic graph context
- Inferior experience: Codex users don't get proactive graph context injection during tool calls
Current State
What Claude Code gets (from cli.c)
| Hook |
Behavior |
| PreToolUse |
Intercept Grep/Glob, inject graph context via hook-augment (non-blocking) |
| SessionStart |
One-line reminder to use graph tools |
| SubagentStart |
Inject context into Claude subagents |
What Codex gets today (from #330 implementation)
| Hook |
Behavior |
| SessionStart |
✅ One-line reminder (implemented) |
| PreToolUse |
❌ Missing |
| PostToolUse |
❌ Missing |
Proposed Solution
Extend the Codex hooks to include PreToolUse/PostToolUse, following the Claude Code pattern:
1. PreToolUse hook (high-value)
Intercept Grep/Glob/Bash calls and inject graph context:
# ~/.codex/config.toml
[[hooks.PreToolUse]]
matcher = "Grep|Glob|Bash"
[[hooks.PreToolUse.hooks]]
type = "command"
command = "/path/to/codebase-memory-mcp hook-augment"
timeout = 10
Implementation approach:
- Reuse existing
hook-augment subcommand (already implemented for Claude Code)
- Add Codex-specific hook format in
cli.c
- Follow same non-blocking design as Claude Code hooks
2. PostToolUse hook (optional)
Augment tool output with graph context:
[[hooks.PostToolUse]]
matcher = "Bash"
[[hooks.PostToolUse.hooks]]
type = "command"
command = "/path/to/codebase-memory-mcp hook-augment --post"
timeout = 10
Technical Notes
Codex hooks format
Codex uses TOML-based config (~/.codex/config.toml):
[[hooks.PreToolUse]]
matcher = "ToolName1|ToolName2"
[[hooks.PreToolUse.hooks]]
type = "command"
command = "script-path"
timeout = 10
Differences from Claude Code
| Aspect |
Claude Code |
Codex |
| Config format |
JSON (settings.json) |
TOML (config.toml) |
| Config location |
~/.claude/settings.json |
~/.codex/config.toml |
| Hook output |
JSON to stdout |
JSON to stdout |
| Timeout |
seconds |
seconds |
Existing infrastructure
The hook-augment subcommand already exists and is agent-agnostic:
- Takes a search token from stdin
- Calls
search_graph to find matching symbols
- Returns structured context to stdout
- Non-blocking (exits 0 on all failure paths)
Implementation location
- Extend
cbm_upsert_codex_hooks() in cli.c to add PreToolUse hook
- Add
cbm_install_codex_hook_script() to install the hook script
- Reuse existing
hook-augment subcommand
Hook script for Codex
Create a Codex-specific hook script that:
- Reads the tool call from stdin (JSON format)
- Extracts the search token (from Grep pattern, Glob pattern, or Bash command)
- Calls
codebase-memory-mcp hook-augment with the token
- Returns the augmented context to stdout
Alternative: Reuse the existing cbm-code-discovery-gate shim script with Codex-specific path resolution.
Acceptance Criteria
codebase-memory-mcp install detects Codex and installs PreToolUse hook
- PreToolUse hook intercepts Grep/Glob/Bash (same as Claude Code)
- Hook is non-blocking (exits 0 on all failure paths)
- Hook injects graph context via
search_graph results
codebase-memory-mcp uninstall removes Codex PreToolUse hook
- Tests cover fresh install, update, and removal
- Documentation updated in README.md Multi-Agent Support table
References
Additional Context
Proposed Multi-Agent Support Table Update
The README table currently shows:
| Agent |
MCP Config |
Instructions |
Hooks |
| Claude Code |
.claude/.mcp.json |
4 Skills |
PreToolUse (Grep/Glob graph augment, non-blocking) |
| Codex CLI |
.codex/config.toml |
.codex/AGENTS.md |
SessionStart reminder |
After this change:
| Agent |
MCP Config |
Instructions |
Hooks |
| Claude Code |
.claude/.mcp.json |
4 Skills |
PreToolUse (Grep/Glob graph augment, non-blocking) |
| Codex CLI |
.codex/config.toml |
.codex/AGENTS.md |
PreToolUse (Grep/Glob graph augment, non-blocking) + SessionStart reminder |
Note: I'm willing to contribute a PR if maintainers agree with this direction.
Summary
codebase-memory-mcp already implements Codex SessionStart hook (#330) and Claude Code PreToolUse hook, but has no PreToolUse/PostToolUse hooks for Codex CLI. Codex now supports the same lifecycle hooks as Claude Code, and deserves the same proactive graph integration.
Problem
Codex CLI now supports PreToolUse/PostToolUse hooks similar to Claude Code. Currently:
hook-augmentsubcommandCurrent State
What Claude Code gets (from
cli.c)hook-augment(non-blocking)What Codex gets today (from #330 implementation)
Proposed Solution
Extend the Codex hooks to include PreToolUse/PostToolUse, following the Claude Code pattern:
1. PreToolUse hook (high-value)
Intercept Grep/Glob/Bash calls and inject graph context:
Implementation approach:
hook-augmentsubcommand (already implemented for Claude Code)cli.c2. PostToolUse hook (optional)
Augment tool output with graph context:
Technical Notes
Codex hooks format
Codex uses TOML-based config (
~/.codex/config.toml):Differences from Claude Code
settings.json)config.toml)~/.claude/settings.json~/.codex/config.tomlExisting infrastructure
The
hook-augmentsubcommand already exists and is agent-agnostic:search_graphto find matching symbolsImplementation location
cbm_upsert_codex_hooks()incli.cto add PreToolUse hookcbm_install_codex_hook_script()to install the hook scripthook-augmentsubcommandHook script for Codex
Create a Codex-specific hook script that:
codebase-memory-mcp hook-augmentwith the tokenAlternative: Reuse the existing
cbm-code-discovery-gateshim script with Codex-specific path resolution.Acceptance Criteria
codebase-memory-mcp installdetects Codex and installs PreToolUse hooksearch_graphresultscodebase-memory-mcp uninstallremoves Codex PreToolUse hookReferences
src/cli/hook_augment.cAdditional Context
hook-augmentsubcommand can be reused directlyProposed Multi-Agent Support Table Update
The README table currently shows:
.claude/.mcp.json.codex/config.toml.codex/AGENTS.mdAfter this change:
.claude/.mcp.json.codex/config.toml.codex/AGENTS.mdNote: I'm willing to contribute a PR if maintainers agree with this direction.