-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add support for UserPromptSubmit and PreCompact hooks #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Rename 'session' command to 'logs' for clarity - Change logs command to only print paths instead of opening files - Add comprehensive custom help command with detailed information - Align help output with README content including: - Overview and purpose - Quick start guide - File structure visualization - Requirements and installation - Hook types descriptions - Command examples - Links to documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Emphasize the exclusive use of environments for all file, code, or shell operations - Prohibit the installation or use of the git CLI with the environment_run_cmd tool - Instruct users on how to view work using `container-use log <env_id>` and `container-use checkout <env_id>` 🤖 Generated with [Claude Code](https://claude.ai/code)
|
Caution Review failedFailed to post review comments. Configuration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (9)
🧰 Additional context used🧬 Code Graph Analysis (1)templates/hooks/index.ts (2)
🪛 markdownlint-cli2 (0.17.2)CLAUDE.md79-79: Fenced code blocks should have a language specified (MD040, fenced-code-language) 🔇 Additional comments (24)
WalkthroughThis update introduces two new hook types, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant InitCommand
participant SettingsFile
participant HooksIndex
User->>CLI: Run "claude-hooks init"
CLI->>InitCommand: Invoke init logic
InitCommand->>SettingsFile: Add UserPromptSubmit and PreCompact hooks
InitCommand->>HooksIndex: Generate handler functions for new hooks
CLI-->>User: Initialization complete with new hooks
sequenceDiagram
participant Claude
participant CLI
participant UserPromptSubmitHandler
Claude->>CLI: Trigger UserPromptSubmit hook event
CLI->>UserPromptSubmitHandler: Call handler with payload
UserPromptSubmitHandler->>CLI: Return response (contextFiles, approve/block, etc.)
CLI-->>Claude: Process response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
🎉 This PR is included in version 1.7.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
This PR adds support for two new hook types that were recently added to Claude Code:
These hooks were discovered in the official Claude Code hooks documentation but were missing from this project.
Changes
🎯 Core Implementation
Updated hook interfaces in
templates/hooks/lib.ts:UserPromptSubmitPayloadinterface withpromptfieldPreCompactPayloadinterface withtrigger: 'manual' | 'auto'fieldHookPayloadunion type to include new hooksAdded handlers in
templates/hooks/index.ts:userPromptSubmithandler with example logic:preCompacthandler with example logic:Updated settings generation in
src/commands/init.ts:UserPromptSubmitandPreCompactto the hooks configuration📝 Documentation Updates
✅ Test Coverage
test/commands/init.test.tsto verify new hooks are included in settings.jsontest/smoke/generated-files.test.tsto check for new hook handlers and types🔧 Additional Changes
Reasoning
Completeness: The Claude Code documentation shows 7 hook types, but this project only supported 5. Adding the missing hooks ensures users have access to all available functionality.
User Control:
UserPromptSubmitallows users to validate, modify, or enrich prompts before processingPreCompactgives users control over when conversation compaction happensConsistency: The implementation follows the existing patterns in the codebase, maintaining consistency with how other hooks are structured and configured.
Testing
claude-hooks initBreaking Changes
None. This is a purely additive change that maintains backward compatibility.
Future Work
References
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Tests