# Antigravity Features and Practical Usage
🚀 What if you could inject your own logic into an agent's execution loop? Antigravity's lifecycle hooks let you enforce policy, log everything, and add guardrails automatically.
📌 Title and Feature URL
Title: Hooks
URL:
📝 Overview
Hooks let you run custom scripts or shell commands at specific points in Antigravity's agent execution loop. By reacting to events such as before/after a tool call or at session termination, you can enforce rules, capture diagnostics, and add guardrails without relying on a human to watch every step. They are the foundation for making agents follow your organization's policies.
🔧 How It Works
Hooks fire on lifecycle events and differ by their nature:
- PreToolUse: fires before a tool runs, letting you inspect arguments and allow or deny the call
- PostToolUse: fires after a tool completes, useful for logging and audit
- PreInvocation: fires before the model is called
- PostInvocation: fires immediately after each model invocation completes
- Stop: fires when the execution loop ends
- By behavior, hooks fall into Inspect (read-only, non-blocking), Decide (read-only, blocking allow/deny), and Transform (can modify data)
- Decide hooks return a decision result (HookResult) with allow/deny to stop policy violations before they happen
🛠 Practical Usage
- Use PreToolUse to inspect risky command arguments and return deny to halt execution
- Use PostToolUse to emit structured logs and build metrics or audit trails
- Inject system instructions before a model call to apply internal guidelines to the prompt
- Use Stop as a stop-condition check to force tests or lint to pass
- Execution order is Decide -> operation -> Inspect, validating first to avoid TOCTOU-style gaps
🎯 Use Cases
- Block destructive operations against a production DB before the agent runs them
- Auto-generate an audit log by recording every tool call for later review
- Inject coding standards and prohibited actions before each model call
- Force lint, type checks, and tests to run at session termination
⚠️ Caveats
- Inspect and Decide hooks are read-only and cannot mutate data (use Transform hooks for that)
- Faulty deny logic can stop legitimate work, so design conditions carefully
- The config location and JSON I/O contract may vary by version or distribution, so confirm with the latest docs
- Hooks interrupt the loop, so heavy work inside them slows overall responsiveness
#
Antigravity# #
DevTools#