Skip to content

feat: add Codex SessionStart reminder hook for codebase-memory tool discovery #330

@dergachoff

Description

@dergachoff

Problem

codebase-memory-mcp install already configures Codex CLI with MCP config and .codex/AGENTS.md, but it does not install a Codex hook reminder. The README currently lists Codex hooks as -.

That leaves Codex users exposed to a known deferred-tool discovery failure mode: a broad tool_search query can omit an expected MCP tool from the first result set, even when the query includes the tool name. In our local Codex setup, a broad codebase-memory discovery query omitted search_graph; a second exact-name tool_search for search_graph found it.

This is tracked upstream in Codex as openai/codex#21503.

Proposed Solution

Add optional Codex CLI SessionStart hook installation alongside the existing Codex MCP config and .codex/AGENTS.md installation.

The hook should be non-blocking and only print a compact discovery protocol. It should not install a PreToolUse gate for Codex yet.

Suggested reminder text:

Code discovery protocol:
1. For source-code exploration, use codebase-memory-mcp first.
2. If MCP tools are not callable, run tool_search for:
   "search_graph trace_path get_code_snippet query_graph search_code index_repository codebase-memory-mcp"
3. If an expected tool is still missing, retry tool_search with the exact tool name, for example "search_graph"; absence from the first broad result is not proof the tool is unavailable.
4. Establish the project with list_projects/index_status; run index_repository if missing or stale.
5. Use search_graph for symbols, search_code for fuzzy text, get_code_snippet for exact qualified names, trace_path for callers/callees, and query_graph for complex graph queries.
6. Fall back to shell search/read only for docs/configs/non-code files or after MCP discovery genuinely fails.

Why SessionStart, not PreToolUse?

Claude Code currently gets a PreToolUse gate, but that gate has open UX issues around over-blocking and session detection. Codex also has different hook semantics and still has upstream limitations around full tool coverage / input rewrite.

A Codex SessionStart reminder is lower-risk:

  • no blocked reads or grep calls
  • works across startup/resume/clear lifecycle events
  • preserves user autonomy
  • directly addresses the deferred tool_search exact-name retry workaround

Acceptance Criteria

  • codebase-memory-mcp install detects Codex and can install/update a Codex SessionStart hook.
  • The hook writes to Codex's hook config without disturbing existing user hooks.
  • uninstall removes only the codebase-memory-managed Codex hook.
  • README Multi-Agent Support table changes Codex hooks from - to SessionStart reminder.
  • Tests cover fresh install, preserving existing hooks, replacing old managed hook text, and uninstall.

I'm happy to make an upstream PR if maintainers agree with this direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions