◉ANTIGRAVITY LABJP
Articles/AI Tools
⚙ AI Tools/2026-08-28Intermediate

Three things I had to fix before my status line could tell me what a session cost

Getting real session cost into a custom Antigravity CLI status line took three fixes: how the script reads stdin, how to tell whether your build sends a cost field, and how to keep a usage ledger that does not double-count.

antigravity476antigravity-cli16statuslinecost5indie-development5

✦ Premium Article

I could read the invoice at the end of the month. What I could not do was answer a simpler question: which piece of work cost the most last week?

As an indie developer moving between several repositories in a single day, almost everything I run is short. A few large design requests, and then hundreds of completions, searches, and quick confirmations. Those short sessions are exactly the ones that never show up in a monthly total in any useful shape.

CLI 1.1.21 added an unrounded session cost to the status line data model. I sat down to wire that into a custom status line, and hit three separate problems before anything useful appeared on screen. Here they are, in the order I met them.

Start by dumping what your own build actually sends

The mechanism is simple. Put a statusLine block in ~/.gemini/antigravity-cli/settings.json, and whenever the agent state changes, the CLI runs your command, pipes a JSON state payload into its stdin, reads a string from stdout, and renders it at the bottom of the prompt panel.

{
  "statusLine": {
    "type": "command",
    "command": "~/.gemini/antigravity-cli/statusline.sh"
  }
}

The official status line documentation lists the fields in that payload. As I will get to below, that table is not guaranteed to match the build on your machine. So the first thing worth doing is not reading the table — it is writing the payload to a file, once.

#!/usr/bin/env bash
# ~/.gemini/antigravity-cli/statusline.sh  (throwaway, for inspection only)
# Goal: capture exactly one real payload from the build you are running.
DUMP="$HOME/.gemini/antigravity-cli/payload-sample.json"
 
payload="$(timeout 2 cat)"
 
# Only write once. If it is overwritten on every state change,
# you lose the ability to diff it against a later version.
if [ -n "$payload" ] && [ ! -s "$DUMP" ]; then
  printf '%s\n' "$payload" > "$DUMP"
fi
 
echo "sampling..."

Start the CLI once, open payload-sample.json, and you know where you stand. I skipped this step, went straight from the docs table to writing code, and took the detour described below.

The reason for timeout 2 cat is the next section.

Reading stdin the obvious way can leave your script hanging

The first line I wrote was this:

payload="$(cat)"

In an ordinary shell script that is fine. A status line script is not ordinary: it runs under a wall-clock budget and has to print something and exit inside it. And during auth token refresh or conversation resume, the CLI can hold the stdin pipe open without writing to it and without closing it. cat waits for end-of-input, so in that state it simply does not come back.

The official docs put the budget at 5 seconds; a run that exceeds it is stopped by the CLI. The command fires on state changes, at most once every 300 ms, and after 30 consecutive failures the CLI stops calling the script for the rest of the session. So one wedging read does not just freeze a frame — it can remove the status line from that session altogether.

I reproduced the condition locally — a parent that holds the pipe and never writes — and measured both spellings from inside the script itself.

How stdin is readParent writes and closesParent holds the pipe openExit code
payload="$(cat)"read in 4 msnever returns; killed from outside124
payload="$(timeout 2 cat)"read in 4 msreturns empty after 2,004 ms0

Exit code 124 means it was killed for running out of time. On screen this shows up as vague symptoms — the status line stops updating, input feels sticky for a moment — which is why it takes a while to suspect the way your script reads its input.

The fix is to guarantee the return, and to have somewhere to fall back to when nothing arrives.

#!/usr/bin/env bash
# A status line that always returns inside its budget
CACHE="$HOME/.gemini/antigravity-cli/.statusline-last"
 
payload="$(timeout 2 cat)"
 
if [ -z "$payload" ]; then
  # Nothing arrived. Print the previous line and exit.
  # Exiting non-zero here just puts an error on screen every few seconds.
  cat "$CACHE" 2>/dev/null || echo "agy"
  exit 0
fi
 
line="$(printf '%s' "$payload" | python3 -c '
import sys, json
p = json.load(sys.stdin)
cw = p.get("context_window") or {}
vcs = p.get("vcs") or {}
print("{} | {} | ctx {:.0f}%".format(
    (p.get("model") or {}).get("display_name", "?"),
    vcs.get("branch", "-"),  # docs list only vcs.type; default keeps it safe
    cw.get("used_percentage") or 0,
))
')"
 
printf '%s' "$line" | tee "$CACHE"

I also tried read -r -t 2, which bounds the wait but only captures the first line — and the payload can arrive pretty-printed across several lines. timeout 2 cat handles both.

One more thing that cost me time. If you test with something like ( sleep 20 ) | timeout 8 ./statusline.sh, the script returns in two seconds but your shell waits for the left side of the pipeline, so it feels like twenty. It is easy to conclude your script is slow when your test harness is. Measure from inside the script.

# Time it from inside; an outer `time` measures the whole pipeline
S=$(date +%s%N)
payload="$(timeout 2 cat)"
E=$(date +%s%N)
echo "took=$(( (E - S) / 1000000 ))ms" >&2
✦

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
✦You can write a status line script that always returns inside its time budget, instead of one that wedges the CLI
✦You can confirm what your own build actually sends, rather than trusting a field table that may lag behind the release notes
✦You can keep a usage ledger that does not double-count, and answer which project your spend is concentrated in
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-11-13
Gemini 4 Carbon Doubles in Price on December 1: Estimating One Antigravity Session from Cache Ratio and Thinking Level
Antigravity v2.31.2 lets you pick Gemini 4 Carbon when signed in with Google Cloud credentials. Before the introductory price ($2 input, $10 output) ends on November 30, here is a small script that estimates what one session costs from tokens, cache ratio, and thinking level, plus where the price increase can and cannot be absorbed.
⚙ AI Tools2026-10-15
Does Splitting Work Across AI Tools Really Save Money? Put the Monthly Gap and the Switching Cost in One Table
Is it cheaper to use different AI tools for different tasks? A small Python script that puts per-task cost and switching effort side by side so you can find the break-even point.
⚙ AI Tools2026-10-01
You Don't Need to Read Commands: Three Places to Check When an Agent Works
If strings of terminal text make the approve button feel risky, here is a way to check just three things: a way back before you start, the first word of a command, and the diff afterward.