Post-command hook fails with "xargs: unmatched double quote" error for complex commands
- Dominant language
- TypeScript
- Stars
- 72.6k
- Forks
- 8.6k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 85
Description
Description
The post-command hook in Claude Flow fails when processing Bash commands that contain quotes, newlines, or other special characters. While this is a non-blocking error (the main command executes successfully), it prevents proper command tracking and metrics collection.
Steps to Reproduce
1. Use Claude Code with Claude Flow hooks enabled
2. Execute a Bash command containing quotes and newlines, such as:
gh issue create --repo user/repo --title "Test Issue" --body "## Description
This is a test with quotes and newlines
- [ ] Task item
"
3. Observe the error message:
PostToolUse:Bash [cat | jq -r '.tool_input.command // ""' | xargs -I {} npx claude-flow@alpha hooks post-command --command "{}" --track-metrics true --store-results true]
failed with non-blocking status code 1: xargs: unmatched double quote; by default quotes are special to xargs unless you use the -0 option
Expected Behavior
The post-command hook should successfully process commands regardless of special characters, quotes, or newlines.
Actual Behavior
The hook fails with an xargs parsing error when the command contains quotes or other special characters.
Environment
- Claude Flow version: alpha (latest)
- Claude Code version: (latest)
- OS: Linux/macOS/Windows
- Node.js version: 20+
Suggested Fix
The current hook implementation uses:
cat | jq -r '.tool_input.command // ""' | xargs -I {} npx claude-flow@alpha hooks post-command --command "{}" --track-metrics true --store-results true
Possible solutions:
1. Use xargs -0 option with null-terminated strings
2. Use proper shell escaping for the command string
3. Pass the command via stdin or a temporary file instead of command line arguments
4. Use jq to properly escape the JSON string before passing to xargs
Impact
- Commands execute successfully (non-blocking)
- Command metrics and tracking fail for affected commands
- Potentially affects learning/optimization features that rely on command history
Additional Context
This issue primarily affects commands with:
- Multi-line strings (common with --body flags)
- Embedded quotes
- Special shell characters
- Here-documents or complex command structures
Contributor guide
Assessment
This issue has not been assessed yet.