Skip to content

Stop hook hangs on Windows: missing process.exit(0) after stdout.write in mempalace-stop.js #1268

@ffroliva

Description

@ffroliva

Summary

The Claude Code stop hook (mempalace-stop.js) hangs indefinitely on Windows at session end. The spinner shows running stop hooks… 3/3 and blocks for minutes (observed: 4m 41s+) before the session closes.

Root Cause

The final process.stdout.write() call in mempalace-stop.js does not pass a callback with process.exit(0). On Windows, Node.js holds the event loop open after a spawn() call — even with detached: true and child.unref() — because the stdout pipe is not flushed synchronously. The process never exits.

Steps to Reproduce

  1. Install the mempalace Claude Code plugin on Windows
  2. Run any Claude Code session long enough for the stop hook to fire (no cooldown active)
  3. End the session (/clear, close, or Ctrl+C)
  4. Observe: spinner shows running stop hooks… 3/3 and hangs for minutes

Fix

Change the final stdout.write call from:

process.stdout.write(JSON.stringify({ systemMessage: '...' }));

to:

process.stdout.write(JSON.stringify({ systemMessage: '...' }), () => process.exit(0));

The callback fires after the write is flushed, then exits immediately. This is the correct pattern for Node.js CLI scripts that write JSON to stdout and must exit cleanly.

Also recommended: add "timeout": 10 to the Stop hook entry in the plugin's settings.json template as a hard backstop against any future regressions.

Environment

  • OS: Windows 11 Pro 10.0.26200
  • Shell: bash (Git Bash)
  • Node.js: system node
  • Claude Code: latest
  • mempalace: latest

Workaround (applied locally)

Applied both fixes manually:

  1. Edited ~/.claude/hooks/mempalace-stop.js to use the callback form
  2. Added "timeout": 10 to the Stop hook in ~/.claude/settings.json

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