Skip to content

codex install writes bash-only PreToolUse hook that fails on Windows PowerShell #522

Closed

Description

@Userchenentao5

Summary

graphify codex install writes a bash-style PreToolUse command into .codex/hooks.json. On Windows, Codex executes that hook under PowerShell, so the hook fails before every matching tool invocation with hook exited with code 1.

Affected environment

  • graphifyy: 0.4.25 (installed locally)
  • OS: Windows
  • Shell used by Codex CLI: PowerShell

Generated hook

{
  "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"
          }
        ]
      }
    ]
  }
}

Steps to reproduce

  1. On Windows, run graphify codex install in a repo.
  2. Ensure graphify-out/graph.json exists.
  3. Let Codex invoke a matching shell/tool command in that repo.

Actual result

The hook fails with exit code 1 before command execution.

PowerShell parses the generated command as invalid syntax, for example:

  • Missing type name after '['
  • The token '&&' is not a valid statement separator in this version
  • The token '||' is not a valid statement separator in this version

Expected result

graphify codex install should generate a hook command that works in the shell Codex uses on Windows, or emit a shell-agnostic command.

Notes

A local workaround is to replace the generated command with a PowerShell-safe equivalent such as:

if (Test-Path 'graphify-out/graph.json') {
  Write-Output '{"hookSpecificOutput":{"hookEventName":"PreToolUse","additionalContext":"graphify: Knowledge graph exists. Read graphify-out/GRAPH_REPORT.md for god nodes and community structure before searching raw files."}}'
}

I am intentionally omitting local file paths, usernames, and screenshots for privacy.

Activity

  1. rexkoh425 commented on May 3, 2026

    @rexkoh425

    Please update to v0.6.8 and try. Thanks.

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

    #651

  2. safishamsi commented on Jul 6, 2026

    @safishamsi
    Member

    Fixed on v8 (f7911fd), shipping in the next release.

    Root cause was exactly as you described: the Claude/Codebuddy PreToolUse hook command was inline POSIX bash (case/esac, [ -f ], single-quoted echo '{json}', &&/||), which Windows cmd.exe/PowerShell can't parse — so the hook errored before every matching tool call and the graph nudge never reached the agent.

    The fix moves the detection logic (search-command match, source-file extension match, skip-under-output-dir, graph-exists check) into a shell-agnostic graphify hook-guard <search|read> subcommand, invoked via the absolute graphify exe path. A single console-script invocation has no shell syntax, so it parses identically under sh, cmd.exe, and PowerShell — the same pattern already used for the codex hook. macOS/Linux behavior is unchanged (byte-identical nudge payload), and the graph path now also honors GRAPHIFY_OUT.

    Note: I could not execute-test on real Windows in CI, so if you're able to run graphify install on Windows against a repo with graphify-out/graph.json and confirm the hook no longer exits 1 (and that grep/read calls get the nudge), that verification would be very welcome. Closing as resolved; reopen if anything still fails on your setup.

  3. added a commit that references this issue on Jul 26, 2026
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