8000 hook codex Support · Issue #91 · ayghri/i-have-adhd · GitHub
[go: up one dir, main page]

Skip to content

hook codex Support #91

Open
Open

Description

@SpxZhu

Currently, SessionStart Hooks only work properly within Claude Code. Can a universal Hook be provided that can also work in Codex?

Activity

  1. ayghri commented on Aug 1, 2026

    @ayghri
    Owner

    Do you have any diagnostic for the failure/lack of support on codex? I haven't tried the hook on codex yet.

  2. Repository owner deleted a comment from on Aug 5, 2026
  3. Repository owner deleted a comment from on Aug 5, 2026
  4. Repository owner deleted a comment from on Aug 5, 2026
  5. lwu-st commented on Aug 9, 2026

    @lwu-st

    Here's the fix fyi:
    i-have-adhd used args with ${CLAUDE_PLUGIN_ROOT}, and Codex passed that arg literally, so node tried to load Users/dev/${CLAUDE_PLUGIN_ROOT}/hooks/always-on.mjs and exited 1.

  6. fanqiecd commented on Aug 9, 2026

    @fanqiecd

    Thanks for opening this. I reproduced the failure on Windows with Codex using the current main hook manifest (i-have-adhd v0.1.0) and Node v26.5.0.

    Observed

    Codex reports:

    hook exited with code 1
    

    main/hooks/hooks.json currently contains:

    "command": "node",
    "args": ["${CLAUDE_PLUGIN_ROOT}/hooks/always-on.mjs"]

    The Codex hook runner does not handle this Claude-specific args / ${CLAUDE_PLUGIN_ROOT} combination the same way Claude Code does. In the observed path, only node is executed and the SessionStart JSON on stdin is parsed as JavaScript.

    Minimal PowerShell reproduction:

    $payload = '{"session_id":"codex-repro","cwd":"C:\\Temp","hook_event_name":"SessionStart"}'
    $payload | node

    This exits 1:

    SyntaxError: Unexpected token ':'
    ExitCode=1
    

    If the argument is forwarded literally instead, the same manifest fails with a MODULE_NOT_FOUND path containing ${CLAUDE_PLUGIN_ROOT}.

    Expected

    The SessionStart hook should invoke hooks/always-on.mjs and exit 0 (silently when the opt-in flag is absent) on Codex/Windows as well as Claude Code.

    Minimal Codex-side fix

    Putting the complete command in command and using Codex's plugin-root placeholder fixes the failure:

               {
                 "type": "command",
    -            "command": "node",
    -            "args": ["${CLAUDE_PLUGIN_ROOT}/hooks/always-on.mjs"],
    +            "command": "node \"${PLUGIN_ROOT}/hooks/always-on.mjs\"",
                 "timeout": 5,
                 "statusMessage": "Checking i-have-adhd always-on flag..."
               }

    If one manifest must remain Claude-compatible, a host-specific entry/adapter may be needed so Claude can keep its existing root variable while Codex receives the complete command.

    Verification

    With the local diff above:

    • the SessionStart payload invokes always-on.mjs;
    • the hook exits 0;
    • stdout/stderr are empty when .i-have-adhd-always is absent;
    • two regression checks pass.

    The missing opt-in flag is therefore not the cause—the script already treats that case as success. This is related to #70, but the Codex args handling is the additional failure mode here.

    The regression appears to have been introduced by d3cba85, which changed the hook from a single command string to separate command and args fields.

  7. ayghri commented on Aug 17, 2026

    @ayghri
    Owner

    this should be fixed in the latest commits. Let me know if the problem still persists

  8. SergiorCode commented on Aug 21, 2026

    @SergiorCode

    Still works on macOS — I can't reproduce the original failure.

    Codex CLI 0.142.5, Node v25.9.0, current main (b42a45a). With PLUGIN_ROOT set and the opt-in flag present, the SessionStart hook loads and emits the ruleset (exit 0). The args + ${CLAUDE_PLUGIN_ROOT} combination behind hook exited with code 1 is gone from hooks/hooks.json, so @lwu-st's and @fanqiecd's diagnosis matches what's in the manifest now. tests.test_always_on_hooks is 7/7 here.

    One gap is left, and it's why a Codex-only user still can't turn always-on on: hooks/always-on.mjs:16 resolves the flag as CLAUDE_CONFIG_DIR || ~/.claude. On a machine with Codex but no Claude Code that directory doesn't exist, so the hook runs, finds nothing and exits silently — which looks exactly like "not supported" from the user's side. grep CODEX_HOME returns nothing in the repo; Codex's own home is CODEX_HOME || ~/.codex.

    What I ran, same hook command as the manifest, only the environment changes:

    environment output
    PLUGIN_ROOT + flag in CLAUDE_CONFIG_DIR 6647 bytes, exit 0
    PLUGIN_ROOT, clean HOME, no CLAUDE_CONFIG_DIR 0 bytes

    Happy to send a PR that checks the Codex path too — a few lines across the hooks, a test, and a line in INSTALL.md, same shape as the OpenCode (~/.config/opencode) and Pi (~/.pi/agent) paths. Only if you want it that way; CONTRIBUTING says to discuss hook semantics first.

    Not verified on Windows or Linux.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0