Skip to content

Conversation

@croakingtoad
Copy link

Summary

This PR fixes two critical issues in the setup-hooks.sh script that prevented successful installation:

1. Fix jq syntax error

Problem: The script failed with the error:

jq: error: syntax error, unexpected end, expecting IDENT or __loc__

Cause: The variable name $end conflicts with jq's reserved keyword end (used to terminate structures).

Solution: Renamed the jq variable from $end to $sessionend.

2. Preserve existing hooks

Problem: The setup script completely overwrote the .hooks configuration in ~/.claude/settings.json, deleting any existing hooks users had configured.

Solution: Changed the script to append new hooks to existing arrays instead of replacing them entirely.

Before:

.hooks.UserPromptSubmit = [{"matcher": "", "hooks": [...]}]

This overwrites any existing UserPromptSubmit hooks.

After:

.hooks.UserPromptSubmit = (.hooks.UserPromptSubmit // []) + [{"matcher": "", "hooks": [...]}]

This appends to existing hooks, preserving user configuration.

Testing

Tested on a system with existing Claude Code hooks:

  • ✅ Setup script runs without jq syntax errors
  • ✅ New hooks are added successfully
  • ✅ Existing hooks are preserved (ccnotify, append-subagents, copy-claude-response, etc.)
  • ✅ All hook arrays properly merged

Impact

These changes allow the setup to work correctly on systems with existing Claude Code hook configurations, which is likely the common case for users installing claude-code-ui.

This commit fixes two issues in the setup script:

1. **Fix jq syntax error**: Renamed the jq variable from `$end` to
   `$sessionend` because `end` is a reserved keyword in jq, causing
   the error: "syntax error, unexpected end, expecting IDENT"

2. **Preserve existing hooks**: Changed the script to append new hooks
   to existing hook arrays instead of replacing them entirely. This
   prevents the setup from deleting users' existing hook configurations.

   Before: `.hooks.UserPromptSubmit = [...]` (overwrites)
   After: `.hooks.UserPromptSubmit = (.hooks.UserPromptSubmit // []) + [...]` (appends)

These changes allow the setup to work correctly on systems with existing
Claude Code hook configurations.
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.

1 participant