The Autonomous Context Firewall
for AI Coding Agents
Stop Cursor, Claude Code, and Windsurf from choking on 40,000-token terminal cascades, giant monorepos, and runaway retry loops.
pip install iktisad
iktisad --mcp
The 4 Pillars of Autonomous Context Defense
Autonomous coding agents don't just fail on bad prompts—they fail because raw terminal noise, bloated codebases, runaway retry loops, and unrouted frontier models incinerate token budgets.
1. CLI & Terminal Noise Compactor
Compress pytest, vitest, cargo, docker, and build outputs deterministically. Strips passing dots, worker heartbeats, and internal framework frames while preserving the exact failing assertion and root cause.
2. AST Codebase Skeletonizer
Compress 10,000-line monorepos into semantic structural signatures, classes, and method boundaries in pure Python AST. Provides complete architectural visibility without ingesting private implementation code.
3. Runaway Loop Circuit Breaker
Tracks retry velocity and repetitive error patterns. Automatically detects when an agent is trapped in an infinite retry loop and trips the circuit breaker before $50+ is wasted on repetitive hallucinated fixes.
4. Frugal Model Router
Enforces the Bezos Sandwich Protocol: routes heavy terminal and repo ingestion to Gemini 3.8 Flash for brief distillation, and triggers 1-shot Claude Opus 5.5 / o3 only for strategic execution.
Before vs. After Token Bleed Visualizer
Reasoning models generate internal chain-of-thought (CoT) over every token you feed them. Feeding thousands of tokens of noisy terminal stdout inflates reasoning latency, distorts attention, and multiplies costs.
The Bezos Sandwich Protocol (2026 Edition)
Type-1 decisions (one-way doors) require deep strategic reasoning. Type-2 decisions (two-way doors) are reversible. Never burn frontier reasoning tokens on mechanical compilation or log scrolling.
Gemini 3.8 Flash
Extracts 0-token AST code skeletons, compresses noisy terminal logs, and constructs a dense <600-token brief.
Claude Opus 5.5 / o3 / Fable
Frontier reasoning model ingests ONLY the distilled brief. Solves the core algorithmic failure in a single zero-shot decision without thinking token bloat.
Gemini 3.8 Flash / Local AST
Applies exact code diff, runs local pytest verification through the iktisad firewall, and stages clean commit. Total cost: $0.01 instead of $1.50.
| Architecture | Input Context Size | Frontier CoT Thinking Tokens | Cost per Bug Fix | Loop Risk |
|---|---|---|---|---|
| Naive Agentic Loop (Raw Terminal Dumps) | 40k – 90k tokens | 8,000 – 16,000 tokens | $1.20 – $2.80 | High (HTTP 429 cascades) |
| İktisad Sandwich Protocol (Frugal Gateway) | < 600 tokens | < 800 tokens | $0.02 – $0.05 | Zero (Circuit breaker protected) |
Native Model Context Protocol (MCP) Server
Equip Cursor, Claude Code, and Windsurf with native token defense tools using the official Model Context Protocol.
// In Cursor Settings -> MCP Servers:
{
"name": "iktisad",
"type": "stdio",
"command": "iktisad",
"args": ["--mcp"]
}| Exposed MCP Tool | Functionality | Token Savings |
|---|---|---|
compress_terminal_log |
Compresses pytest, compiler, and shell logs, isolating only failed assertions and tracebacks | 80% – 97% |
extract_ast_skeleton |
Extracts class/function signatures, docstrings, and line bounds with 0 LLM tokens | 100% (0 tokens) |
select_frugal_model |
Evaluates task heaviness/irreversibility and routes between Flash & Frontier reasoners | 50% – 90% |
check_circuit_breaker |
Enforces hourly/daily token quotas, automatically killing runaway agent retry loops | Protects Budgets |
iktisad Frugal Gateway
A drop-in reverse proxy that intercepts outbound LLM API requests, silently strips terminal noise, enforces local SQLite token velocity, and protects against HTTP 429 cascades.
Reverse Proxy Interceptor
Point your agents to http://localhost:8000/v1. Compatible with OpenAI, Anthropic, and Gemini wire protocols. Automatically strips raw test logs before forwarding upstream.
iktisad --serve-gateway --port 8000
Runaway Loop Circuit Breaker
If an autonomous agent is caught in an infinite error-fix loop consuming tokens without moving the needle, iktisad trips the breaker and stops the bleed before your card gets billed.
iktisad --circuit-status
Zero-Token AST Skeletonizer
Extract class definitions, method signatures, and line boundaries in pure Python AST. Read 2,000-line repositories in 30 lines without ingesting entire files into LLM context.
iktisad --ast-skeleton my_file.py