Skip to content

Installer adds hooks to both hooks.json and config.toml #570

Closed

Description

@jiangjianzeng

Summary

After installing codebase-memory-mcp, Codex starts with this warning:

loading hooks from both ~/.codex/hooks.json and ~/.codex/config.toml; prefer a single representation for this layer

It looks like the installer writes hook configuration into both hook representations at the same time.

What happened

The installation added a SessionStart hook to ~/.codex/config.toml:

[[hooks.SessionStart]]
matcher = "startup|resume|clear|compact"

[[hooks.SessionStart.hooks]]
type = "command"
command = 'echo "Code discovery: prefer codebase-memory-mcp (search_graph, trace_path, get_code_snippet, query_graph, search_code) over grep/file-read; run index_repository first if the project is not indexed."'
# <<< codebase-memory-mcp SessionStart <<<

At the same time, ~/.codex/hooks.json also contains hook definitions, including a matching SessionStart hook with the same message:

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup|resume|clear|compact",
        "hooks": [
          {
            "type": "command",
            "command": "echo \"Code discovery: prefer codebase-memory-mcp (search_graph, trace_path, get_code_snippet, query_graph, search_code) over grep/file-read; run index_repository first if the project is not indexed.\""
          }
        ]
      }
    ]
  }
}

This causes Codex to warn that hooks are being loaded from both hooks.json and config.toml.

Impact

For this specific hook, the impact is minor but visible:

  • the startup/session hook message can appear more than once;
  • Codex emits the warning about mixed hook representations;
  • users may think their Codex or MCP setup is broken;
  • if future hooks have side effects, duplicate hook sources could cause duplicate execution, slower startup, duplicated state writes, etc.

Expected behavior

The installer should prefer a single hook representation for the same layer, for example:

  • write codebase-memory-mcp hooks only to ~/.codex/hooks.json if that file is already being used; or
  • write only to ~/.codex/config.toml; or
  • detect the existing representation and avoid adding the same hook to both places.

Suggested fix

During installation/setup, detect whether ~/.codex/hooks.json exists or whether Codex is already using TOML hooks, then install the SessionStart hook into only one location.

It may also be useful to add cleanup/migration logic that removes the duplicate codebase-memory-mcp SessionStart block from config.toml when the same hook already exists in hooks.json.

Activity

  1. sahil-mangla commented on Jun 23, 2026

    @sahil-mangla
    Contributor

    @DeusData can i work on this?

  2. DeusData commented on Jun 28, 2026

    @DeusData
    Owner

    This issue now has a first-class, durable reproduction in the cumulative bug-reproduction suite landing in #667 — a test that pins the exact failing behaviour, so it's tracked and guarded against silent regression. Where #667 also lands the root-cause fix, that's called out in the PR; otherwise the reproduction makes the eventual fix straightforward and verifiable.

    The reproduction goes live once #667 merges. (Posted from the release branch's QA pass.)

  3. added
    priority/normalStandard review queue; useful PR with ordinary maintainer urgency.
    on Jun 30, 2026
  4. added this to the 0.9.1-rc milestone on Jul 8, 2026
  5. added
    priority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.
    and removed
    priority/normalStandard review queue; useful PR with ordinary maintainer urgency.
    on Sep 5, 2026
  6. DeusData commented on Sep 26, 2026

    @DeusData
    Owner

    Thank you, @jiangjianzeng, for the precise report with both files quoted, and @sahil-mangla for offering to take it on!

    The installer now picks one representation. If ~/.codex/hooks.json exists, the SessionStart reminder goes there and the codebase-memory-mcp SessionStart block is removed from config.toml. Otherwise it stays in config.toml only. That removes Codex's "loading hooks from both" warning. This shipped in v0.9.0.

    Closing as fixed. Please reopen if a v0.11.0 install still writes both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingeditor/integrationEditor compatibility and CLI integrationpriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions