Skip to content

fix: wrap hook commands in bash -c for paths with spaces - #15

Merged
Lisztos merged 1 commit into
mainfrom
fix/hooks-path-spaces-clean
Mar 25, 2026
Merged

fix: wrap hook commands in bash -c for paths with spaces#15
Lisztos merged 1 commit into
mainfrom
fix/hooks-path-spaces-clean

Conversation

@Lisztos

@Lisztos Lisztos commented Mar 24, 2026

Copy link
Copy Markdown
Owner

Ported from parcadei/Continuous-Claude-v3#47 by @carmandale


Summary

Wraps all 25 hooks using $CLAUDE_PROJECT_DIR in bash -c '...' to handle paths containing spaces. Fixes hook failures when project path contains spaces.

Problem

When $CLAUDE_PROJECT_DIR contains spaces, hooks fail because Claude Code strips quotes before shell execution, causing word splitting.

Solution

// Before
"command": "python3 \"$CLAUDE_PROJECT_DIR/.claude/hooks/script.py\""

// After
"command": "bash -c 'python3 \"$CLAUDE_PROJECT_DIR/.claude/hooks/script.py\"'"

Test plan

  • JSON validates
  • All CLAUDE_PROJECT_DIR hooks wrapped
  • Tested in actual Claude Code session with spaced path

Problem: Claude Code hooks fail when $CLAUDE_PROJECT_DIR contains
spaces (e.g., "Groove Jones Dropbox"). The shell splits the path
on spaces even when quoted in settings.json.

Solution: Wrap all commands using $CLAUDE_PROJECT_DIR in bash -c '...'
so bash handles variable expansion with proper quoting.

Changes:
- Wrapped 25 hooks using $CLAUDE_PROJECT_DIR with bash -c
- Preserved all timeout values
- Left $HOME hooks unchanged (no spaces in home paths)

Pattern applied:
  Before: python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/script.py"
  After:  bash -c 'python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/script.py"'
@Lisztos
Lisztos force-pushed the fix/hooks-path-spaces-clean branch from 3f60223 to 5002a9f Compare March 25, 2026 15:30
@Lisztos
Lisztos merged commit 9ee82b3 into main Mar 25, 2026
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