ctxfw is a local context firewall and Tree-Sitter AST pruning MCP server for AI coding agents, developed by Heurístico Lab and released under the Apache 2.0 open-source license (core functionality). Its goal is to perform three deterministic checks on the local CPU before context reaches the LLM or leaves CI, fully offline with zero cloud egress.
Purpose: to solve predictable problems that arise when coding agents read unfiltered repositories and untrusted MCP tool output, including peripheral token bloat, indirect prompt injection, and unfounded diffs.
Main capabilities:
- Syntax-aware AST compression: keeps the focus file being edited 100% byte-intact, trims imported peripheral dependencies into typed function/class interface contracts (supporting Python, TypeScript/JavaScript, Go, Java), generates a compact symbol index of no more than 1,000 tokens, and compresses noisy multi-step agent trajectories.
- Pre-ingestion tool and input sanitization (SARA, mcp_guard): screens untrusted tool results and prompts within 1 ms P50, covering 7 languages (es, fr, de, pt, zh, ja, ko), Cyrillic/Greek/Armenian homoglyphs in mixed scripts, Trojan Source bidirectional overrides (U+202A–U+202E), 1 to 4 rounds of percent-encoded path traversal (%XX), SHA-256 tool schema rug-pull, and per-client burst flooding (McpBurstRateLimiter using hashed client IDs).
- Spec checking, diff gating, and local audit chain (SWE-Gate, TraceKit): requires formal specs to contain at least 5 explicit negative invariants, finite variable bounds, deterministic state transitions, and 4 classes of error taxonomy (Axiom Completeness Index ACI ≥ 0.9000); blocks diffs that increase cyclomatic complexity by more than 10 or introduce # type: ignore; records verdicts to an append-only local SQLite WAL SHA-256 chain.
Usage:
- Standalone zero-Python executable (v4.2.2) for Linux, macOS, and Windows, published on GitHub Releases.
- Can configure Claude Code, Claude Desktop, Cursor and Windsurf (automatically creating .bak.<timestamp> backups).
- Provides a reusable Agent Skill (SKILL.md) as well as guided walkthroughs for Claude Code, Cursor, and Antigravity.
- For non-MCP agents (Aider, OpenCode Interpreter, Continue.dev), a local loopback proxy can be started.
- Exposes MCP stdio tools (ctxfw mcp) and core CLI commands.
Applicable scenarios: development scenarios that use AI coding agents to read code repositories, invoke MCP tools, need to reduce token consumption, defend against indirect prompt injection, and enhance diff reliability.
Limitations and boundaries:
- Syntax and types: AST skeletonization reduces peripheral token noise at the syntax level and does not replace the full cross-file semantic type resolution of an LSP (pyright/tsserver); unsupported file extensions fall back safely and do not truncate the focus file.
- False-positive trade-off: deterministic CPU sanitization prioritizes sub-millisecond speed and zero external calls over contextual nuance; in security test suites or repositories containing vulnerability fixtures, literal signatures may trigger false positives (for example, legacy findings need to be handled via signature baseline freezing or added to an allowlist), and strict diff gating will reject # type: ignore suppressions unless scoped in policy.
- Deterministic rules vs. LLM judgment: the pre-execution gate performs offline checks of lexical, structural, and cryptographic invariants and does not act as a general-purpose reasoning LLM judge.
Other information: official empirical benchmarks are provided; all benchmarks run offline with zero network egress calls. On cold-start turns, dynamic tool outputs, or providers without prompt caching, pruning about 72.4% of peripheral context can reduce single-turn token mass by 3.62x; combined with multi-turn trajectory folding, it can compound to 4.2x under traditional multi-turn billing models (when provider prompt caching is enabled, dollar savings on repeated prefix tokens are smaller, but latency and context dilution still improve). The commercial edition provides multi-developer governance and enterprise infrastructure.