Skip to content

Windows Codex Stop hook can fail under PowerShell despite being enabled #229

@shupivot

Description

@shupivot

Summary

On Windows, the Nowledge Mem Codex Stop hook can be installed/enabled but still fail with:

Saving Codex thread to Nowledge Mem...
error: hook exited with code 1

The failure is not that the hook is disabled. It is caused by Windows shell execution details in the generated hook command and, in some cases, by invoking nmem.cmd from inside the hook.

Environment

Symptoms

hooks.json contains a Stop hook and the status message is shown, but Codex reports the hook failed with exit code 1.

The configured command previously looked like this pattern:

"C:\...\python.exe" "C:\...\nowledge-mem-stop-save.py" --event stop

That pattern works when interpreted by cmd.exe, but in PowerShell a quoted executable path needs the call operator (&). Without that, PowerShell can fail before the Python hook script runs.

Local Root Cause

Two Windows-specific issues were found locally:

  1. PowerShell parser failure when the hook command string begins with a quoted python.exe path followed by a quoted script path.
  2. The Python hook invoked nmem.cmd, which can leave child processes hanging on this Windows install. Calling the bundled Python CLI module directly was more reliable.

Local Workaround Tested

I added a .cmd wrapper with a simple no-space command target and pointed both user and plugin hook configs at it:

%USERPROFILE%\.codex\hooks\nowledge-mem-stop-save.cmd --event stop

Then patched the Python hook to call the bundled CLI directly instead of shelling through nmem.cmd:

%LOCALAPPDATA%\Nowledge Mem\_up_\python-standalone\python\python.exe -m nowledge_graph_server.ncli --json t save ...

with PYTHONPATH set to the bundled app\src.

Updated local hook config paths:

%USERPROFILE%\.codex\hooks.json
%USERPROFILE%\.codex\plugins\cache\nowledge-community\nowledge-mem\0.1.10\hooks\hooks.json
%USERPROFILE%\.claude\plugins\marketplaces\nowledge-community\nowledge-mem-codex-plugin\hooks\hooks.json

After this workaround:

GET /health -> ok
nmem --json status -> ok
manual wrapper pipeline test -> EXIT=0
hook log -> nmem_exit=0 and Codex thread append success

Suggested Fix

For Windows hook installation, generate a shell-neutral wrapper command instead of a raw quoted Python executable command. Also consider avoiding nmem.cmd inside lifecycle hooks and invoking the bundled Python module directly, so hooks are not affected by cmd/PowerShell quoting or child-process hangs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions