Episode 5: Core Differences (3) - Deep Dive into Hooks

⏱ Est. reading time: 3 min Updated on 5/7/2026

Hooks allow you to automatically insert custom scripts at critical points in the AI's execution. They are the strongest tools for implementing "hard constraints" and "automated flows."

1. Event Coverage Comparison

Event Type Claude Code Gemini CLI Antigravity
Before/After Tool Call
Session Start/End
Post-Response Generation
Before/After Model Inference Unique
Pre-Context Compression
  • Gemini CLI is the King of Granularity: It features unique BeforeModel and BeforeToolSelection hooks. This means you can run a script to modify the AI's context or constrain its choices before it even decides which tool to call.
  • Antigravity's Shortcoming: It does not natively support event hooks. All workflows must be guided through rule files, making them "soft constraints."

2. Practical Scenario: Security Interception

In Claude Code or Gemini CLI, you can write a PreToolUse hook:

  1. When the AI attempts to run an rm -rf command.
  2. The hook script is triggered and intercepts the operation via an exit code.
  3. It prompts the user for manual confirmation.

3. Code Example (Gemini CLI Hook)

"hooks": {
  "BeforeTool": {
    "command": "bash",
    "args": ["scripts/security-check.sh"],
    "matcher": "Bash"
  }
}

💡 Summary

If you need to build a highly controlled AI workstation with automated compliance checks, the Hooks systems in Claude Code or Gemini CLI are indispensable. The model-layer hooks in Gemini CLI even allow you to observe and intervene in the AI's thinking process.