Hooks allow you to run custom scripts or shell commands at specific points during Antigravity’s execution loop to enforce rules, execute linters, or capture diagnostics.
Antigravity App
Section titled “Antigravity App”Managing hooks in the Antigravity App
Section titled “Managing hooks in the Antigravity App”In the Antigravity App, hooks are configured in a hooks.json file located in your
customization directory:
- Workspace level:
.agents/hooks.jsonin your workspace root. - Global level:
~/.gemini/config/hooks.json. - Plugin level: Packaged inside an installed plugin’s
hooks.jsonfile (managed from Customizations > Installed).
For the Antigravity App, <app_data_dir> in hook payloads resolves to
~/.gemini/antigravity.
Antigravity CLI
Section titled “Antigravity CLI”Managing hooks in Antigravity CLI
Section titled “Managing hooks in Antigravity CLI”Hooks intercept agent actions right before or immediately after execution. They
are useful for running automated pre-flight checks or post-generation
formatters (such as running prettier after writing files).
You can define hooks in any of the following locations:
- Workspace level:
.agents/hooks.jsonat your project root. - Global level:
~/.gemini/config/hooks.json. Hooks in~/.gemini/antigravity-cli/settings.jsonaren’t loaded. - Plugin level: Packaged inside an installed plugin’s
hooks.jsonfile.
You can inspect all loaded and active hooks interactively inside the TUI by typing:
/hooksFor Antigravity CLI, <app_data_dir> in hook payloads resolves to
~/.gemini/antigravity-cli.
Antigravity IDE
Section titled “Antigravity IDE”Managing hooks in Antigravity IDE
Section titled “Managing hooks in Antigravity IDE”In the standalone Antigravity IDE, hooks are configured in a hooks.json file:
- Workspace level:
.agents/hooks.jsonin your open project. - Global level:
~/.gemini/config/hooks.json.
You can manage active hooks from the … > Customizations > Hooks
menu in the agent side panel. For Antigravity IDE, <app_data_dir> in hook
payloads resolves to ~/.gemini/antigravity-ide.
Schema and file format
Section titled “Schema and file format”The hooks.json file maps hook names to their event configurations:
{
"my-linter-hook": {
"PostToolUse": [
{
"matcher": "run_command",
"hooks": [
{
"type": "command",
"command": "./scripts/lint.sh",
"timeout": 10
}
]
}
]
},
"safety-gate": {
"enabled": false,
"PreToolUse": [
{
"matcher": "run_command",
"hooks": [
{
"command": "./scripts/safety-check.sh"
}
]
}
]
},
"reminder": {
"PreInvocation": [
{
"type": "command",
"command": "./scripts/reminder.sh"
}
]
},
"session-init": {
"SessionStart": [
{
"type": "command",
"command": "./scripts/init-env.sh"
}
]
}
}
Hook definition fields
Section titled “Hook definition fields”Each hook definition supports the following fields:
| Field | Type | Description |
|---|---|---|
enabled | boolean | Optional. Set to false to disable the hook without removing it. Defaults to true. |
SessionStart | array | Handlers that run once when a new conversation session starts, before the first model invocation. |
PreToolUse | array | Handlers that run before a tool is executed. |
PostToolUse | array | Handlers that run after a tool completes. |
PreInvocation | array | Handlers that run before Antigravity calls the model. |
PostInvocation | array | Handlers that run immediately after each model invocation completes. |
Stop | array | Handlers that run when the execution loop terminates. |
Supported events
Section titled “Supported events”Antigravity supports the following hook events:
| Event | Description | Matcher Target |
|---|---|---|
SessionStart | Fires once when a new conversation session starts, before the first model invocation. | N/A (matcher ignored) |
PreToolUse | Fires before a tool is executed. | Tool name (for example, run_command) |
PostToolUse | Fires after a tool completes. | Tool name |
PreInvocation | Fires before the model is called. | N/A (matcher ignored) |
PostInvocation | Fires immediately after each model invocation completes. | N/A (matcher ignored) |
Stop | Fires when execution terminates. | N/A (matcher ignored) |
Matcher
Section titled “Matcher”For PreToolUse and PostToolUse, you can use a regular expression in the matcher field to specify which tools trigger the hook:
""or"*": Match all tools."run_command": Match exactlyrun_command."run_command|read_file": Match either tool."call_mcp_tool|mcp_.*": Match both default lazy-loaded MCP tool calls (call_mcp_tool) and eager MCP tools (mcp_<server>_<tool>)."browser_.*": Match any tool starting withbrowser_.
Supported tools
Section titled “Supported tools”For PreToolUse and PostToolUse matchers, you can match against standard tool names, grouped by category.
File and directory operations
Section titled “File and directory operations”The following tools read, create, and edit files:
read_file: Read the contents of a file.- Arguments:
Path,StartLine(optional),EndLine(optional),ByteOffset(optional)
- Arguments:
write_file: Create, overwrite, or append to a file.- Arguments:
Path,Content,Overwrite(optional),Append(optional),ArtifactMetadata(optional)
- Arguments:
edit_file: Replace text in an existing file.- Arguments:
Path,Target,Replacement,ArtifactMetadata(optional)
- Arguments:
Search and research
Section titled “Search and research”The following tool searches the web:
search_web: Perform a general web search.- Arguments:
query,domain(optional)
- Arguments:
System and execution
Section titled “System and execution”The following tools run commands, manage tasks, and invoke MCP servers:
run_command: Execute a shell command.- Arguments:
CommandLine,WaitMsBeforeAsync,IsDaemon(optional),BypassSandbox(optional),NotificationTimeoutSeconds(optional),toolSummary
- Arguments:
manage_task: Interact with background tasks.- Arguments:
Action('list','kill','status','send_input'),TaskId(optional),Input(optional)
- Arguments:
schedule: Set timers or recurring cron jobs.- Arguments:
DurationSeconds(optional),CronExpression(optional),MaxIterations(optional),TimerCondition(optional),Prompt,IsDaemon(optional),ExactTiming(optional)
- Arguments:
call_mcp_tool: Call a default lazy-loaded MCP tool (MCP tools configured with"eager": trueinvokemcp_<server>_<tool>directly instead).- Arguments:
ServerName,ToolName,Arguments
- Arguments:
list_resources: List available resources from an MCP server.- Arguments:
ServerName
- Arguments:
read_resource: Read a resource from an MCP server.- Arguments:
ServerName,Uri
- Arguments:
Agent collaboration
Section titled “Agent collaboration”The following tools coordinate subagents:
invoke_subagent: Spawn specialized subagents.- Arguments:
Subagents(array of specs withPrompt,Role,TypeName,Workspace(optional))
- Arguments:
define_subagent: Create a custom subagent.- Arguments:
name,description,system_prompt,enable_mcp_tools(optional),enable_write_tools(optional),enable_subagent_tools(optional)
- Arguments:
send_message: Communicate with other agents.- Arguments:
Recipient,Message
- Arguments:
manage_subagents: List or terminate active subagents.- Arguments:
Action('list','kill','kill_all'),ConversationIds(optional)
- Arguments:
Interaction and media
Section titled “Interaction and media”The following tools handle user interaction and media generation:
ask_question: Ask multiple-choice questions.- Arguments:
questions(array of questions withquestion,options,is_multi_select)
- Arguments:
generate_image: Create or edit images.- Arguments:
Prompt,ImageName,ImagePaths(optional)
- Arguments:
Hook handler configuration
Section titled “Hook handler configuration”Each item in the hooks array supports the following fields:
| Field | Type | Description |
|---|---|---|
type | string | Optional. Currently only "command" is supported. Defaults to "command". |
command | string | Required. The shell command to execute. |
timeout | integer | Optional. Timeout in seconds. Defaults to 30. |
Input and output contract
Section titled “Input and output contract”Hooks receive input through stdin as JSON and return output through stdout as JSON. Field names use camelCase.
Common input fields
Section titled “Common input fields”All hooks receive the following system metadata fields in their input payload on stdin:
| Field | Type | Description |
|---|---|---|
conversationId | string | The unique UUID of the active agent conversation. |
workspacePaths | array of strings | Absolute directory paths representing your mounted workspaces. |
transcriptPath | string | The absolute path to the persistent transcript.jsonl conversation logs. Note: This file lives in <app_data_dir>/brain/<conversationId>/.system_generated/logs/transcript.jsonl where <app_data_dir> is:
|
artifact | string | The absolute path to the directory containing all conversation artifacts and screenshots. |
modelName | string | The name or identifier of the model handling the invocation (for example, gemini-3.6-flash-medium). |
lastUserInput | string | The most recent user prompt in the conversation. |
hookEventName | string | The hook event being run, as written in hooks.json (for example, "PreToolUse"). |
cwd | string | The agent’s default working directory for commands (not the hook process’s working directory). Empty when the conversation has no workspace. |
SessionStart
Section titled “SessionStart”Fires once when a new conversation session starts, before the first model invocation.
Input fields (stdin):
| Field | Type | Description |
|---|---|---|
| (Common fields) | Includes conversationId, workspacePaths, transcriptPath, artifactDirectoryPath, modelName, lastUserInput, hookEventName, and cwd. |
Output fields (stdout):
| Field | Type | Description |
|---|---|---|
injectSteps | array of objects | Optional. List of steps to inject into the conversation trajectory at the start of the session (same schema as PreInvocation inject steps). |
Example:
- Input (stdin):
{
"hookEventName": "SessionStart",
"cwd": "/workspace/project",
"conversationId": "ec33ebf9-0cba-4100-8142-c61503f6c587",
"workspacePaths": ["/workspace/project"],
"transcriptPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587/.system_generated/logs/transcript.jsonl",
"artifactDirectoryPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587",
"modelName": "gemini-3.6-flash-medium"
}
- Output (stdout):
{
"injectSteps": [
{
"systemMessage": {
"systemMessage": "Environment initialized for workspace /workspace/project"
}
}
]
}
PreToolUse
Section titled “PreToolUse”Fires before a tool is executed.
Input fields (stdin):
| Field | Type | Description |
|---|---|---|
toolCall | object | Details of the proposed tool call. |
toolCall.id | string | The tool call ID, matching the id sent to PostToolUse for the same call. |
toolCall.name | string | The name of the tool being executed (for example, run_command). |
toolCall.args | object | Arguments passed to the tool call. |
stepIdx | integer | The 0-based index of the current step in the trajectory. |
| (Common fields) | Includes conversationId, workspacePaths, transcriptPath, artifactDirectoryPath, modelName, lastUserInput, hookEventName, and cwd. |
Output fields (stdout):
| Field | Type | Description |
|---|---|---|
decision | string | Required. Controls how the tool call is gated: - "allow": Allows the tool call to proceed, delegating to the next hook or default policy.- "auto_approve": Automatically approves the tool call when the default policy would otherwise prompt, while honoring explicit user-configured rules.- "deny": Hard blocks execution immediately.- "ask": Prompts you for approval, but respects “Always Allow” settings.- "force_ask": Always prompts you for approval, ignoring cached permissions.- "deny_unless_prior_grant": Denies execution unless the resource was previously approved in a prior grant. |
reason | string | Optional. The explanation shown to the agent or to you for the decision. |
overwrite | object | Optional. Replacement arguments merged (shallow top-level merge) into toolCall.args before execution. When arguments are modified, a notice naming the changed keys is prepended to the tool result. |
permission | array of strings | Optional. A list of resource strings (for example, ["read_file(/path)", "command(args)"]) to override default tool permissions. |
Example:
- Input (stdin):
{
"toolCall": {
"id": "toolu_01",
"name": "run_command",
"args": {
"CommandLine": "npm test",
"WaitMsBeforeAsync": 5000
}
},
"stepIdx": 19,
"hookEventName": "PreToolUse",
"cwd": "/workspace/project",
"conversationId": "ec33ebf9-0cba-4100-8142-c61503f6c587",
"workspacePaths": ["/workspace/project"],
"transcriptPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587/.system_generated/logs/transcript.jsonl",
"artifactDirectoryPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587",
"modelName": "gemini-3.6-flash-medium"
}
- Output (stdout):
{
"decision": "ask",
"reason": "Requires confirmation for test execution.",
"permissionOverrides": ["command(npm test)"]
}
PostToolUse
Section titled “PostToolUse”Fires after a tool completes.
Input fields (stdin):
| Field | Type | Description |
|---|---|---|
toolCall | object | Details of the executed tool call (id, name, and args). |
stepIdx | integer | The 0-based index of the completed step. |
error | string | Optional. The detailed runtime error message if the tool call failed. Empty if successful. |
| (Common fields) | Includes conversationId, workspacePaths, transcriptPath, artifactDirectoryPath, modelName, lastUserInput, hookEventName, and cwd. |
Output fields (stdout): Returns an empty JSON object {}.
Example:
- Input (stdin):
{
"toolCall": {
"id": "toolu_01",
"name": "run_command",
"args": {
"CommandLine": "npm test",
"WaitMsBeforeAsync": 5000
}
},
"stepIdx": 5,
"error": "exit status 1",
"hookEventName": "PostToolUse",
"cwd": "/workspace/project",
"conversationId": "ec33ebf9-0cba-4100-8142-c61503f6c587",
"workspacePaths": ["/workspace/project"],
"transcriptPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587/.system_generated/logs/transcript.jsonl",
"artifactDirectoryPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587",
"modelName": "gemini-3.6-flash-medium"
}
- Output (stdout):
{}
PreInvocation
Section titled “PreInvocation”Fires before the model is called.
Input fields (stdin):
| Field | Type | Description |
|---|---|---|
invocationNum | integer | The 0-indexed sequence number of the current model invocation (the first invocation is 0). |
initialNumSteps | integer | The number of steps currently in the trajectory. |
| (Common fields) | Includes conversationId, workspacePaths, transcriptPath, artifactDirectoryPath, modelName, lastUserInput, hookEventName, and cwd. |
Output fields (stdout):
| Field | Type | Description |
|---|---|---|
injectSteps | array of objects | Optional. List of steps to inject into the conversation trajectory before the model is called. |
termination | string | Optional. Controls the execution flow before calling the model: - "terminate": Stops execution immediately before calling the model (pair with an injected errorMessage to display a block message).- "" (or omitted): Proceeds to the model call (default). |
Each object in the injectSteps array can have one of the following fields:
systemMessage(object): An out-of-band system instruction for the agent. The value is an object with its ownsystemMessagestring and optionalmetadata(for example,{"systemMessage": {"systemMessage": "Remember to lint", "metadata": {"source": "policy"}}}).userMessage(string): A message from you.ephemeralMessage(string): Deprecated. UsesystemMessageinstead.errorMessage(object): Displays an error message without sending it to the model (for example,{"userMessage": "Prompt blocked by policy."}). Marks the turn as errored with a non-zero exit code in non-interactive-pmode, and does not stop execution on its own unless paired with"terminationBehavior": "terminate".
Example:
- Input (stdin):
{
"invocationNum": 3,
"initialNumSteps": 10,
"hookEventName": "PreInvocation",
"cwd": "/workspace/project",
"conversationId": "ec33ebf9-0cba-4100-8142-c61503f6c587",
"workspacePaths": ["/workspace/project"],
"transcriptPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587/.system_generated/logs/transcript.jsonl",
"artifactDirectoryPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587",
"modelName": "gemini-3.6-flash-medium",
"lastUserInput": "Fix the failing unit test"
}
- Output (stdout) (injecting a reminder for the agent):
{
"injectSteps": [
{
"systemMessage": {
"systemMessage": "Remember to lint"
}
}
]
}
- Output (stdout) (blocking a prompt before calling the model):
{
"injectSteps": [
{
"errorMessage": {
"userMessage": "Prompt blocked by policy."
}
}
],
"terminationBehavior": "terminate"
}
PostInvocation
Section titled “PostInvocation”Fires immediately after each model invocation completes.
Input fields (stdin): Same as PreInvocation (invocationNum, initialNumSteps, and the common fields, with "hookEventName": "PostInvocation").
Output fields (stdout):
| Field | Type | Description |
|---|---|---|
injectSteps | array of objects | Optional. List of steps to inject after the invocation completes (same schema as PreInvocation inject steps). |
termination | string | Optional. Controls the execution flow after injection: - "force_continue": Forces the loop to continue.- "terminate": Forces the loop to terminate.- "" (or omitted): Default behavior. |
Example:
- Input (stdin): Same as
PreInvocation, with"hookEventName": "PostInvocation". - Output (stdout):
{
"injectSteps": [],
"terminationBehavior": ""
}
Fires when the execution loop terminates.
Input fields (stdin):
| Field | Type | Description |
|---|---|---|
executionNum | integer | The sequence number of the execution attempt. |
termination | string | Why the execution loop stopped: "NO_TOOL_CALL", "MAX_INVOCATIONS", "MAX_FORCED_INVOCATIONS", "MAX_TOKEN_BUDGET_EXCEEDED", "ERROR", "USER_CANCELED", "TERMINAL_STEP_TYPE", "TERMINAL_CUSTOM_HOOK", or "INJECTED_RESPONSE". |
error | string | Optional. The error message if termination was caused by a system error. |
fullyIdle | boolean | Required. true if the agent is completely finished and all background commands or asynchronous tasks have completed. false if active background tasks are still running. |
continuation | boolean | true when this turn is already a continuation triggered by an earlier Stop hook (executionNum > 0). Check this field before returning {"decision": "continue"} to avoid infinite loops. |
| (Common fields) | Includes conversationId, workspacePaths, transcriptPath, artifactDirectoryPath, modelName, lastUserInput, hookEventName, and cwd. |
Output fields (stdout):
| Field | Type | Description |
|---|---|---|
decision | string | Required. Set to "continue" to prevent the agent from stopping and re-enter the execution loop. Any other value allows the stop. |
reason | string | Optional. If decision is "continue", this message is injected as a system message into the conversation. |
Example:
- Input (stdin):
{
"executionNum": 0,
"terminationReason": "NO_TOOL_CALL",
"error": "",
"fullyIdle": true,
"continuationActive": false,
"hookEventName": "Stop",
"cwd": "/workspace/project",
"conversationId": "ec33ebf9-0cba-4100-8142-c61503f6c587",
"workspacePaths": ["/workspace/project"],
"transcriptPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587/.system_generated/logs/transcript.jsonl",
"artifactDirectoryPath": "~/.gemini/antigravity/brain/ec33ebf9-0cba-4100-8142-c61503f6c587",
"modelName": "gemini-3.6-flash-medium"
}
- Output (stdout):
{
"decision": "continue",
"reason": "Not done yet"
}