Skip to content

[Bug]: Hook errors on Windows when username contains spaces #239

@KhalilArabiKatbi

Description

@KhalilArabiKatbi

Platform

Claude Code

context-mode version

1.0.75 (latest)

Debug script output (REQUIRED)

{
    "version": "2.0.0",
    "generated": "2026-04-08T09:05:49Z",
    "sections": {
      "1. System Info": {
        "checks": [],
        "info": {
          "OS type": "windows",
          "uname -a": "MINGW64_NT-10.0-19045 Khalil 3.4.7-25de8b84.x86_64 2023-08-28 21:32 UTC x86_64 Msys",
          "Architecture": "x86_64",
          "Windows ver": "Microsoft Windows [Version 10.0.19045.6466]",
          "Shell": "/bin/bash.exe",
          "Bash version": "5.2.15(1)-release"
        }
      },
      "2. Runtime Versions": {
        "checks": [],
        "info": {
          "Node.js": "v22.22.0",
          "npm": "10.9.4",
          "npm global root": "C:\\Users\\TECH SHOP\\AppData\\Roaming\\npm\\node_modules"
        }
      },
      "7. Hook Validation": {
        "checks": [
          { "pass": true, "label": "PreToolUse registered" },
          { "pass": true, "label": "PostToolUse registered" },
          { "pass": true, "label": "PreCompact registered" },
          { "pass": true, "label": "SessionStart registered" }
        ]
      },
      "13. Hook Execution": {
        "checks": [
          { "pass": true, "label": "PreToolUse denies WebFetch" },
          { "pass": true, "label": "PreToolUse passes Write tool through" },
          { "pass": true, "label": "SessionStart injects routing context" }
        ]
      }
    },
    "summary": { "pass": 23, "fail": 7, "total": 30 }
  }

Exact prompt that triggered the bug (REQUIRED)

Any prompt triggers it. The very first message after launching Claude Code shows "UserPromptSubmit hook error" and "SessionStart:resume hook
  error". Example: "i restarted again last test"

Full error output (REQUIRED)

SessionStart:resume hook error
  UserPromptSubmit hook error
  PostToolUse:mcp__plugin_context-mode_context-mode__ctx_doctor hook error
  These appear on every session start and on the first few tool calls. No stack trace is shown by Claude Code — it only displays "hook error".
  Running the hook manually with an unquoted path reproduces the crash:
  $ CLAUDE_PLUGIN_ROOT="C:/Users/TECH SHOP/.claude/plugins/marketplaces/context-mode"
  $ echo '{}' | node $CLAUDE_PLUGIN_ROOT/hooks/userpromptsubmit.mjs

  C:\Users\TECH:1
  SyntaxError: Invalid or unexpected token
      at wrapSafe (node:internal/modules/cjs/loader:1638:18)
      at Module._compile (node:internal/modules/cjs/loader:1680:20)
  Node receives C:/Users/TECH as the script path because the shell splits on the space.

Steps to reproduce (REQUIRED)

  1. Have a Windows username with a space (e.g. TECH SHOP)
  2. Install context-mode via plugin marketplace: /plugin marketplace add mksglu/context-mode then /plugin install context-mode@context-mode
  3. Restart Claude Code
  4. Send any message
  5. See: SessionStart:resume hook error and UserPromptSubmit hook error

What have you tried to fix it?

Upgraded to latest version (1.0.75)

  • Read hooks/hooks.json — found all commands use unquoted ${CLAUDE_PLUGIN_ROOT}:
    "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/userpromptsubmit.mjs"
  • Tested manually: echo '{}' | node $CLAUDE_PLUGIN_ROOT/hooks/userpromptsubmit.mjs — crashes with SyntaxError because shell splits TECH SHOP
    into two args
  • Tested with quotes: echo '{}' | node "$CLAUDE_PLUGIN_ROOT/hooks/userpromptsubmit.mjs" — works perfectly
  • Fix: Changed all 13 commands in hooks/hooks.json to use escaped quotes:
    "command": "node "${CLAUDE_PLUGIN_ROOT}/hooks/userpromptsubmit.mjs""
  • After the fix, all hook errors are gone. Verified with a clean restart — zero errors.

Pre-submission checklist

  • I have run the debug script and pasted the output above
  • I am using the latest version of context-mode
  • I have searched existing issues for duplicates
  • I have included steps to reproduce the issue

Operating System

Windows (PowerShell)

JS Runtime

Node.js v22.22.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions