SuperAPIAI Directory

ctxfw

github.com · AI coding

ctxfw is a local context firewall and Tree-Sitter AST pruning MCP server for AI coding agents. It strips indirect prompt injection from untrusted MCP tool output before the context enters the LLM, and compresses peripheral dependencies into typed interfaces, thereby reducing token consumption (officially claimed to reduce peripheral context token mass by about 72.4%). The tool runs fully offline, with no cloud proxy, no vector database, and no telemetry, and provides its service via local stdio. Main features include: syntax-aware AST compression (keeping the focus file intact, trimming imported dependencies into typed interface contracts, and generating a compact symbol index), pre-ingestion tool and input sanitization (SARA, mcp_guard, supporting multiple languages and detection of homoglyphs, bidirectional override characters, path traversal, etc.), spec checking and diff gating (SWE-Gate, TraceKit, requiring formal specs to include negative invariants, etc., and recording a local audit chain). It provides a standalone zero-Python executable (v4.2.2) supporting Linux, macOS, and Windows, and can configure Claude Code, Claude Desktop, Cursor, and Windsurf with a single idempotent command. It is suitable for scenarios where AI coding agents read code repositories or call MCP tools, helping to reduce token bloat, prevent prompt injection, and enhance diff reliability. Limitations include: AST skeletonization does not replace LSP's cross-file semantic type resolution; deterministic CPU sanitization may produce false positives; strict diff gating may reject certain types of ignore comments.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsmacOS · Linux

About this tool

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:

  1. 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.
  2. 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).
  3. 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.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools