Skip to content

Codex: PreToolUse failed #651

Closed
Closed

Description

@rexkoh425

Version 0.6.1
Python 3.14.0

OS

Windows

Issue

Image

{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "[ -f graphify-out/graph.json ] && echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","additionalContext":"graphify: Knowledge graph exists. Read graphify-out/GRAPH_REPORT.md for god nodes and community structure before searching raw files."}}' || true"
}
]
}
]
}
}

Instructions/commands applied so far

  1. pip install graphifyy && graphify install
  2. graphify install --platform codex
  3. /graphify .
  4. graphify codex install
  5. graphify hook install

Activity

  1. Stef500 commented on May 2, 2026

    @Stef500

    Hello, same problem here.

  2. safishamsi commented on May 2, 2026

    @safishamsi
    Member

    Fixed in v0.6.4. The [ -f ] bash check has been replaced with a cross-platform Python one-liner — re-run graphify codex install after upgrading to regenerate the hook.

  3. rexkoh425 commented on May 2, 2026

    @rexkoh425
    Author

    #PreToolUse still fails after running upgrading to v0.6.4 and running "graphify codex install".

    OS: Windows
    Virtual Enviroment: Conda
    CLI : Powershell
    Python version: 3.14.0

    Linking similar issue below

    #522

    Image

    @safishamsi

  4. safishamsi commented on May 2, 2026

    @safishamsi
    Member
  5. safishamsi commented on May 2, 2026

    @safishamsi
    Member

    Re-opening — the python3 -c "..." fix in v0.6.4 still fails on Windows Conda (no python3 shim) and PowerShell (JSON brace/quote parsing). Root cause confirmed via #522.

    Real fix (in next release): the hook command is now just graphify hook-check — a new shell-agnostic subcommand that prints the hookSpecificOutput JSON if graph.json exists and exits silently if not. No inline Python, no shell quoting, works on PowerShell, cmd.exe, macOS, and Linux.

    After upgrading, re-run graphify codex install to regenerate the hook with the new command.

  6. safishamsi commented on May 2, 2026

    @safishamsi
    Member

    v0.6.5 is now on PyPI with the updated fix. Please try:

    pip install --upgrade graphifyy
    graphify codex install
    

    The hook command is now just graphify hook-check — no inline Python, no bash syntax, no JSON escaping. Should work cleanly on PowerShell and Conda.

    We don't have a Windows machine to verify this ourselves, so your feedback is really valuable. If it still fails, please open a PR with the working command for your setup — even a one-line change to _CODEX_HOOK in graphify/__main__.py would be enough and we'll merge it straight away.

  7. rikdoclo commented on May 2, 2026

    @rikdoclo
    I can reproduce this on macOS as well, so it is not only the Windows `[ -f ... ]` hook issue.
    
    Environment:
    
    - OS: macOS
    - Python: 3.14.2 via pyenv
    - Package: graphifyy 0.6.5
    - CLI: graphify
    - Module path: `/Users/rikdoclo/.pyenv/versions/3.14.2/lib/python3.14/site-packages/graphify`
    - App/runtime: Codex Desktop
    - Hook config path:
      - project: `.codex/hooks.json`
      - global: `~/.codex/hooks.json`
    
    Installed hook config:
    
    ```json
    {
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Bash",
            "hooks": [
              {
                "type": "command",
                "command": "graphify hook-check"
              }
            ]
          }
        ]
      }
    }

    Reproduction:

    1. Install/run graphify so graphify-out/graph.json exists.
    2. Run graphify codex install or otherwise install the Codex hook.
    3. Start Codex Desktop in the project.
    4. Any Bash tool call triggers the PreToolUse hook.

    Observed error:

    PreToolUse hook returned unsupported additionalContext
    

    Direct command output:

    graphify hook-check

    prints:

    {
      "hookSpecificOutput": {
        "hookEventName": "PreToolUse",
        "additionalContext": "graphify: Knowledge graph exists. Read graphify-out/GRAPH_REPORT.md for god nodes and community structure before searching raw files."
      }
    }

    This means graphifyy 0.6.5 still emits hookSpecificOutput.additionalContext for Codex PreToolUse. Codex Desktop rejects that field.

    Local workaround:

    "command": "graphify hook-check >/dev/null 2>&1 || true"

    This stops the hook failure by suppressing the unsupported JSON, but it also disables the graph reminder injection.

    Suggested fix:

    For Codex installs, graphify hook-check should not emit hookSpecificOutput.additionalContext for PreToolUse. Either emit the currently supported Codex hook schema, or make the Codex hook a no-op reminder-free hook until Codex supports context injection for this event.

  8. safishamsi commented on May 2, 2026

    @safishamsi
    Member

    Can you submit a PR for the same?

    Thanks

  9. rikdoclo commented on May 2, 2026

    @rikdoclo

    Can you submit a PR for the same?

    Thanks

    Cannot create PR apparently -> info hereunder

    PR Title
    Fix Codex PreToolUse hook-check emitting unsupported additionalContext

    Problem
    graphify hook-check is installed as the Codex PreToolUse hook command:

    "command": "graphify hook-check"

    When graphify-out/graph.json exists, it prints:

    {
      "hookSpecificOutput": {
        "hookEventName": "PreToolUse",
        "additionalContext": "graphify: Knowledge graph exists..."
      }
    }

    Codex Desktop rejects this with:

    PreToolUse hook returned unsupported additionalContext
    

    Confirmed on:

    • macOS
    • Codex Desktop
    • Python 3.14.2 via pyenv
    • graphifyy 0.6.5

    Recommended Code Change
    In graphify/__main__.py, change the hook-check command so it exits successfully without printing unsupported hookSpecificOutput.additionalContext.

    Current logic:

    elif cmd == "hook-check":
        graph = Path("graphify-out") / "graph.json"
        if graph.exists():
            import json as _json
            print(_json.dumps({
                "hookSpecificOutput": {
                    "hookEventName": "PreToolUse",
                    "additionalContext": (
                        "graphify: Knowledge graph exists. "
                        "Read graphify-out/GRAPH_REPORT.md for god nodes and "
                        "community structure before searching raw files."
                    ),
                }
            }))
        sys.exit(0)

    Proposed minimal fix:

    elif cmd == "hook-check":
        # Codex Desktop currently rejects `additionalContext` on PreToolUse.
        # Keep this hook as a cross-platform no-op so installed hooks do not
        # break Bash tool calls when graphify-out/graph.json exists.
        sys.exit(0)

    Optionally, preserve old behavior behind an explicit opt-in flag/env var, but not by default:

    elif cmd == "hook-check":
        graph = Path("graphify-out") / "graph.json"
        if graph.exists() and os.environ.get("GRAPHIFY_UNSUPPORTED_PRETOOL_CONTEXT") == "1":
            ...
        sys.exit(0)

    Test To Add
    Add a regression test that creates graphify-out/graph.json, runs graphify hook-check, and verifies no unsupported JSON is printed.

    Example:

    def test_codex_hook_check_does_not_emit_additional_context(tmp_path):
        import subprocess
        import sys
    
        out = tmp_path / "graphify-out"
        out.mkdir()
        (out / "graph.json").write_text("{}", encoding="utf-8")
    
        result = subprocess.run(
            [sys.executable, "-m", "graphify", "hook-check"],
            cwd=tmp_path,
            capture_output=True,
            text=True,
        )
    
        assert result.returncode == 0
        assert result.stdout == ""
        assert result.stderr == ""

    Acceptance Criteria

    • graphify hook-check exits 0.
    • It does not emit additionalContext.
    • Existing .codex/hooks.json installs can keep using "graphify hook-check".
    • Bash tool calls in Codex Desktop no longer fail when graphify-out/graph.json exists.
    • Graph guidance still exists through AGENTS.md / installed skill instructions, not through unsupported PreToolUse context injection.
  10. safishamsi commented on May 2, 2026

    @safishamsi
    Member

    Fixed in v6 (commit cf7ce3a). graphify hook-check is now a silent no-op — exits 0 without printing anything. Codex Desktop no longer rejects the hook. Graph guidance reaches the agent via AGENTS.md and the installed skill instead. Thanks @rikdoclo for the detailed diagnosis and suggested fix!

  11. rexkoh425 commented on May 2, 2026

    @rexkoh425
    Author

    OS: Windows
    Virtual Enviroment: PyEnv
    CLI : Powershell
    Python version: 3.14.0
    Agent: Codex
    Agent platform: VSCode Codex Extension

    Previous Issue

    #651 (comment)

    Hypothesis : Codex’s environment PATH does not include .venv/Scripts. Likely due to using codex's vscode extension instead of Codex CLI.

    Tested Solution :

    1. Replace graphify hook-check with .venv/Scripts/graphify.exe hook-check
    2. Explicit instruction to Codex to activate venv via AGENTS.md when running commands

    Proposed Solution :

    1. graphify codex install dynamically sources for graphify.exe and writes to hook
     ```powershell 
    $g = Get-ChildItem -Recurse -Filter graphify.exe -ErrorAction SilentlyContinue | Select-Object -First 1
    if ($g) {
        Resolve-Path -Relative $g.FullName
    } else {
        "graphify.exe not found"
    }
    ``` 

    New Issue

    Linked to #651 (comment)
    Linked to #533

    Image

    @safishamsi

  12. added a commit that references this issue on May 2, 2026
    96267ad
  13. safishamsi commented on May 2, 2026

    @safishamsi
    Member

    Also fixed the PATH issue you reported @rexkoh425 (commit 96267ad). graphify codex install now writes the absolute path to the graphify executable into hooks.json instead of the bare graphify command — so it works even when .venv/Scripts isn't on Codex's PATH in the VS Code extension. Re-run graphify codex install after upgrading to regenerate the hook with the full path.

    Let me know if there any regressions yet again after the fix

  14. mjjabarullah commented on May 2, 2026

    @mjjabarullah

    on fresh session i got

    Image after updating version 0.6.7

  15. rexkoh425 commented on May 2, 2026

    @rexkoh425
    Author

    Will run again after version 0.6.8 is released with the new changes. Thanks!

    Edit:
    PreHookUse successfully runs from v0.6.8 after running

    1. pip install --upgrade graphifyy
    2. graphify codex install

    #522 #533. Please verify. Thanks.

    Image

    @safishamsi

  16. added 2 commits that reference this issue on Sep 10, 2026
    811b00b
    be60e7a
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions