Skip to content

About

Reduce context size by 90%+ *and* make your agent smarter. Antigravity Context Mode is a local-first plugin built specifically for the Google Antigravity App. It prevents terminal commands, build logs, and multi-megabyte files from flooding your conversation history, saving thousands of tokens per turn and stopping "agent amnesia" in its tracks.

Topics

Resources

Stars

172 stars

Watchers

2 watching

Forks

Repository files navigation

Antigravity Context Mode

Stop context bloat. Save 90%+ of your prompt tokens. Keep your agent fast, focused, and sharp.

npm version Live Simulator License: MIT Zero Runtime Dependencies Antigravity App Compatible

Antigravity Context Mode is a free, local-first plugin built specifically for the Google Antigravity App. It prevents terminal commands, build logs, and multi-megabyte source files from flooding your conversation history β€” saving thousands of tokens per turn and stopping "agent amnesia" in its tracks.

Major 2.0 update - Update now. See table below for details

🌐 Interactive Simulator & Documentation: domush.github.io/antigravity-plugin-context-mode

image_e74feae3118b629d

Quick Install (10 Seconds)

Install directly into Google Antigravity using npx:

# Global install (available across all Antigravity chats)
npx antigravity-plugin-context-mode install

# Or per-project install (scoped to current workspace only)
npx antigravity-plugin-context-mode install --workspace

Restart or open the Google Antigravity App, and Context Mode is active immediately (installed into ~/.gemini/config/plugins/context-mode, or .gemini/plugins/context-mode for workspace installs).


The Problem: Context Window Bloat

When an AI coding agent executes tools, standard workflows dump everything directly into your conversation context:

  • Running Get-Content Logs/Editor.log dumps 65 KB (~16,000 tokens) into your prompt.
  • Running test suites, compiler outputs, or git diffs dumps 100+ KB of repetitive text.
  • Reading large files or documentation dumps thousands of lines of irrelevant boilerplate.

Why this hurts:

  1. Agent Amnesia: Important system instructions, user constraints, and earlier architectural decisions get drowned out.
  2. Slower Responses: Generation times climb as the context window fills up with raw text.
  3. Burned Quota: You hit model context ceilings and rate limits after only a few turns.

How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 1. Agent attempts to read a large file or command      β”‚
β”‚    (e.g. 5,000-line build log or 40 KB source file)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 2. Pre-Tool Lifecycle Hook Intercepts Unbounded Dumps  β”‚
β”‚    β€’ Files under 8 KB pass through normally            β”‚
β”‚    β€’ Un-paged dumps over 8 KB are safely intercepted   β”‚
β”‚    β€’ Images, docs, and chat attachments are exempted   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 3. Sandboxed Execution ("Thinking in Code")            β”‚
β”‚    β€’ Agent filters data locally using Node/Python      β”‚
β”‚    β€’ Indexes text into local SQLite FTS5 BM25 database β”‚
β”‚    β€’ Returns only the exact answer or error to chat!   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Proven Results

Tested live on real-world build logs and source files in the Antigravity App:

Operation Without Context Mode With Context Mode Savings
Parsing 665-line Unity Editor.log 65,242 B (~16,300 tokens) 550 B (~137 tokens) 99.2% saved
Full File Read on 40 KB component 40,960 B (~10,240 tokens) Intercepted & paged to 50 lines (~800 tokens) 92.1% saved
Searching Compiler Warnings Entire log dumped into chat Top 2 ranked FTS5 snippets (~350 tokens) 97.8% saved

Key Features

  • πŸ›‘οΈ Automated Interception: Blocks unbounded file dumps and commands before they bloat your context window.
  • 🧠 Intelligent Language-Aware Chunking (v2.0): Intelligently chunks source code (JS, TS, Python, Java, C#, Go, Rust, Ruby, PHP, C/C++, Shell, SQL), Markdown, JSON, YAML, TOML, HTML/XML, and logs. Never slices methods, headings, or stack traces mid-block.
  • 🎯 Context-Expanding Search Results: ctx_search returns complete source code methods, paragraphs, or markdown sections intact, along with startLine, endLine, and enclosing scope metadata.
  • ⚑ Thinking in Code: Filters multi-thousand-line outputs in 50 ms via local sandboxed scripts.
  • πŸ” Local SQLite FTS5 Search: Indexes files and logs locally on your machine with BM25 keyword matching and trigram search.
  • πŸ“Š Built-In Sidecar Dashboard: Real-time stats pane inside Antigravity showing tokens kept out of context.
  • πŸ”’ 100% Local & Private: All indexed data stays on your machine in ~/.context-mode/context.db. Zero network calls.
  • πŸ“¦ Zero Dependencies: Pure native Node.js (node:sqlite). No native builds, no node-gyp.

πŸ“Š Release Summary Matrix

Feature / Capability v1.4.0 v1.5.0 v2.0.0
Tool Read Cutoff & Hook Interception βœ… Dynamic line scaling βœ… Auto-index on hook βœ… Auto-index on hook
File Exemption Controls βœ… 1-click category pills βœ… Injected into agent context βœ… Injected into agent context
Indexing Model Manual (ctx_index) βœ… Just-In-Time (ctx_search) βœ… Just-In-Time (ctx_search)
MCP Tool Surface 8 tools (with ctx_index) βœ… 7 streamlined tools βœ… 7 streamlined tools
Log Search Strategy Standard βœ… Reverse / Tail-First βœ… Tail-First + Stack Trace Grouping
Chunking Engine Byte & line buckets Byte & line buckets βœ… AST & Syntax-Aware Semantic Engine
Code Structure Preservation Partial Partial βœ… 15+ Languages, Classes & Methods Intact
Markdown Chunking Line-based Line-based βœ… Heading Breadcrumbs (# H1 > ## H2)
Search Result Snippets Centered window slice Centered window slice βœ… Complete Intact Method (up to 2 KB)
Search Metadata Score & source Path & score βœ… Lines X–Y, Enclosing Scope Context
SQLite Schema Schema v2 Schema v3 (path PK) βœ… Schema v4 (Unindexed Scope Metadata)

Available MCP Tools

Once installed, Context Mode provides 7 specialized tools under context-mode_ctx that return clean, readable Markdown summaries for your agent:

Tool What It Does
ctx_execute Runs sandboxed Node.js, Python, or PowerShell scripts to inspect files and extract answers without context dumps.
ctx_search Searches files, directories, or URLs with Just-In-Time auto-indexing using local SQLite FTS5 BM25 + Trigram RRF.
ctx_batch Runs multiple terminal commands in batch and indexes the combined output.
ctx_stats Displays a formatted context savings report and token metrics.
ctx_resume Returns recent indexed sources and state pointers after context compactions.
ctx_doctor Checks SQLite database health, WAL mode, and platform runtimes.
ctx_purge Clears stored sources and events from SQLite.

Managing the Plugin

Enable / Disable Anytime

Open the Google Antigravity App β†’ Customizations β†’ Plugins, and toggle Context Mode on or off with one click.

Adjust Cutoffs

You can adjust the file read cutoff directly in the sidecar dashboard dropdown (2 KB, 4 KB, 8 KB, 16 KB, 32 KB, 64 KB, or none).

Optional Environment Variables

For fine-grained control alongside the dashboard settings, you can configure optional environment variables:

Variable Purpose Default
CONTEXT_MODE_MAX_READ_BYTES General file read cutoff in bytes (0 disables the limit) 8192 (8 KB)
CONTEXT_MODE_MAX_LINE_RANGE Maximum line slice allowed without triggering the cutoff Dynamic (50–2000 lines)
CONTEXT_MODE_SOURCE_MAX_BYTES Separate size ceiling in bytes for programming source files (e.g. 65536 for 64 KB), preserving full code context while still capping minified bundles (*.min.js/*.min.css), oversized files, and data dumps Unset (uses general cutoff)
CONTEXT_MODE_SOURCE_EXTENSIONS Additional comma-separated file extensions added to the built-in programming source allowlist (e.g. .json,.yaml) Built-in source languages
CONTEXT_MODE_MAX_AUTO_INDEX_BYTES Maximum file size automatically indexed on interception (0 disables) 52428800 (50 MB)

Uninstall

To remove the plugin from your system:

# Remove global plugin
npx antigravity-plugin-context-mode uninstall

# Remove per-project plugin
npx antigravity-plugin-context-mode uninstall --workspace

License

MIT Β© Phillip Webber

About

Reduce context size by 90%+ *and* make your agent smarter. Antigravity Context Mode is a local-first plugin built specifically for the Google Antigravity App. It prevents terminal commands, build logs, and multi-megabyte files from flooding your conversation history, saving thousands of tokens per turn and stopping "agent amnesia" in its tracks.

Topics

Resources

Stars

172 stars

Watchers

2 watching

Forks

Releases

Contributors

Languages