-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: implement Claude Code-style hooks system #10785
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
base: main
Are you sure you want to change the base?
Conversation
Add lifecycle hooks for tool execution with 12 event types: - PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest - SessionStart, SessionEnd, Stop, SubagentStart, SubagentStop - UserPromptSubmit, Notification, PreCompact Core implementation: - HookManager service with config loading, validation, and execution - HookExecutor for shell command execution with timeout, stdin JSON, env vars - HookConfigLoader with project/global/mode-specific precedence - HookMatcher for pattern matching (exact, regex, glob) - ToolExecutionHooks adapter for pipeline interception Tool pipeline integration: - PreToolUse hooks can block or modify tool input - PostToolUse/PostToolUseFailure for non-blocking notifications - PermissionRequest hooks before approval prompts Webview UI: - Hooks tab in Settings with enable/disable toggles - Hook Activity log with real-time status updates - Reload config and open folder actions Includes comprehensive tests for all components. Relates to: Claude Code hooks feature parity
Review complete. This commit adds hook execution display in the chat by introducing a new "hook_triggered" say message type, a SayCallback in ToolExecutionHooks, and corresponding UI in ChatRow. No new issues found. The previously flagged issue remains unresolved.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| timestamp: exec.timestamp.toISOString(), | ||
| hookId: exec.hook.id, | ||
| event: exec.event, | ||
| toolName: exec.result.hook.matcher ? undefined : undefined, // Tool name is in context, not easily accessible here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ternary expression always evaluates to undefined regardless of the condition (exec.result.hook.matcher ? undefined : undefined). The comment suggests this was intentional because extracting the tool name is difficult, but the condition serves no purpose and makes the code misleading. Consider simplifying to just toolName: undefined to make the intent clear, or actually extracting the tool name if it's available in the execution context.
| toolName: exec.result.hook.matcher ? undefined : undefined, // Tool name is in context, not easily accessible here | |
| toolName: undefined, // Tool name is in context, not easily accessible here |
Fix it with Roo Code or mention @roomote and request a fix.
Update Hooks UI to explicitly document that matchers use Roo Code internal tool IDs (e.g. write_to_file, execute_command) rather than display labels. Add regression test ensuring display labels do not unintentionally match internal IDs.
Add open project/global folder buttons at bottom Move reload to bottom Add enable-all toggle (with new message type) Convert hooks list to accordion + per-hook logs
- Add switch, status dot, and delete button to HooksSettings UI - Implement backend support for hook deletion - Add safeWriteText utility - Update translation strings - Add UI and backend tests for new functionality
Summary
This PR implements a Claude Code-compatible hooks system for Roo Code, enabling users to run custom shell commands at key lifecycle events during AI assistant interactions.
Features
Core Hooks System
Configuration
.roo/hooks.jsonComponents
HookConfigLoader: Loads and merges hooks from project/global/mode configsHookExecutor: Executes hooks as subprocesses with JSON input/outputHookMatcher: Matches events against hook matchers (tool names, patterns)HookManager: Orchestrates hook discovery and executionToolExecutionHooks: Integration with tool execution lifecycleSecurity
Documentation
See hooks-prd.md for full PRD including:
Testing
All components include comprehensive unit tests:
HookConfigLoader.spec.tsHookExecutor.spec.tsHookManager.spec.tsHookMatcher.spec.tswebviewMessageHandler.hooks.spec.tsRelated
Addresses community request for event-driven automation (Discussion #6147)
Important
Implements a Claude Code-compatible hooks system in Roo Code, enabling custom shell command execution at lifecycle events, with configuration, management, and UI integration.
PreToolUse,PostToolUse,ToolError, etc..roo/hooks.jsonand global settings.HookManager,HookExecutor,HookMatcher,ToolExecutionHooksclasses for managing and executing hooks.HookConfigLoaderfor loading and merging hook configurations.HooksSettingscomponent to manage hooks in the settings UI.HookManager,HookExecutor,HookMatcher, andHookConfigLoader.This description was created by
for 22eda99. You can customize this summary. It will automatically update as commits are pushed.