Skip to content

fix(plugin): quote HOOK_COMMAND path to handle spaces in home directory#1056

Merged
JeremyDev87 merged 2 commits into
masterfrom
fix/993-unquoted-hook-command-path
Mar 28, 2026
Merged

fix(plugin): quote HOOK_COMMAND path to handle spaces in home directory#1056
JeremyDev87 merged 2 commits into
masterfrom
fix/993-unquoted-hook-command-path

Conversation

@JeremyDev87

Copy link
Copy Markdown
Owner

Summary

  • Quote HOOK_COMMAND path using $HOME with double quotes instead of unquoted ~
  • Prevents breakage when the home directory path contains spaces

Fixes #993

Test plan

  • yarn test:hooks — 389 tests passed

…ry (#993)

Use $HOME with double quotes instead of unquoted ~ to prevent breakage
when the home directory path contains spaces.
@vercel

vercel Bot commented Mar 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
codingbuddy-landing Ready Ready Preview, Comment Mar 28, 2026 4:01am

@JeremyDev87 JeremyDev87 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Code Review — PR #1056

Critical: Backward Compatibility Bug in _is_hook_in_settings (line 274)

_is_hook_in_settings() at line 274 uses exact string match:

if hook.get("command") == HOOK_COMMAND:

Existing installations have python3 ~/.claude/hooks/codingbuddy-mode-detect.py stored in settings.json. After this PR, HOOK_COMMAND becomes python3 "$HOME/.claude/hooks/codingbuddy-mode-detect.py".

Impact: The comparison will FAIL for existing users → duplicate hook entry added to settings.json → hook runs twice per prompt.

Suggested fix: Match by HOOK_FILENAME substring instead of exact command match:

def _is_hook_in_settings(settings: dict) -> bool:
    user_prompt_hooks = settings.get("hooks", {}).get("UserPromptSubmit", [])
    for hook_group in user_prompt_hooks:
        for hook in hook_group.get("hooks", []):
            if HOOK_FILENAME in hook.get("command", ""):
                return True
    return False

This handles both old (~) and new ($HOME) formats.

Minor: permission_hint messages still use ~

Lines 42, 51, 60, 69, 78 display ~/.claude/hooks/... in hint messages. While these are display-only, consider updating them to $HOME for consistency, or leave as-is since ~ is more readable for users.

Good

  • Correct use of $HOME instead of ~ (proper quoting in all shell contexts)
  • Double-quote wrapping ensures paths with spaces work
  • Minimal, focused change

… compat

Existing installations store the old ~ format in settings.json. Exact
string comparison against the new $HOME format would fail, causing
duplicate hook registration. Match by HOOK_FILENAME substring instead.
@JeremyDev87

Copy link
Copy Markdown
Owner Author

Review Response

Critical: Backward Compatibility Bug — Resolved

Fixed in commit 446db60. Changed _is_hook_in_settings() from exact string comparison to HOOK_FILENAME substring matching:

# Before
if hook.get("command") == HOOK_COMMAND:

# After
if HOOK_FILENAME in hook.get("command", ""):

This handles both old (~) and new ($HOME) formats, preventing duplicate hook registration for existing users.

Minor: permission_hint messages still use ~

Leaving as-is. These are user-facing display messages where ~ is more readable and universally understood. They are not executed by the shell.

All 389 tests passing.

@JeremyDev87 JeremyDev87 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Re-Review: APPROVED ✅

Review feedback fully addressed:

  1. Critical fix applied: _is_hook_in_settings() now uses HOOK_FILENAME in hook.get("command", "") instead of exact string match — backward compatibility preserved for existing installations.
  2. HOOK_COMMAND properly uses $HOME with double-quote wrapping.

No critical or high issues remaining. Ready to merge.

@JeremyDev87 JeremyDev87 merged commit e4747e8 into master Mar 28, 2026
50 of 51 checks passed
@JeremyDev87 JeremyDev87 deleted the fix/993-unquoted-hook-command-path branch March 28, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Unquoted path in UserPromptSubmit HOOK_COMMAND (session-start.py)

1 participant