All posts

Google Antigravity Context Window & Token Management Guide

Nov 21, 2026 4 min read Oleg Savelev
antigravity multi-agent context-window token-optimization google

Google Antigravity has emerged as one of the most capable multi-agent coding environments. By coordinating specialized subagents, running background tasks, and maintaining conversation logs across complex refactorings, it tackles architectural engineering problems that overwhelm single-turn chat interfaces.

However, multi-agent architectures introduce a structural cost: the multi-agent context tax.

When a parent coordinator delegates tasks to research subagents, code authors, and test runners, each subagent operates with its own context window. Without deterministic filtering, subagents repeatedly crawl the same repository files, load thousands of lines of inactive helper code, and burn through daily token quotas in a fraction of the expected working day.

Here is an architectural breakdown of how Antigravity handles context, where tokens leak, and how to manage context windows deterministically.

The Multi-Agent Context Tax in Antigravity

In a single-agent environment (such as a standard terminal assistant), context grows linearly with user prompts and agent tool responses. In Antigravity's multi-agent model, context expands exponentially:

  1. Coordinator turn: The root coordinator inspects directory structures and briefs a subagent.
  2. Subagent onboarding: The subagent reads dependencies, configuration files, and target source modules.
  3. Cross-turn synthesis: Tool outputs return to the parent transcript, compounding the prompt size for subsequent turns.

Consider a typical refactoring task in an active 25,000-line TypeScript or Python monorepo:

Operation Unfiltered Raw Baseline TokenSafe AST Sliced Token Reduction
Directory discovery (tree / recursive scan) 14,200 tokens 164 tokens (get_architecture_graph) -98.8%
Target symbol read (e.g. auth_service.ts) 8,450 tokens 620 tokens (smart_read_file) -92.7%
Subagent 2 repeat read (same file, next turn) 8,450 tokens 48 tokens (SUBAGENT_DEDUP pointer hit) -99.4%
Staged diff egress (writing surgical change) 6,100 tokens 120 tokens (edit_file diff window) -98.0%

When subagents crawl raw files, a single multi-step task easily consumes 150,000 to 250,000 tokens. With AST slicing and repeat-read deduplication, the exact same task executes in under 12,000 tokens.

Figures above are illustrative single-turn examples, sized against measured aggregates in the public real-repo benchmark. Treat them as representative for a mid-size repository, not exact quotes for yours.

Three Root Causes of Antigravity Context Bloat

1. Wholesale File Reads on 1-Hop Tasks

When an Antigravity agent needs to modify a single function in a 2,000-line module, standard tools call read_file on the entire file. The agent ingests hundreds of lines of private helper implementations, math routines, and internal data structures that have zero bearing on the edit. The full cost math of this pattern is broken down in Stop paying for code your agent already read.

2. MCP Tool Schema Overhead (Context Tax)

Every enabled Model Context Protocol (MCP) server registers JSON schemas for its available tools. When a development environment loads multiple heavy MCP servers (database connectors, cloud APIs, browser automation), tool schemas can inject 15,000 to 30,000 tokens of boilerplate into the system prompt before the agent reads a single line of your code.

3. Subagent Memory Drift and Broken Prompt Caches

When subagents execute commands that output volatile timestamps, process IDs, or dynamic progress bars, the strict byte-prefix ordering required for KV-cache reuse breaks. The provider invalidates the cached prompt and bills the entire conversation history from scratch. The mechanics of this are covered separately in KV-cache prefix locking explained.

How to Optimize Antigravity Context Windows

Managing Antigravity context requires a local-first, deterministic pipeline:

[ Antigravity Subagent ]
        │
        ▼ (Tool Call: inspect symbol / file)
[ TokenSafe Local Hook ] ─── < 30ms deterministic Tree-sitter parse
        │
        ├─ Keep target function body intact
        ├─ Fold inert helper bodies into 1-line typed signatures
        └─ Attach 8-char Blake2b hash anchor (#hash) for 0ms expansion
        │
        ▼ (Compact context payload: -90% tokens)
[ Gemini / Claude Model ]

1. Replace Blind File Crawling with God-Node Maps

Instead of allowing subagents to run recursive directory searches, guide them to inspect project architecture via god-node graphs:

# Returns top architectural hubs and 1-hop dependencies in < 250 tokens:
tokensafe:get_architecture_graph(project_path=".")

2. Enforce Signature-Mode Reads (smart_read_file)

Configure Antigravity agents to inspect code through AST slicing:

# Preserves target executable body while folding surrounding inactive code:
tokensafe:smart_read_file(path="src/service.py", symbol="process_payment")

The model sees the complete interface contract, imports, and types without burning context on inactive code.

3. Audit System Prompt MCP Overhead

Run the MCP tax doctor to identify schemas that inflate prompt baseline costs:

tokensafe doctor

Quick Integration for Google Antigravity

TokenSafe integrates natively into Google Antigravity as an MCP server. Add the following entry to your Antigravity configuration or workspace rules:

{
  "mcpServers": {
    "tokensafe": {
      "command": "npx",
      "args": ["-y", "tokensafe", "mcp"]
    }
  }
}

Once configured, Antigravity subagents automatically prioritize compact symbol reads, architectural maps, and pre-commit secret guards. Your team can run multi-agent workflows all day without exhausting context windows or hitting rate-limit ceilings.