Context engineering // structural intake
AST Pruning vs Prompt Compression: What Actually Cuts Tokens Without Breaking the Model
Prompt compression shrinks text; AST pruning removes syntactic dead weight before the model ever sees your repo. Learn when each approach wins, how to measure the delta, and why IDE agents need structure-aware intake—not another summarizer.
Every week another “context compression” startup promises to cram a forty-file pull request into a postcard-sized paragraph. The pitch sounds irresistible: drop input tokens, dodge rate limits, and keep the chat box green. In production, teams discover the catch quickly. Aggressive summarization deletes the one import path, the deprecated flag, or the error branch that the model needed to ship a safe fix. AST pruning takes a different philosophy. It keeps semantics intact while stripping nodes the compiler would ignore anyway—license headers duplicated across files, generated protobuf stubs, comment blocks that repeat Javadoc from upstream, and import graphs that pull entire standard libraries into scope without ever being referenced.
Polycracker’s intake pipeline is built on that structural distinction. Polydyno instruments raw versus pruned payloads so you can see the savings in tokens and milliseconds, while The Tuning House lets security teams publish signed maps that define which pruning rules apply per repository. If you are evaluating tooling, this guide walks through decision criteria, token math, and integration patterns so you can defend the architecture to both staff engineers and budget owners.
Two pipelines, two failure modes
Prompt compression typically runs late in the request path. A middleware layer receives the full chat transcript, optional RAG chunks, and attached files, then calls a smaller model or heuristic embedder to rewrite the bundle. Information loss is intentional: nouns become pronouns, stack traces collapse to one line, and “similar” code blocks dedupe by fuzzy hash. That works for executive summaries and customer-support macros. It fails for coding agents because the rewrite is not reversible and not scoped to language grammar. A missing generic type parameter or swallowed exception handler can send an agent into a thrashing loop that burns output tokens—often costing more than you saved on input.
AST pruning runs early and locally. The runtime parses each attached file into an abstract syntax tree (or equivalent intermediate representation for non-JS languages), applies deterministic rules—drop whitespace-only nodes, collapse re-export barrels, inline trivial type aliases, strip unreachable branches identified by static analysis—and serializes a canonical, minified source view. The model still reads valid code. Diff tools still apply. Reviewers can map answers back to line numbers in Git. The failure mode is under-pruning: you leave boilerplate on the table. That is measurable and fixable without retraining models.
| Dimension | Prompt compression | AST pruning (Polycracker) |
|---|---|---|
| Runs | Cloud middleware, often third party | Local runtime (Polycracker ECU) |
| Preserves syntax | No guarantee | Yes—output stays parsable |
| Best for | Narrative RAG, support tickets | IDE agents, refactors, codegen |
| Typical savings | 20–40% with hallucination risk | 50–70% with audit trail |
| Telemetry | Often ships content to vendor | Zero-telemetry option on Windows ECU |
Worked token math on a real intake payload
Consider a TypeScript service handlers folder attached to a Cursor or Copilot Workspace session: eight files, 2,840 lines, heavy on OpenAPI-generated types and repeated axios interceptors. A frontier model billed at $2.50 per million input tokens on a 128k context window still cares about the billable subtotal on every turn.
| Stage | Tokens (est.) | Notes |
|---|---|---|
| Raw attach (all files) | 38,200 | Includes generated clients + comments |
| After LLM-side “summarize repo” | 22,400 | Lost stack-specific error enums |
| After Polycracker AST prune + import graph | 14,050 | 63% reduction, syntax valid |
| Incremental turn (pruned cache hit) | 3,800 | Only dirty files re-serialized |
At 200 agent turns per day across ten engineers, the difference between 38k and 14k input tokens per turn is not academic. Using the same pricing assumption, raw attach spend trends toward $4,750 per month on input alone for that squad; pruned intake lands near $1,740. Output tokens from fewer regrounded retries provide additional savings documented in our token testing guide.
What gets pruned (and what never should)
Effective maps treat pruning as policy, not whimsy. The Tuning House encodes rules such as: remove block comments longer than N lines unless they contain @license; strip test fixtures from production intake unless the user prompt mentions “test”; collapse barrel index.ts re-exports when the leaf modules are already in the attachment set. Security-sensitive teams add deny lists for files matching **/secrets/** and hash-verified allow lists for standard library shims.
{
"map_version": "2026.11.1",
"language": "typescript",
"rules": [
{ "id": "drop_generated", "glob": "**/*.gen.ts", "action": "exclude" },
{ "id": "minify_imports", "action": "tree_shake_imports", "max_depth": 2 },
{ "id": "strip_banner", "pattern": "^/\\*!.*?\\*/", "action": "remove" }
]
}
Prompt compression cannot express those guarantees because it does not parse globs or AST node kinds. It sees bytes. That is why hybrid architectures fail when compression runs after pruning and undoes structure—double-processing latencies spike, and you pay twice.
Latency and rate limits follow intake size
Tokens per minute (TPM) throttles from OpenAI, Anthropic, and Azure OpenAI are input-sized. A 38k prompt not only costs more but also occupies the TPM budget longer, increasing queue time and 429 responses documented in our rate-limit playbook. Local pruning on Polycracker ECU shrinks payloads before they hit TLS, so the provider queue sees a leaner request and your p95 time-to-first-token improves even when the model name stays constant.
Polydyno’s drag-strip view compares stock versus tuned lanes using the same pricing sliders as the marketing site. Wire it into CI to fail builds when a new dependency adds more than X thousand tokens of boilerplate to default agent context—turning context debt into a lint error.
When prompt compression still makes sense
We are not claiming summarization is useless. Longitudinal chat history—weeks of stand-up notes, incident timelines, or legal discovery PDFs—benefits from hierarchical summarization where fidelity to source code is irrelevant. RAG pipelines that retrieve ten near-duplicate Markdown chunks may dedupe at the embedding layer before synthesis. The mistake is applying those patterns to compilable source. Use compression downstream of retrieval for prose; use AST pruning upstream of any tool that edits code.
If your vendor only offers compression, ask whether their rewriter is invertible and whether they log payloads. For regulated industries, the answer pushes teams toward local pruning with SHA-256 verified binaries as described in the zero-telemetry proxy guide.
Implementation checklist
- Baseline a week of agent sessions with Polydyno counters on raw attachments.
- Enable Polycracker ECU on developer workstations; point IDE MCP HTTP proxy to
127.0.0.1:8000. - Publish a Tuning House map per monorepo; start conservative, tighten rules after diff review.
- Re-run token tests; target 50–70% input reduction without rising defect rate.
- Document wins for finance using monthly TPM charts—not anecdotal “it feels faster.”
AST pruning is not a cosmetic minifier. It is an intake discipline that aligns agent context with what the compiler already knows is redundant. Prompt compression is a blunt instrument for prose. Pair the right tool to the artifact type, measure everything, and keep the pipeline on your machine when IP sensitivity demands it.