Skip to content

fix(utils): convert Windows hook path backslashes to forward slashes - #542

Merged
uladzislausvetlakou merged 3 commits into
codemie-ai:mainfrom
oleksii-hryshyn:EPMCDME-14762_fix-windows-hook-path-backslash-escape
Sep 7, 2026
Merged

fix(utils): convert Windows hook path backslashes to forward slashes#542
uladzislausvetlakou merged 3 commits into
codemie-ai:mainfrom
oleksii-hryshyn:EPMCDME-14762_fix-windows-hook-path-backslash-escape

Conversation

@oleksii-hryshyn

Copy link
Copy Markdown
Contributor

Summary

Fixes Claude Code hook errors on Windows where every hook (SessionStart, Stop, UserPromptSubmit, etc.) failed with command not found after migration 006 rewrote hooks.json.

Refs: EPMCDME-14762

Root Cause

Migration 006 (006-resolve-hook-command-paths) rewrites installed Claude/Gemini hook commands to the absolute codemie binary path. On Windows, resolveCodemieBinary() returned Windows-style paths with backslashes (e.g. C:\Users\pavel\AppData\Roaming\npm\codemie).

When Claude Code executes hooks via bash (Git Bash on Windows), every \X sequence in the path is consumed as a shell escape — the path collapses to garbage and the hook fails:

/usr/bin/bash: line 1: C:UserspavelAppDataRoamingnpmcodemie: command not found

Changes

  • src/utils/hook-command.ts: added toForwardSlash() helper; applied on every branch of resolveCodemieBinary() (getCommandPath result, argv1 fallback, node + .js Windows fallback with process.execPath).
  • src/utils/__tests__/hook-command.test.ts: updated the Windows .js fallback assertion; added two new cases covering forward-slash conversion of getCommandPath output (with and without spaces).

No changes on POSIX — paths never contain backslashes there, so toForwardSlash() is a no-op.

Testing

  • Unit tests: src/utils/__tests__/hook-command.test.ts (11 cases, all pass) and src/migrations/__tests__/006-resolve-hook-command-paths.migration.test.ts (4 cases, all pass) — 15/15 green.
  • Manual A/B reproduction on Windows:
    • main (unfixed): migration writes C:\Users\...\codemie.cmd, bash execution → command not found, exit 127.
    • this branch: migration writes C:/Users/.../codemie.cmd, bash execution → exit 0.
  • Pre-commit hooks (ESLint, TypeScript, vitest across 27 utility test files) all passed.

Checklist

  • Code follows project standards
  • Local checks green (lint-staged, typecheck, targeted vitest)
  • No merge conflicts with main
  • No breaking changes — bug fix only, existing forward-slash paths pass through unchanged

oleksii-hryshyn and others added 3 commits September 7, 2026 16:26
Migration 006 rewrote installed Claude/Gemini hook commands to the
absolute codemie binary path but preserved Windows backslashes. When
Claude Code executes hooks via bash (Git Bash on Windows), every
\X sequence in the path is consumed as an escape — the path collapses
to gibberish and every hook fails with:
  /usr/bin/bash: line 1: C:UserspavelAppDataRoamingnpmcodemie:
    command not found

resolveCodemieBinary() now normalizes all Windows paths to forward
slashes on every return branch (getCommandPath, argv1, and the
node + .js Windows fallback). No-op on POSIX where paths never have
backslashes.

Refs: EPMCDME-14762
Raise all hook timeouts to 10 s (Claude: seconds unit; Gemini: ms unit)
so slow-starting codemie hook processes are not killed prematurely on
Windows where process startup is measurably slower.

Refs: EPMCDME-14762

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
A replace-all edit for 3000→10000 ms accidentally matched the substring
inside 30000, producing 100000 ms. Correct value is 30000 ms (30 s),
which was intentional in the original file.

Refs: EPMCDME-14762

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@uladzislausvetlakou
uladzislausvetlakou merged commit c8d7432 into codemie-ai:main Sep 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants