Skip to content
Projects

souhhcong/antigravity-context-monitor

View on GitHub

About

Live session context window monitor for Google Antigravity — token breakdown, cache hit rate, orchestrator models & interactive turn history in the side pane.

Developer Tools

How these counts are measured

What you can do

  • Clean Tab Layout (Overview / History / Cache / Beta) — Keeps Overview focused on active context and cache stats, History on Turn history and Top context hogs, and Cache on an empirical binned Cache survival step chart (with scale break after 5m, longest hit, and self-eviction / effort-switch detection), plus Beta for the opt-in agent features.
  • Clean Category Breakdown — Automatically sorts active categories largest-first across Assistant, Thinking, Files, Terminal, Skills, Web, MCP tools, System prompt, Summary (after /compact), User messages, and Free space with linked hover highlighting.
  • Compact alert Threshold — Set a token (128K–512K) or percentage (75%–85%) reminder to show a marker on the usage bar, a reference line in Turn history, and a Compact ready indicator when reached.
  • Multi-Model Turn History — Interactive SVG sparkline with separate per-model series lines and a clickable legend to isolate models in Orchestrator sessions, plus zero-shift hover inspection.

Measured star growth

in 24h
Collecting history
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original
Antigravity Context Monitor logo

Antigravity Context Monitor

Live session context window telemetry for Google Antigravity — in your side pane, using 0 extra LLM tokens.

Tests VS Code Marketplace VS Code Installs Open VSX Version Open VSX Downloads Zero Dependencies LLM Overhead License: MIT


Context Monitor Overview tab Context Monitor History tab Context Monitor Cache tab

Features

  • Clean Tab Layout (Overview / History / Cache / Beta) — Keeps Overview focused on active context and cache stats, History on Turn history and Top context hogs, and Cache on an empirical binned Cache survival step chart (with scale break after 5m, longest hit, and self-eviction / effort-switch detection), plus Beta for the opt-in agent features.
  • Clean Category Breakdown — Automatically sorts active categories largest-first across Assistant, Thinking, Files, Terminal, Skills, Web, MCP tools, System prompt, Summary (after /compact), User messages, and Free space with linked hover highlighting.
  • Compact alert Threshold — Set a token (128K–512K) or percentage (75%–85%) reminder to show a marker on the usage bar, a reference line in Turn history, and a Compact ready indicator when reached.
  • Optimal Compaction Point (Auto) — The Auto compact alert picks the cheapest point to compact from your own transcripts, with no extra LLM calls. It learns your post-compaction base, growth per turn, summary size and recovery turns, then minimizes the cycle-cost model from LangWatch's Context Tax study, weighted by the model's prices when they are known (cheap cached re-reads vs. the fresh input and output a compaction and its recovery pay), falling back to plain token counts otherwise. It is a heuristic estimate, and the tooltip says which basis (priors or learned, token or dollar weighting) it used. The usage bar and Turn history show the near-optimal band (within 10% of the cheapest point), and the menu reads Auto (Learned ~186K) once a few compactions back it (Est. before that). The target leans later for building and code understanding and earlier for PR driving, and it is capped at 85% of the window. Inside the band, Cheap to compact appears when the cache is already cold or much of the context is reclaimable. A manual alert below the learned floor is flagged as too early. When the window itself is too small (its 85% cap is below the floor), Auto shows Window < floor at the cap instead of Compact ready. Hover the button for the numbers behind it.
  • Multi-Model Turn History — Interactive SVG sparkline with separate per-model series lines and a clickable legend to isolate models in Orchestrator sessions, plus zero-shift hover inspection.
  • Top Context Hogs — Ranks up to 8 largest individual file reads, shell outputs, web searches, edits, and plans in the session. Hover one to select the turn that added it in Turn history.
  • Live Cache Telemetry — Tracks prompt cache hit rate, cached prefix, Adaptive Learned Cache TTL (automatically learns fixed cutoffs vs. variable LRU eviction per model from local transcripts, with manual 5m–1h overrides), Cache-Bust Autopsy (saved vs. wasted re-prefill tokens and sparkline bust markers for TTL expiry, prefix mutation, model switches, and compaction), new input, last output, and total output using 0 extra LLM tokens.
  • Compaction ROI & Re-Read Thrash — Hover a compaction in Turn history to see 412K → 18K (−96%) · 3 files re-read (+19K): files the agent read again in the 10 turns after compacting that it had already read before. Many re-reads mean you compacted too early.
  • "Why Did My Cache Break?" — Cache misses of any gap name their likely cause on hover (a loaded SKILL.md, a plugin/MCP tool-set change, a harness SYSTEM_MESSAGE, a harness re-prompt, a rewind, or no visible cause). Harness-driven resets are explained without counting as busts, and the Cache drops tooltip breaks prefix mutations down by cause. Misses with no visible cause are judged against the model's effective TTL (learned, or your manual override): past it they read TTL expired, just under it Likely TTL expired, well under it Cache evicted?, and without timestamps cause unknown, so uncertain causes are never reported as TTL expiry.
  • Cost & Cache Savings — Estimated session cost, what cache hits saved and drops cost, and in Orchestrator sessions how much delegating to the executor saved versus running every turn on the Orchestrator. Claude rates are list prices; rates for Antigravity's internal models are marked ≈ estimates. Override them in ~/.gemini/context-monitor-pricing.json (or the file named by AGY_CTX_PRICING_FILE), e.g. { "hydrogen": { "input": 1.25, "cachedInput": 0.125, "output": 10 } } in USD per million tokens.
  • Subagent Footprint — Sessions that spawn subagents (invoke_subagent) get a collapsible Subagents rollup (count, total tokens, cache %, cost, and one row per child) read lazily from the child transcripts, kept apart from the parent's context bar; the status bar never switches to a running child. Rollups past 24 children say which totals are partial. Children that start on an inherited context of 150K+ or run 72+ turns are flagged.
  • Configurable Context Ceiling — Click the window limit (e.g. 512K) to switch between Auto and fixed ceilings (128K, 200K, 256K, 400K, 512K, 1M, 2M). Auto is where Antigravity compacts the conversation on its own, which can be well below the model's window: Gemini 4 models have a 1M window but compact at 512K. If you set AGY_CLI_AUTO_COMPACT_OVERRIDE (a token count, 800K/0.5M, or 80%), Auto follows it; models without such a threshold use their full window.
  • Native Antigravity Theme — Adapts seamlessly to Antigravity's light/dark theme tokens and typography (Google Sans Flex).

Quick Install

Via Antigravity CLI

agy plugin install https://github.com/souhhcong/antigravity-context-monitor

Manual Install

git clone https://github.com/souhhcong/antigravity-context-monitor.git ~/.gemini/config/plugins/context-monitor

Once installed, open the + menu in Antigravity's right-hand auxiliary pane and select Context.

Antigravity IDE / VS Code Extension

The VS Code Antigravity extension does not currently host aux-pane sidecars, so a companion extension in vscode-extension/ reuses the same parser and UI, with a Status Bar indicator and session switcher.

Install it from the VS Code Marketplace or Open VSX (Antigravity IDE, VSCodium, Cursor), or search for Antigravity Context & Cache Monitor in the Extensions view:

code --install-extension souhhcong.antigravity-context-monitor             # VS Code
antigravity-ide --install-extension souhhcong.antigravity-context-monitor  # Antigravity IDE

Each .vsix is also attached to the matching GitHub release.

Or build it from source:

node vscode-extension/scripts/package-vsix.mjs
code --install-extension vscode-extension/antigravity-context-monitor-*.vsix --force

It automatically follows your newest active Antigravity session.

How It Works

Antigravity Context Monitor runs a lightweight, read-only local Node sidecar (sidecars/context_monitor/main.mjs) with zero external npm dependencies:

  1. Locates the active conversation's transcript_full.jsonl (falling back to transcript.jsonl) inside Antigravity's local data directory.
  2. Parses step-level token counts (input_tokens, cache_read_tokens, output_tokens) and attributes context growth across categories while preserving exact token sums and handling compaction drops.
  3. Caches parsed snapshots by file stat ETag so polling stays fast and lightweight.
  4. Makes zero outbound network requests and zero LLM calls.

Agent Self-Inspection Skill

Alongside the side-pane UI, the plugin bundles an on-demand context-intelligence skill (skills/context-intelligence/SKILL.md) backed by a local zero-dependency CLI (skills/context-intelligence/scripts/inspect.mjs). The CLI is a Beta feature: until Self-inspection CLI is checked it only prints how to turn it on.

  • Zero idle overhead: Progressive disclosure keeps the skill out of the prompt until needed, and it runs locally inside Antigravity's standard sandbox with 0 network calls.
  • Compact telemetry for the agent: Reports active context, growth rate, compaction band/status, cache warmth and drops, reclaimable stale/duplicate reads, top context hogs, cost/quota, and subagent flags:
node skills/context-intelligence/scripts/inspect.mjs --conversation "<conversation-id>" --app-data-dir "<app-data-dir>"
  • Benchmarking (bench/run-bench.mjs): Compare existing transcripts at 0 extra quota with node bench/run-bench.mjs score --control <id> --treatment <id>, or preview/run budgeted A/B scenarios with node bench/run-bench.mjs run --dry-run. Every run gets a throwaway workspace (a git worktree, or a copy of --worktree-base outside git); each treatment run stages this checkout in that workspace's .agents/plugins/ folder and the control runs without it; the harness refuses to start while the plugin is installed and enabled in your profile (it would load in both arms), checks that the plugin's hooks ran only in the treatment, and counts the quota of failed runs toward --max-usd. Pick which Beta features the treatment arm turns on with --beta <flag,...|all|none> (default selfInspectionSkill); the control arm runs with all of them off.

Beta Features (opt-in)

Open the Beta tab (sidecar or VS Code extension) to turn on features that feed the same telemetry back to the agent. All six are off by default: until one is checked, the plugin's lifecycle hooks (hooks.json, hooks/context-hooks.mjs) answer {} without reading any transcript and inject 0 tokens.

Feature Flag Hook What the agent gets
Compaction nudge compactionNudge PreInvocation When context is Cheap to compact or Compact ready, a note to wrap up the current step and suggest /compact.
Duplicate read guard duplicateReadGuard PreToolUse (read_file|view_file) A re-read of a range that is still in context and unchanged on disk is blocked once with the reason; the same read retried goes through, so the agent never gets stuck.
Runaway output alert runawayOutputAlert PreInvocation When one tool step adds 25K+ tokens, a nudge toward filtered or paged output (head, grep, StartLine/EndLine).
Heavy-context subagent nudge heavyContextSubagentNudge PreInvocation At 150K+ context growing 5K+ per turn, a suggestion to delegate broad read-only work to a fresh research subagent.
Quota pressure nudge quotaPressureNudge PreInvocation When the active model group has 20% or less of its cached 5h or weekly quota left, a note to keep steps lean.
Self-inspection CLI selfInspectionSkill — Unlocks inspect.mjs for the context-intelligence skill.
  • Each advisory fires at most once per compaction cycle per conversation (state lives in the plugin's data directory, or the OS temp directory), starts with [Context Intelligence], and shows up on the Cache tab as a Context Intelligence nudge when it changes the prompt prefix.
  • Settings are stored in ~/.gemini/context-monitor-beta.json (override the path with AGY_CTX_BETA_CONFIG), shared by the sidecar, the VS Code extension, the hooks and the CLI.

FAQ

If conversation context is shared between models in Orchestrator mode, why are there separate prompt caches?

The conversation text is shared, while the server-side prompt cache (KV cache) is separate per model. Think of context as one shared notebook on the table—both models read from and write to the same conversation history—whereas prompt caching is each model's own 5-minute short-term memory of the internal neural-network state (KV tensors) from pages it already processed. Because different models have different weights, one model cannot reuse another model's KV cache, so each model keeps its own cached prefix and independent ~5-minute TTL.

Why do context tokens spike on the planning model and drop on the execution model?

During plan-execute handoffs, the planning model keeps its own prior thinking/thought-signature blocks intact so its prefix cache stays hot across switches. The execution model cannot consume another model's thought blocks and strips them (alongside minor differences in plan vs. execution tool/system prompts), so its input count drops on handoff and rises again when switching back. That gap grows as thinking accumulates and resets after /compact.

Does Cache TTL reset on every message turn?

Yes. Each new turn for a model refreshes that model's timer (and /compact resets caches to Reset). Because providers vary and rarely publish exact TTL rules—some use fixed cutoffs (5m, 15m, 1h) while others use capacity-based LRU caches—Antigravity Context Monitor automatically learns each model's effective TTL window and variance from prefix-retention gaps across your recent local transcripts (starting from a 5m prior until enough boundary samples are observed), or lets you pin a manual window (5m–1h).

Does Compact alert trigger /compact automatically?

No—it is a visual threshold and reminder only (showing a marker on the usage bar, a reference line in Turn history, and a Compact ready badge when reached). Antigravity's plugin and sidecar APIs do not currently allow plugins to invoke /compact or override the built-in compaction threshold programmatically.

Development & Testing

# Run unit tests (Node built-in test runner)
node --test

# Validate plugin manifest & structure strictly (expects `hooks 1`)
agy plugin validate --strict .

License

MIT © 2026 souhhcong

Explore related projects

Loading…