ANTIGRAVITY LABJP
Articles/AI Tools
AI Tools/2026-07-01Advanced

Measure Before You Trim: A Context Ledger for Antigravity CLI Token and Latency Costs

Prompted by the ~70% token reduction reported for the Android CLI agent, I built a thin wrapper and a weekly review to measure my own agent runs. Here is how I replaced whole-file context with line ranges and cut wait times.

Antigravity CLI11Token ReductionContext DesignMeasurementIndie Development5

Premium Article

A recent update reported that an agent running on the Android command line completed tasks about three times faster and used roughly 70% fewer tokens than standard tooling. The speed is genuinely welcome, but staring at that number made me realize something uncomfortable: I had no idea how much context my own agent runs were actually sending, or how long I was waiting. A story about reduction only means something once you can measure where you stand today.

As an indie developer I run several apps and several blogs in parallel, and I throw small fix-it tasks at the Antigravity CLI many times a day. I had a vague feeling that "this task is oddly slow" or "my quota is draining fast today," but I couldn't put a number on any of it. So I worked in a deliberate order: lay a thin measurement layer over the CLI first, then trim. These are my notes from doing exactly that.

What Do You Measure to See the Waste?

The most reliable source of exact token usage is the CLI's quota screen or usage report. The trouble is that those numbers tend to be a session-wide total rather than per-task, so they can't tell you which task is heavy.

So I settled on two proxy metrics I can fully control.

Wall-clock seconds

This maps directly to how it feels. Simply recording the real time until the agent returns already makes the weight difference between tasks obvious.

Bytes of explicitly passed context

I can't fully control what semantic search picks up behind the scenes, but I can count the bytes of the files and ranges I hand over by hand precisely. It isn't tokens, but it's more than enough to spot when I'm shipping a needlessly large input.

I append these two values, along with a tag for the task, one line at a time. That tiny ledger became my starting point.

A Thin Wrapper That Records One Task

Instead of calling the CLI directly, I route calls through a wrapper that writes the time and context size before and after. Adjust the command and flags to match your version. What matters is that one line gets recorded automatically on every call, without my having to ask for it.

#!/usr/bin/env bash
# agy-run.sh — a thin wrapper that records wait time and context size around the Antigravity CLI
set -euo pipefail
 
LEDGER="${HOME}/.agy/ledger.csv"
mkdir -p "$(dirname "$LEDGER")"
[ -f "$LEDGER" ] || echo "ts,tag,context_bytes,context_files,seconds,status" > "$LEDGER"
 
TAG="${1:?usage: agy-run <tag> <prompt-file> [context files or ranges...]}"
PROMPT_FILE="${2:?prompt file required}"
shift 2
CTX=("$@")
 
# Total bytes of explicitly passed context (a proxy I can control).
# For a range like "path:120-164", approximate using just the file name.
ctx_bytes=0
for item in "${CTX[@]}"; do
  f="${item%%:*}"
  [ -f "$f" ] && ctx_bytes=$(( ctx_bytes + $(wc -c < "$f") ))
done
 
start=$(date +%s)
# The real call. Only what you pass via --context is used for grounding.
agy run --prompt "$PROMPT_FILE" ${CTX[@]:+--context "${CTX[@]}"}
status=$?
end=$(date +%s)
 
printf '%s,%s,%d,%d,%d,%d\n' \
  "$(date -u +%FT%TZ)" "$TAG" "$ctx_bytes" "${#CTX[@]}" "$(( end - start ))" "$status" \
  >> "$LEDGER"
 
exit "$status"

Three points matter here. First, set -euo pipefail keeps a mid-run failure from being silently swallowed. Second, recording the exit code too lets me later filter out tasks that were "fast but actually failed." Third, when I pass a range like path:120-164, the byte count is approximated from the file name only. If you want exact range counts, pipe sed -n output into wc -c, but I chose a rough form I could actually keep up with.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
How to build a ~60-line wrapper that records per-task wait time and context size for the Antigravity CLI into a CSV
The exact steps that cut my wait time from about 70 seconds to around 25 by swapping whole-file context for @path:line-range plus semantic search
The ledger_report aggregation logic for a weekly token audit of unattended runs, such as an AdMob-connected app
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

AI Tools2026-06-24
When an Overnight Local Agent Crawls by Dawn — Keeping Ollama's Latency Flat by Working Backward from Context Length
Why each step of a long-running local agent gets heavier toward the end, how to measure it from Ollama's timing fields, and how a fixed num_ctx plus a rolling summary keep per-step latency flat.
AI Tools2026-06-20
A Schedule That Survives 429s: Backoff and Jitter for Agent Automation
Run agents in parallel and rate-limit 429s can cascade until everything dies. Here is how to design exponential backoff and jitter so the retries themselves don't create new congestion, from an indie developer's automation setup.
AI Tools2026-06-18
Using the v2.1.4 Quota Screen for a Weekly Reckoning: Reading Used and Remaining to Run an Indie Budget
How to turn the used/remaining display in the reworked Antigravity v2.1.4 quota screen into a weekly reckoning instead of a gut feeling. Baseline recording, burn-rate math, and allocation across multiple projects, written as an indie-dev operating routine.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →