Add Plugin Manager System for Claude Code Hooks#21
Open
nodeGarden wants to merge 4 commits intodisler:mainfrom
Open
Add Plugin Manager System for Claude Code Hooks#21nodeGarden wants to merge 4 commits intodisler:mainfrom
nodeGarden wants to merge 4 commits intodisler:mainfrom
Conversation
Implements a clean plugin architecture that eliminates dirty git state and follows Python plugin framework best practices. **Plugin Manager:** - Auto-discovers plugins from plugins/ directory - Loads plugin metadata from plugin.json - Executes plugins with fail-safe error handling - Supports multiple plugins per hook with priority ordering **Hook Integration:** - Minimal 7-line addition to each of 9 hook files - Graceful fallback if plugin_manager doesn't exist - No patching required - clean single import **Developer Experience:** - Comprehensive PLUGIN_DEVELOPMENT.md guide - Complete TEMPLATE plugin skeleton - Drop-in installation (no scripts needed) - Clean git state (no modified core files) **Benefits:** - Eliminates dirty git state problem - Upstream-friendly minimal changes - Supports unlimited plugins simultaneously - Easy plugin distribution and updates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implemented all recommended improvements from code review: **1. Professional Logging System** - Replaced all print() statements with proper logging module - Configured logger with formatter: [PluginManager] LEVEL: message - Default level: WARNING (configurable with --verbose flag) - Logs to stderr to avoid interfering with stdout - Better error context in log messages **2. Plugin Version Compatibility** - Added __version__ = "1.0.0" to plugin manager - New min_manager_version field in plugin.json - Automatic version checking during plugin load - Semantic versioning support (major.minor.patch) - _is_version_compatible() helper function - Skips incompatible plugins with clear warning **3. Plugin Reload Support** - Added reload_plugins() method to PluginManager - Clears and rediscovers all plugins from disk - Useful for development when modifying plugins - CLI: python3 plugin_manager.py --reload - Logs reload progress with DEBUG level **4. Config Schema Validation** - Comprehensive PLUGIN_METADATA_SCHEMA definition - Validates all metadata fields and formats - _validate_metadata() with detailed error messages - Checks: name format, version format, entry point syntax - Optional jsonschema support for strict validation - Falls back to basic validation if jsonschema unavailable **Enhanced CLI:** - --list: List all plugins (existing) - --test HOOK: Test plugins for hook type (existing) - --reload: Reload plugins from disk (NEW) - --verbose: Enable DEBUG logging (NEW) **Benefits:** - More professional error messages - Easier debugging with verbose mode - Prevents incompatible plugin versions - Hot-reload during development - Better metadata validation - Production-ready logging All improvements backward compatible. Existing plugins work unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Created complete test coverage for plugin_manager.py following the project's simple Python test pattern (no pytest required). **Test Coverage (9 tests, 100% pass):** 1. **test_version_compatibility()** - Exact version matches - Newer versions (major, minor, patch) - Older versions (should fail) - Edge cases and boundary conditions 2. **test_metadata_validation()** - Valid metadata acceptance - Missing required fields detection - Invalid name format (uppercase, special chars) - Invalid version format (non-semver) - Invalid entry point format 3. **test_plugin_class()** - Plugin properties (name, version, enabled) - Hook support checking - Execution without errors - Disabled plugin behavior 4. **test_plugin_error_handling()** - Plugins that raise exceptions - Error catching and logging - Hook execution continues despite errors 5. **test_plugin_manager_discovery()** - Auto-discovery from plugins directory - Plugin loading and initialization - Plugin registration 6. **test_plugin_manager_version_check()** - Incompatible plugins skipped - Version requirement enforcement - Warning messages logged 7. **test_plugin_manager_reload()** - Plugin rediscovery from disk - State clearing and rebuilding - Hot-reload during development 8. **test_plugin_priority_execution()** - Plugins execute in priority order - Lower number = higher priority - Execution sequence verification 9. **test_execute_plugins_function()** - Convenience function works correctly - Singleton manager instance - Error handling for unknown hooks **Test Infrastructure:** - TestResults class tracks pass/fail - Temporary directories for isolated testing - No external dependencies (uses stdlib only) - Clear pass/fail output with summary - Proper cleanup after tests **Usage:** ```bash # Run all tests python3 .claude/hooks/tests/test_plugin_manager.py # Verbose output python3 .claude/hooks/tests/test_plugin_manager.py --verbose ``` **Benefits:** - Verifies all improvements work correctly - Catches regressions during future changes - Documents expected behavior - No pytest/dependencies required - Fast execution (<1 second) All tests passing ✓ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implements a flexible source_app detection system with fallback chain: 1. CLAUDE_SOURCE_APP environment variable (highest priority) 2. source_app in .claude/hooks/config.json 3. Project directory name auto-detection (fallback) **New Files:** - utils/source_app.py - Detection utility with get_source_app() - config.json - Configured with "cc-hook-multi-agent-obvs" - config.json.example - Template for other projects **Modified Hooks:** All 9 hook files now add source_app to input_data before calling plugins: - notification.py - post_tool_use.py - pre_compact.py - pre_tool_use.py - session_end.py - session_start.py - stop.py - subagent_stop.py - user_prompt_submit.py **Benefits:** - Plugins can now identify which app triggered the hook - No manual configuration required (auto-detects from folder name) - Flexible override via env var or config file - Consistent source_app across all hooks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Plugin Manager System for Claude Code Hooks
Overview
This PR introduces a plugin manager system that allows multiple plugins to be installed and executed for hook events without modifying core hook files. The system auto-discovers plugins, validates metadata, and executes them in priority order with fail-safe error handling.
Caution
This was vibe coded with Claude... but it works for me
Key Features
Plugin Manager (
plugin_manager.py)plugins/directoryreload_plugins()for testingPlugin Development Support
Hook Integration
Changes
New Files
.claude/hooks/plugin_manager.py(497 lines) - Core plugin system.claude/hooks/PLUGIN_DEVELOPMENT.md- Developer documentation.claude/hooks/plugins/TEMPLATE/- Plugin template skeleton.claude/hooks/tests/test_plugin_manager.py(496 lines) - Test suiteModified Files
.claude/hooks/notification.py- Added plugin execution.claude/hooks/post_tool_use.py- Added plugin execution.claude/hooks/pre_compact.py- Added plugin execution.claude/hooks/pre_tool_use.py- Added plugin execution.claude/hooks/session_end.py- Added plugin execution.claude/hooks/session_start.py- Added plugin execution.claude/hooks/stop.py- Added plugin execution.claude/hooks/subagent_stop.py- Added plugin execution.claude/hooks/user_prompt_submit.py- Added plugin executionEach hook file received this minimal addition:
Technical Implementation
Plugin Structure
Plugin Metadata Schema
{ "name": "my_plugin", "version": "1.0.0", "description": "My awesome plugin", "enabled": true, "priority": 50, "hooks": ["PostToolUse", "Stop"], "entry_point": "src.plugin:handle_hook", "min_manager_version": "1.0.0" }Version Compatibility
Error Handling
Testing
Test Coverage
Comprehensive test suite with 9 tests covering:
Running Tests
Plugin Manager CLI
Benefits
For Developers
plugins/directoryFor Users
For Maintainers
Breaking Changes
None. This is a new feature that doesn't modify existing behavior.
Migration Path
Existing hooks continue to work without changes. To adopt the plugin system:
Reviewer Checklist
Follow-up Work
Future enhancements (not in this PR):
Related Issues
This PR builds the foundation for the multi-agent observability system by providing a clean plugin architecture that allows multiple monitoring and notification plugins to coexist without conflicts.
Branch:
feature/plugin-systemBase:
mainCommits: 3
033dcbcAdd plugin manager system for hooks8c3571fImprove plugin system with logging, validation, and dev tools5f7384fAdd comprehensive test suite for plugin managerTesting: All tests passing (9/9) ✅
Security: Code review completed, no issues found ✅
Documentation: Complete developer guide included ✅