gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

feat(hooks): Hooks Commands Panel, Enable/Disable, and Migrate

Open Edilmo opened this issue 4 weeks ago • 1 comments

Summary

Implement comprehensive hooks management commands for Gemini CLI: Panel, Enable, Disable, migrate

Details

  • Add /hooks command with interactive panel showing all configured hooks
    • Display hook type, event, and enabled/disabled status
    • Support navigation and selection via keyboard
    • Show empty state when no hooks configured
  • Add /hooks enable command to enable disabled hooks
    • Removes hook from hooks.disabled setting
    • Provides confirmation feedback
  • Add /hooks disable command to disable active hooks
    • Adds hook to hooks.disabled setting
    • Provides confirmation feedback
  • Add /hooks migrate command for migrating Claude Code hooks
    • Converts from old hooks.* format to new hooks.BeforeTool format
    • Preserves all hook configurations and settings
    • Provides detailed migration summary
  • Add hooks.disabled setting with UNION merge strategy
    • Allows disabling hooks by name across settings files
    • Implements union merge to combine disabled lists from all sources
  • Implement additionalProperties for hook event arrays with CONCAT strategy
    • Supports both predefined (BeforeTool, AfterTool, etc.) and custom events
    • Uses concatenation merge for all hook event arrays
  • Add comprehensive test coverage
    • Unit tests for HookSystem disable functionality
    • Integration tests for settings-based and runtime hook disabling
    • Mock LLM responses for fast integration test execution
  • Regenerate settings schema and documentation

Related Issues

Closes #9132 Closes #9133 Closes #9137

How to Validate

  • Test /hooks panel shows all registered hooks correctly
  • Verify hook source information is accurate (project/user/system/extension)
  • Test hook enable/disable state is displayed correctly
  • Validate execution history and statistics are shown
  • Test with various hook configurations and sources
  • Test /hooks enable <hook-name> enables a disabled hook
  • Test /hooks disable <hook-name> disables an enabled hook
  • Verify hook state persists across CLI restarts
  • Test with various hook names and configurations
  • Validate error handling for invalid hook names
  • Test migration from various Claude Code configurations
  • Verify event name aliasing works correctly
  • Test environment variable conversion (CLAUDE_PROJECT_DIR → GEMINI_PROJECT_DIR)
  • Validate migrated hooks work correctly in Gemini
  • Test error handling for invalid Claude configurations

Pre-Merge Checklist

  • [x] Updated relevant documentation and README (if needed)
  • [x] Added/updated tests (if needed)
  • [ ] Noted breaking changes (if any)
  • [ ] Validated on required platforms/methods:
    • [x] MacOS
      • [x] npm run
      • [x] npx
      • [ ] Docker
      • [ ] Podman
      • [ ] Seatbelt
    • [ ] Windows
      • [ ] npm run
      • [ ] npx
      • [ ] Docker
    • [ ] Linux
      • [ ] npm run
      • [ ] npx
      • [ ] Docker

Edilmo avatar Dec 01 '25 06:12 Edilmo

Summary of Changes

Hello @Edilmo, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Gemini CLI's extensibility and user control by introducing a dedicated system for managing hooks. It provides new CLI commands to inspect, enable, and disable hooks, along with a migration utility for users transitioning from Claude Code. The underlying configuration system has been updated to support more flexible merging strategies for hook settings, allowing for a more robust and customizable user experience.

Highlights

  • New Hooks CLI Command: Introduced a new top-level /hooks CLI command with subcommands: panel, enable, disable, and migrate for comprehensive hook management.
  • Hook Management Subcommands: The panel subcommand displays all configured hooks and their status, enable activates a specified hook, and disable deactivates a specified hook by updating the hooks.disabled setting.
  • Claude Code Hooks Migration: A migrate subcommand is added to convert existing Claude Code hooks to the new Gemini CLI format, including transformations for tool names and environment variables like $CLAUDE_PROJECT_DIR to $GEMINI_PROJECT_DIR.
  • Enhanced Hook Settings and Merge Strategies: The hooks.disabled setting now uses a UNION merge strategy, allowing disabled hooks to be combined across different settings files. Additionally, all hook event arrays (e.g., BeforeTool, AfterTool) and custom hook events now use a CONCAT merge strategy for flexible configuration.
  • Updated Settings Schema and Documentation: The settings schema and documentation have been updated to reflect the new hooks.disabled setting and the detailed structure for various hook event types, ensuring clarity and consistency.
  • Comprehensive Testing: Extensive unit and integration tests have been added to cover the new hook disabling functionality (both via settings and command) and the Claude Code migration process, ensuring reliability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist[bot] avatar Dec 01 '25 06:12 gemini-code-assist[bot]