newspaperPress Guidelines
Pricing
Blog
Downloaddownload

Explore our next generation products

See overview

Products

antigravityAntigravity 2.0terminalAntigravity CLIcodeAntigravity IDEsdkAntigravity SDK

Built for developers in the agent-first era

See overview
EnterpriseFrontendFullstackScienceMarketer

Everything you need to stay up-to-date and get help

Documentationkeyboard_arrow_rightChangelogSupportPressReleases

Explore our next generation products

See overview

Products

antigravityAntigravity 2.0terminalAntigravity CLIcodeAntigravity IDEsdkAntigravity SDK

Built for developers in the agent-first era

See overview
EnterpriseFrontendFullstackScienceMarketer
Pricing
Blog

Everything you need to stay up-to-date and get help

Documentationkeyboard_arrow_rightChangelogSupportPressReleases
Home
Antigravity 2.0v2.4.2keyboard_arrow_right
Overview
Getting Started
Build with Google
Feature Overview
Models
Projects
Settingskeyboard_arrow_right
Overview
Agent Settings
Artifact Review
Customizationskeyboard_arrow_right
MCP
Skills
Rules
Plugins
Hooks
Sidecars
Agent Capabilitieskeyboard_arrow_right
Permissions
Subagents
Artifactskeyboard_arrow_right
Overview
Plan
Walkthrough
Screenshots
Antigravity CLIv1.1.8keyboard_arrow_right
Overview
Getting Started
Installation & Auth
Tutorial
Using AGY CLI
Features
Gemini Migration
Prompting
Headless mode
Artifactskeyboard_arrow_right
Overview
Conversations
Agent Capabilitieskeyboard_arrow_right
Choose an execution mode
Subagents
Sandbox
Permissions
Projects
Settingskeyboard_arrow_right
Overview
AI Credits
Customizationskeyboard_arrow_right
MCP
Plugins & Skills
Status Line
Window Title
Commandskeyboard_arrow_right
Agents (/agents)
Code Search (/codesearch)
AI Credits (/credits)
Diff (/diff)
Permissions (/permissions)
Resume (/resume)
Status Line (/statusline)
Window Title (/title)
Model Quotas (/usage, /quota)
Best Practices
Troubleshooting
Reference
Antigravity SDKv0.1.7keyboard_arrow_right
Overview + Quick Start
Customizationskeyboard_arrow_right
MCP
Antigravity IDEv2.1.1keyboard_arrow_right
Overview
Getting Started
Featureskeyboard_arrow_right
Tab
Side Panel
Review Changes
Artifactskeyboard_arrow_right
Plan
Walkthrough
Screenshots
Browser Recordings
Browserkeyboard_arrow_right
Overview
Allowlist / Denylist
Separate Chrome Profile
Customizationskeyboard_arrow_right
MCP
Skills
Rules
Workflows
Plugins
Hooks
Settings
Migrationkeyboard_arrow_right
Firebase Studio Migration
Enterprise
Plans
FAQ
  • side_navigation
  • Antigravity CLI
  • >
  • Headless mode

Headless modelink

Run Antigravity CLI non-interactively to script agent tasks, integrate with CI pipelines, and capture machine-readable output.
Headless mode (also called print mode) sends a single prompt to the agent, streams or returns the response, and exits. Use it whenever you need the agent's output in a program instead of a terminal UI.

Run a single promptlink

Pass a prompt with -p (or its aliases --print and --prompt) to run once and exit:
bash
agy -p "In one sentence, what is a git rebase?"
text
A git rebase rewrites the commit history by transplanting a sequence of commits onto a new base commit, imposing a strictly linear progression of changes that eliminates arbitrary merge artifacts.
The response goes to stdout. Diagnostics — errors, authentication prompts, progress, and permission notices — go to stderr. This split keeps the captured response clean:
bash
# Capture only the model response; diagnostics still print to the terminal.
answer=$(agy -p "Name three popular version control systems, comma-separated.")
Note: Headless mode uses your cached credentials. Authenticate once with an interactive agy session first. In a non-interactive environment with no terminal (for example, CI), a run that is not already authenticated exits with an authentication required error instead of hanging.

Output formatslink

The --output-format flag controls the shape of stdout. It accepts three values:
Formatstdout shapeUse it for
textThe response text (default)Human-readable output, quick scripts
jsonOne JSON object printed on completionCapturing a result plus metadata
stream-jsonNewline-delimited JSON (NDJSON) eventsMonitoring progress, tools, and token usage

Textlink

The default. The response text goes straight to stdout with no wrapping:
bash
agy -p "In one sentence, what does the command git bisect do?"
text
Git bisect executes a binary search algorithm across a project's commit history to rapidly isolate the precise commit responsible for introducing a defect.

JSONlink

Set --output-format json to get a single JSON envelope after the run completes. The CLI emits it on one line; pipe through jq to pretty-print:
bash
agy -p "In one sentence, what is a git rebase?" --output-format json | jq
json
{
  "conversation_id": "055a398f-db14-4c5f-abbb-1bf03f8120a7",
  "status": "SUCCESS",
  "response": "A git rebase rewrites the commit history by transplanting a sequence of commits onto a new base commit, imposing a strictly linear progression of changes that eliminates arbitrary merge artifacts.\n",
  "duration_seconds": 7.16,
  "num_turns": 1,
  "usage": {
    "input_tokens": 10415,
    "output_tokens": 657,
    "thinking_tokens": 616,
    "cache_read_tokens": 8113,
    "total_tokens": 11072
  }
}
The envelope contains these fields:
FieldTypeDescription
conversation_idstringID of the conversation, for resuming later
statusstringTerminal status (see Status values)
responsestringThe agent's free-text response
errorstringError message; present only on failure
duration_secondsnumberWall-clock duration of the run
num_turnsnumberNumber of user turns in the conversation
structured_outputobjectParsed schema output; present only with --json-schema
json_schemaobjectThe schema that was enforced; present only with --json-schema
usageobjectToken counts: input_tokens, output_tokens, thinking_tokens, cache_read_tokens, total_tokens

Structured output with a schemalink

Pass --json-schema to constrain the answer to a schema. The parsed object appears in structured_output, and response holds the same payload serialized as a string:
bash
agy -p "Parse the semantic version string v2.14.3 into an object with integer fields major, minor, and patch." \
  --output-format json \
  --json-schema '{"type":"object","properties":{"major":{"type":"integer"},"minor":{"type":"integer"},"patch":{"type":"integer"}},"required":["major","minor","patch"]}' | jq
json
{
  "conversation_id": "4e502687-290c-4030-b908-5ed6c68fa5dc",
  "status": "SUCCESS",
  "response": "{\"major\":2,\"minor\":14,\"patch\":3}\n",
  "duration_seconds": 4.45,
  "num_turns": 1,
  "structured_output": {
    "major": 2,
    "minor": 14,
    "patch": 3
  },
  "json_schema": {
    "type": "object",
    "properties": {
      "major": {
        "type": "integer"
      },
      "minor": {
        "type": "integer"
      },
      "patch": {
        "type": "integer"
      }
    },
    "required": [
      "major",
      "minor",
      "patch"
    ]
  },
  "usage": {
    "input_tokens": 10522,
    "output_tokens": 354,
    "thinking_tokens": 329,
    "cache_read_tokens": 8112,
    "total_tokens": 10876
  }
}
The flag accepts a schema string, a path to a .json schema file, or a primitive type name (string, number, integer, boolean). Read the parsed value from structured_output:
bash
agy -p "Parse the semantic version string v2.14.3 into an object with integer fields major, minor, and patch." \
  --output-format json \
  --json-schema '{"type":"object","properties":{"major":{"type":"integer"},"minor":{"type":"integer"},"patch":{"type":"integer"}},"required":["major","minor","patch"]}' \
  | jq '.structured_output'

Streaming JSONlink

Set --output-format stream-json to emit one JSON object per line (NDJSON) as the run progresses. Use this format to observe tool calls and token usage in real time.
bash
agy -p "In one sentence, what is a git rebase?" --output-format stream-json
The stream begins with one init event, followed by any number of step_update events, and ends with exactly one result event (the cwd and tools array are abbreviated below):
json
{"event":"init","conversation_id":"c3b66b04-872b-4fbe-a3a4-058a026ef20a","init":{"cwd":"/home/user/project","tools":["ask_permission","run_command","write_to_file","..."],"permission_mode":"request-review"}}
{"event":"step_update","step_update":{"conversation_id":"c3b66b04-872b-4fbe-a3a4-058a026ef20a","step_index":0,"state":"DONE","step_type":"user_input"}}
{"event":"step_update","step_update":{"conversation_id":"c3b66b04-872b-4fbe-a3a4-058a026ef20a","step_index":3,"state":"DONE","step_type":"agent_response","text_delta":"Git rebase destructively rewrites a branch's commit history by systematically detaching its unique commits and sequentially reapplying them onto a new base commit.\n","duration_seconds":6.28,"usage":{"input_tokens":10302,"output_tokens":582,"thinking_tokens":551,"cache_read_tokens":8113,"total_tokens":10884}}}
{"event":"step_update","step_update":{"conversation_id":"c3b66b04-872b-4fbe-a3a4-058a026ef20a","step_index":4,"state":"DONE","step_type":"checkpoint","duration_seconds":0.53,"usage":{"input_tokens":116,"output_tokens":7,"thinking_tokens":0,"cache_read_tokens":0,"total_tokens":123}}}
{"event":"result","result":{"conversation_id":"c3b66b04-872b-4fbe-a3a4-058a026ef20a","status":"SUCCESS","response":"Git rebase destructively rewrites a branch's commit history by systematically detaching its unique commits and sequentially reapplying them onto a new base commit.\n","duration_seconds":6.88,"num_turns":1,"usage":{"input_tokens":10418,"output_tokens":589,"thinking_tokens":551,"cache_read_tokens":8113,"total_tokens":11007}}}
When the response streams in chunks, the agent_response step emits one or more ACTIVE events carrying partial text_delta fragments before its final DONE; short responses like this one arrive in a single DONE.
Every line is an event object whose event field names its type:
eventPayload keyEmitted
initinitOnce, at stream start
step_updatestep_updateFor each step transition or text delta
resultresultOnce, at the end (same shape as json)
The init payload records the run configuration. model and agent appear only when set with --model or --agent; permission_mode is request-review by default (and always-proceed under --dangerously-skip-permissions):
FieldTypeDescription
cwdstringWorking directory
toolsstring[]Names of all available tools
permission_modestringEffective permission mode
modelstringModel in use, when overridden
agentstringActive agent, when overridden
json_schemaobjectEnforced schema, when set with --json-schema
Each step_update payload describes one step. Observed step_type values include user_input, agent_response, tool, and checkpoint; state is ACTIVE while a step runs and DONE when it finishes:
FieldTypeDescription
conversation_idstringID of the conversation
step_indexnumberZero-based index of the step
statestringACTIVE or DONE
step_typestringStep category, for example agent_response or tool
tool_namestringCanonical tool name, on tool steps
text_deltastringIncremental response text
duration_secondsnumberStep duration, when known
usageobjectPer-step token usage, when known
tool_infoobjectTool invocation details (see below)
subagent_infoobjectSubagent invocation details

Tool calls in the streamlink

On tool steps, tool_info carries the call and its result. This is a real tool step from a run that executed echo hello_headless_demo:
json
{
  "event": "step_update",
  "step_update": {
    "conversation_id": "edb1c8c1-50ba-4f3f-87eb-412d0e9d47c3",
    "step_index": 4,
    "state": "DONE",
    "step_type": "tool",
    "tool_name": "run_command",
    "duration_seconds": 0.07,
    "tool_info": {
      "name": "run_command",
      "parameters": {
        "CommandLine": "echo hello_headless_demo"
      },
      "output": "hello_headless_demo\r\n"
    }
  }
}
tool_info holds name, parameters, output, and — when the tool fails — an error object with type and message. Steps that spawn subagents carry subagent_info instead, listing each subagent under subagents (with type_name, role, conversation_id, log_uri, and workspace_uris).

Structured output in the streamlink

With --json-schema, the schema applies to the terminal result event, which carries the same structured_output and json_schema fields as the json envelope.

Parse output with jqlink

stdout is machine-readable, so jq extracts exactly what you need.
Get the response text from a JSON run:
bash
agy -p "Name three popular version control systems, comma-separated." --output-format json | jq -r '.response'
text
Git, Subversion, Mercurial.
Concatenate streaming text as it arrives:
bash
agy -p "Explain what a merge conflict is in two sentences." --output-format stream-json \
  | jq -j 'select(.event=="step_update") | .step_update.text_delta // empty'
Read token usage from the terminal result event:
bash
agy -p "In one sentence, what is a git rebase?" --output-format stream-json \
  | jq 'select(.event=="result") | .result.usage'
Tip: Use jq -j (join output) when concatenating text_delta fragments so jq does not insert newlines between them.

Continue a conversationlink

Headless runs are stateless by default. Resume prior context with --continue (-c) for the most recent conversation, or --conversation with an ID from a previous run's conversation_id:
bash
# Continue the most recent conversation.
agy -p "Now explain your previous answer in more detail" --continue

# Resume a specific conversation by ID.
agy -p "Summarize what we discussed" --conversation 055a398f-db14-4c5f-abbb-1bf03f8120a7

Select a model, effort, or agentlink

List the available model slugs, then pin one for the run:
bash
agy models
text
gemini-3.6-flash-high     Gemini 3.6 Flash (High)
gemini-3.6-flash-medium   Gemini 3.6 Flash (Medium)
gemini-3.5-flash-medium   Gemini 3.5 Flash (Medium)
gemini-3.1-pro-high       Gemini 3.1 Pro (High)
claude-sonnet-4-6         Claude Sonnet 4.6 (Thinking)
...
bash
# Pin a model by slug.
agy -p "Reverse the string antigravity." --model gemini-3.5-flash-medium

# Set reasoning effort (low, medium, or high).
agy -p "Outline a plan to add caching to this service." --effort high

# Select an agent (list them with `agy agents`).
agy -p "Review this function for edge cases." --agent <agent-name>
Unlike the interactive UI, headless mode does not silently fall back when --model names an unknown model. It exits non-zero with an ERROR status so a pinned pipeline fails loudly instead of running the wrong model.

Permissions in headless modelink

There is no interactive prompt in headless mode, so tools that would normally ask for confirmation are handled by policy.
By default, the CLI respects the permission mode in your settings. A tool that requires approval it cannot obtain is soft-denied: the run continues, exits 0, and prints a notice to stderr naming the tool and how to allow it. Reading and writing files inside your active workspace is auto-allowed; actions such as shell commands default to Ask and are soft-denied in headless mode unless you grant them.
Grant a tool ahead of time by adding an action(target) rule under permissions.allow in ~/.gemini/antigravity-cli/settings.json:
json
{
  "permissions": {
    "allow": [
      "command(git)",
      "command(npm run (build|lint|test))",
      "write_file(src/)"
    ]
  }
}
To auto-approve every tool for a run, pass --dangerously-skip-permissions:
bash
agy -p "Run the test suite and report failures" --dangerously-skip-permissions
Warning: --dangerously-skip-permissions approves all tool calls, including file writes and command execution. Prefer scoped permissions.allow rules unless you fully trust the prompt and environment. See Permissions for the full rule syntax.

Handle exit codes and errorslink

A successful run exits 0. A run that fails to produce a response exits non-zero and writes the reason to stderr. In json and stream-json modes, the failure also appears in the status and error fields.
For example, pinning an unknown model exits 1 and returns an error envelope:
bash
agy -p "hi" --model does-not-exist-model --output-format json; echo "exit=$?"
json
{
  "conversation_id": "",
  "status": "ERROR",
  "response": "",
  "error": "invalid model selection (--model \"does-not-exist-model\" --effort \"\"): model does-not-exist-model is not recognized as a known model or custom model in settings\nAvailable models:\n  Gemini 3.6 Flash (High)\n  ...",
  "duration_seconds": 0,
  "num_turns": 0,
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0,
    "thinking_tokens": 0,
    "cache_read_tokens": 0,
    "total_tokens": 0
  }
}
text
exit=1
StatusMeaning
SUCCESSThe run completed and produced a response
ERRORThe run ended with an error
CANCELEDThe run was canceled
INTERRUPTEDThe run was interrupted (for example, SIGINT)
INVALIDThe run reached an invalid state
WAITINGThe run ended while waiting on input
RUNNINGThe run did not reach a terminal state
By default, a run waits up to five minutes for a response. Adjust the ceiling with --print-timeout:
bash
agy -p "Summarize the design tradeoffs of optimistic locking." --print-timeout 15m

Flag referencelink

FlagDefaultDescription
-p, --print, --prompt—Run a single prompt non-interactively and print the response
--output-formattextOutput format: text, json, or stream-json
--json-schema—Schema string or file path to enforce structured output
--model—Model slug for this run (see agy models)
--effort—Reasoning effort: low, medium, or high
--agent—Agent for this run (see agy agents)
--continue, -cfalseContinue the most recent conversation
--conversation—Resume a conversation by ID
--dangerously-skip-permissionsfalseAuto-approve all tool permission requests
--print-timeout5mMaximum time to wait for a response
--sandboxfalseRun with terminal sandbox restrictions enabled

Example: run the agent in CIlink

Fail the job on error and save the response:
bash
#!/usr/bin/env bash
set -euo pipefail

result=$(agy -p "Name three popular version control systems, comma-separated." \
  --output-format json \
  --print-timeout 10m)

status=$(echo "$result" | jq -r '.status')
if [[ "$status" != "SUCCESS" ]]; then
  echo "Agent run failed: $(echo "$result" | jq -r '.error')" >&2
  exit 1
fi

echo "$result" | jq -r '.response' > result.txt

Next stepslink

  • Prompting & Interaction: Write effective prompts for the agent.
  • Permissions: Configure allow, deny, and ask rules.
  • Background Tasks & Subagents: Delegate work to specialized agents.
  • Reference: Full command and flag reference.
Prompting & Interaction
Reviewing Artifacts
On this Page
Headless modeRun a single promptOutput formatsParse output with jqContinue a conversationSelect a model, effort, or agentPermissions in headless modeHandle exit codes and errorsFlag referenceExample: run the agent in CINext steps