Skip to content

hooks: quote ${CLAUDE_PLUGIN_ROOT} so paths with spaces work on Windows#11

Merged
viragtripathi merged 1 commit into
cockroachdb:mainfrom
nickolaschang:fix/quote-plugin-root-in-hooks
Apr 23, 2026
Merged

hooks: quote ${CLAUDE_PLUGIN_ROOT} so paths with spaces work on Windows#11
viragtripathi merged 1 commit into
cockroachdb:mainfrom
nickolaschang:fix/quote-plugin-root-in-hooks

Conversation

@nickolaschang

Copy link
Copy Markdown
Contributor

Summary

Wraps ${CLAUDE_PLUGIN_ROOT} in double quotes in both hook commands so the shell treats the expanded path as a single argument even when it contains whitespace.

Fixes #10.

The bug

On Windows where user profile folders commonly contain spaces (e.g. C:\Users\First Last\.claude\plugins\...), the unquoted expansion gets split on whitespace and Python receives a truncated first argument:

python3: can't open file 'C:\Users\First': [Errno 2] No such file or directory

The plugin's actual functionality is not affected — the hook simply errors and exits — but the error fires after every Write/Edit/MultiEdit (PostToolUse) and before every mcp__cockroachdb-toolbox__cockroachdb-execute-sql (PreToolUse), creating heavy noise in sessions.

The fix

-"command": "python3 ${CLAUDE_PLUGIN_ROOT}/scripts/validate-sql.py"
+"command": "python3 \"${CLAUDE_PLUGIN_ROOT}/scripts/validate-sql.py\""

-"command": "python3 ${CLAUDE_PLUGIN_ROOT}/scripts/check-sql-files.py"
+"command": "python3 \"${CLAUDE_PLUGIN_ROOT}/scripts/check-sql-files.py\""

Two-character change per line. No behaviour difference on Linux/macOS where paths typically lack spaces — "foo" and foo parse identically when there's no whitespace to split on.

Test plan

  • Verified hooks.json is still valid JSON after the edit
  • Local reproduction on Windows (C:\Users\Warehouse PC\…): error gone after applying the patch; PostToolUse and PreToolUse hooks now run cleanly
  • Maintainer verification on Linux/macOS (expected no-op since path has no spaces)

On Windows where user profile folders commonly contain spaces
(e.g. C:\Users\First Last\.claude\plugins\...), the unquoted expansion
gets split on whitespace and Python receives a truncated first argument:

    python3: can't open file 'C:\Users\First': [Errno 2] No such file or directory

Wrapping the path in double quotes treats it as a single argument
regardless of whitespace. No behaviour change on Linux/macOS.

Fixes cockroachdb#10
Copilot AI review requested due to automatic review settings April 23, 2026 01:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Windows failures in hook execution by quoting ${CLAUDE_PLUGIN_ROOT} in hooks/hooks.json, preventing whitespace in the expanded plugin path from being split into multiple arguments.

Changes:

  • Quote the script path in the PreToolUse hook command (validate SQL).
  • Quote the script path in the PostToolUse hook command (check SQL files).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@viragtripathi

Copy link
Copy Markdown
Contributor

Thanks @nickolaschang -- great catch and clean fix. I reproduced the bug locally on macOS by creating a path with spaces (/tmp/test path with spaces/scripts/) and confirmed:

  • Without quotes: python3: can't open file '/tmp/test': [Errno 2] No such file or directory
  • With quotes: clean exit, hooks run correctly

Approved and merging. Appreciate the cross-reference to anthropics/claude-plugins-official#1524 as well.

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.

hooks.json: unquoted ${CLAUDE_PLUGIN_ROOT} breaks on Windows paths with spaces

3 participants