Saturday, August 1, 2026
banner
Top Selling Multipurpose WP Theme

TL;DR:

in pure Python. Earlier than sending something to the mannequin, it figures out what your goal file really will depend on, trims non-essential code all the way down to pure interfaces, and drops the whole lot unreachable.

Examined it on two actual Python repos: it lower immediate sizes by 69–74% and ran in below 75 ms.

All of the numbers under are pulled straight from captured terminal runs. If the device couldn’t decide one thing with certainty, it explicitly marked it as an alternative of guessing.

Compilers Don’t Simply Compile Code

Compilers are simply filters that know what to maintain. You give one an entry level and a codebase, it traces what really will get referred to as, throws out the lifeless weight, and outputs an intermediate illustration with solely the element the following step wants. Nothing additional.

Most coding brokers don’t deal with immediate development like a compiler. They construct some type of repository map, collect recordsdata they consider are related, and ship them to the mannequin with comparatively little structural discount. Bigger context home windows assist, however they don’t take away irrelevant context. That additional context competes for consideration with the code that really issues. And when window sizes shrink, that bloat triggers compaction. Compaction seems like routine cleanup till it occurs mid-task: the agent summarizes its personal context to make room, then spends the following few turns attempting to reconstruct implementation particulars from a lossy abstract of a abstract. Half the time an agent “forgets” one thing, it’s simply its personal reminiscence administration degrading its recall.

I needed to see what occurs should you construct prompts with the self-discipline of a compiler moderately than simply retrieving extra stuff.

So I constructed a Context Compiler: a three-pass pipeline written solely with the Python customary library. It resolves what a goal file really reaches, trims these dependencies all the way down to interfaces, and drops the whole lot else.

Throughout two actual Python repos, it lower immediate sizes by 69–74% with a compile time below 75 ms.

Each quantity right here comes from captured terminal runs of the particular code, not estimates. You may try the supply and run the demos your self on https://github.com/Emmimal/context-compiler/.

The entire pipeline in a single determine: every go narrows the repository down by yet another diploma earlier than something reaches the mannequin. Picture by the writer, generated with gemini

A fast be aware on timing: on July 18, OpenAI quietly dropped the default context window for Codex fashions from 372k all the way down to 272k tokens. Billing correction or functionality trim, it factors to the identical actuality: you don’t personal the context window measurement. You solely management what you feed into it.

Context Compilation Is Not Context Engineering, Simply As soon as

In 2025, Andrej Karpathy coined “context engineering” to explain the general work of deciding what goes right into a mannequin’s immediate. Context compilation is only one particular software of that idea for supply code. Given a recognized codebase and a file you need to edit, it figures out which recordsdata that edit really depends on, then shrinks the whole lot else all the way down to the smallest usable type. That’s so far as this mission goes. I’m assuming you already understand how context administration differs from fundamental immediate engineering or retrieval, so I received’t rehash all of that right here. Let’s get proper into how the compiler really works.

Go 1: Image Decision

Go 1 solutions one fundamental query: ranging from the file you’re modifying, what else within the repo really issues? It traces express imports first. If a name like .save() can’t be defined by an import, it falls again to checking a repo-wide image desk, increasing outward breadth-first as much as a set hop restrict.

Right here is the precise output captured from a run towards a small take a look at repository designed to hit edge instances:

Goal: appviews.py
Reachable recordsdata (3):
  hop 1: appservices.py
  hop 1: appmodels.py
  hop 1: appmodels_order.py

Dynamic dispatch flagged in: [WindowsPath('app/views.py')]
Occasion-decorator hints flagged in: {WindowsPath('app/providers.py'): {'receiver'}}
Identify collisions: {'save': [WindowsPath('app/models.py'), WindowsPath('app/models_order.py')]}
  apphandlershandler_email.py: MISSED (as anticipated) -- getattr() dispatch is invisible to static evaluation
  apphandlershandler_sms.py: MISSED (as anticipated) -- getattr() dispatch is invisible to static evaluation

providers.py and fashions.py have been pulled in via express imports. models_order.py got here in by way of bare-name decision as a result of consumer.save() and Order.save() share a technique title {that a} easy resolver can’t separate with out a sort checker.

Discover what was neglected: the 2 handler recordsdata. They’re solely invoked by way of getattr() at runtime, which static evaluation can’t see. Excluding them is the proper habits. A device that makes a wild guess right here passes an incorrect dependency graph to the mannequin. Reporting an unknown is at all times higher than making issues up.

Two mechanisms drive this output:

  1. An ordinary module index. Each Python file maps to its importable dotted path (like app/fashions.py turning into app.fashions). Importing resolves via a quick dictionary lookup as an alternative of guessing towards the filesystem.
  2. A logo map fallback. When an import doesn’t clarify a name, the compiler checks a desk of each operate and sophistication definition throughout the repo to seek out the place it lives.

Traversing that is strictly breadth-first. Every part found at hop 1 will get parsed for its personal calls to construct the hop 2 frontier. Recordsdata are tracked so every one is visited as soon as, stopping when the hop restrict is reached or there may be nothing left to scan.

Go 2: Interface Extraction

Go 2 handles recordsdata which are reachable however are usually not the file you’re modifying. It strips them down to reveal interfaces, protecting operate signatures and docstrings whereas changing each operate physique with a single placeholder.

Here’s a actual before-and-after output from a run:

Authentic: 448 chars | Skeleton: 173 chars | 1 operate physique stripped

class PaymentProcessor:
    """Handles fee seize."""

    def cost(self, quantity, forex='USD'):
        """Cost a card for `quantity` in `forex`."""
        ...

That cuts this class down by 61% whereas leaving the signature, default values, and docstrings intact.

When an agent edits a file that calls cost(), it must know the tactic exists and what arguments it expects. It doesn’t want the inner implementation logic. Spending context window funds on these particulars for each dependency is exactly what this go cuts out.

Go 3: Context Meeting

Go 3 takes the output from the primary two passes, builds a three-tier context, and studies the precise token value:

Goal file: C:UsersAdminAppDataLocalTempcontext_compiler_demo_1jspidadappviews.py
Repo recordsdata scanned: 9
Tier 1 (full supply): 1 file
Tier 2 (skeletonized): 3 recordsdata
Tier 3 (excluded): 5 recordsdata
Naive full-dump estimate: 556 tokens
Compiled context: 362 tokens
Discount: 34.9%
Construct time: 12.45 ms
Warning: 1 file(s) use getattr()-based dynamic dispatch — targets could also be lacking from tier 2.
Warning: 1 file(s) use event-style decorators (e.g. @receiver) — handlers could also be lacking from tier 2.
Observe: 1 name title(s) resolved to a couple of file (name-only decision) — tier 2 might embody false positives.

Mapped onto the precise repository, these three tiers seem like this:

Code block diagram showing a Python repository file tree categorized into three context assembly tiers for LLMs: Tier 1 full source, Tier 2 skeleton code, and Tier 3 excluded files based on reachability.
Each file within the artificial take a look at repository, labeled with the tier Go 3 really assigned it, 1 file in Tier 1, 3 in Tier 2, 5 in Tier 3, matching the captured run above. Picture by the writer

The 34.9% token discount right here comes from the nine-file take a look at repo. It’s not meant to be a headline stat. The aim of this run is to point out how the compiler handles actual failure modes, flagging potential points explicitly within the terminal output moderately than hiding them in a log file.

The first knob you possibly can modify throughout all three passes is max_hops, which controls how far Go 1 expands.

max_hops What reaches Tier 2 Commerce-off
1 Direct imports and calls solely Smallest payload, however a secondary helper operate is likely to be missed.
2 Direct dependencies plus one layer out Balanced default used for all benchmark runs under.
3+ Wider transitive neighborhood Captures a bigger name graph, however financial savings diminish as depth grows.

All benchmarks within the subsequent part have been run with max_hops=2. This ought to be tuned based mostly on the duty: maintain it wider when exploring unfamiliar code, and tighten it down as soon as you recognize the native dependency construction.

Measuring the Compiler

Listed below are three separate benchmarks with three distinct functions, all pulled immediately from captured terminal output moderately than calculated estimates:

Repository Goal Recordsdata Naive tokens Compiled tokens Discount Construct time
Artificial take a look at repo Confirm edge instances explicitly 9 556 362 34.9% N/A
context-compiler (self) Reproducibility 7 9,379 2,867 69.4% 49 ms
loop-engine (exterior) Check generalization 12 13,254 3,404 74.3% 66 ms

The self-benchmark exists purely for reproducibility. You may clone the repo, run benchmark.py, and hit that precise 69.4% determine your self with out taking my phrase for it.

The loop-engine run is what really reveals generalization. It’s an exterior mission I didn’t contact whereas constructing the compiler, but the discount remained in the identical 70% ballpark regardless of a totally completely different import construction.

Check setting for each actual repo runs: Python 3.12, CPU solely, Home windows 11, customary library solely, with max_hops=2. Finish-to-end compile occasions ranged from roughly 43 to 73 milliseconds throughout repeated runs on each repositories, utilizing benchmark.py immediately. Token counts use a typical characters // 4 estimate, so deal with the relative percentages moderately than the precise token numbers.

To be clear: a naive full-repo dump is an higher certain, not essentially what trendy agent instruments do. Options like Aider’s repo map, Cursor’s context choice, and Claude Code already carry out some type of file filtering.

The extra correct comparability is towards a flat repo map that skeletonizes each file with out checking reachability. That’s the place three-tier meeting makes a distinction. A flat repo map nonetheless pays a token value for each single file within the workspace. This compiler pays zero for something the resolver marks as unreachable.

Within the loop-engine run, 9 out of 12 recordsdata have been excluded solely moderately than skeletonized. A flat repo map can’t shut that hole.

I’ve not benchmarked this on huge monorepos with tons of of recordsdata, so I’m not making claims about efficiency at that scale. Multi-file Python tasks within the tens-of-files vary characterize the precise examined scope right here.

Who Ought to Truly Attain for This

Now that the numbers are out of the best way, right here is the place this device really is sensible to make use of.

That is price including to your setup if:

  • You run multi-file agent duties the place many of the repo is irrelevant to the lively edit.
  • It’s worthwhile to keep strictly inside a decent context funds.
  • Your agent must know that exterior strategies exist with out burning tokens on their full implementations.

Skip it for single-file scripts. A easy file dump is already low-cost sufficient that compilation doesn’t matter there.

Skip it for codebases that rely closely on dynamic dispatch or occasion buses with out static registries. That’s the place static evaluation falls brief.

And skip it, at the very least proper now, in case your repository is so giant that constructing the module index on each run causes a noticeable bottleneck. I break down that constraint within the trade-offs part under moderately than ignoring it.

A easy sanity verify: in case your agent failed lately as a result of it obtained overwhelmed by unrelated code in its context window, this layer immediately solves that downside. If it failed due to obscure directions, this won’t enable you to. That’s nonetheless a immediate engineering downside.

The place Compilation Fails

Resolving calls by title as an alternative of by sort creates three particular blind spots, all seen within the Go 1 output proven earlier:

  • Dynamic dispatch. Within the take a look at repository, dispatch_handler() finds its goal utilizing importlib.import_module() and getattr() with runtime f-strings. The compiler excludes each vacation spot recordsdata and flags them explicitly moderately than guessing. Reporting an unknown is healthier than offering a mistaken dependency graph.
  • Occasion-driven registration. Features adorned with patterns like @receiver fireplace at runtime with out direct imports or express calls from the lively file. The resolver flags frequent event-decorator names as hints moderately than resolved dependencies, since static evaluation can’t verify reachability.
  • Identify collisions. Resolving by naked technique title means consumer.save() and Order.save() look equivalent when trying to find .save(). Each recordsdata get pulled into Tier 2. This doesn’t break the output, however it inflates token rely with an additional interface skeleton. That may be a protected route to fail in in comparison with dropping crucial code.

These trade-offs are intentional: velocity and nil dependencies over a full type-aware name graph. Codebases that favor express imports over string-based plugin loading, and preserve express registries for occasions, make these blind spots traceable once more. That’s customary observe for human builders utilizing fundamental reference searches, and it seems to matter for a similar causes when the reader is an agent.

To place this concretely: if an agent traces a bug via a middleware layer that dispatches handlers by string title, it receives an express warning, a flagged getattr() name, and two excluded handler recordsdata. It doesn’t get an accurate handler by luck or a mistaken handler delivered with false confidence. The output tells you or the agent exactly the place static evaluation stopped, so no person spends time chasing dangerous context.

That’s the core design selection right here: an incomplete map with express warnings is way extra helpful than a whole map that’s secretly mistaken.

Engineering Commerce-offs

Each compiler design entails trade-offs. Right here is the place the present implementation makes compromises:

  • Setting max_hops=2 is empirical. It labored effectively throughout the take a look at repositories, however a codebase with deeper name chains would possibly want max_hops=3.
  • Identify-only name decision prioritizes velocity and ease. It runs in microseconds and requires zero exterior dependencies, however it causes the title collision points famous earlier. Including a full sort checker would repair these collisions, however it might destroy the “clone and run with customary Python” setup.
  • Token counts use characters // 4. This heuristic is okay for tough estimates, however it strays on dense code. Should you want precise counts, changing it with tiktoken in compiler.py takes one line.
  • The decorator record is hardcoded, and the module index rebuilds on each run. The occasion hints depend on a static record of frequent framework decorators, and ModuleIndex rescans the listing per execution. Each may very well be cached or made configurable later, however they weren’t blockers for this model.
  • Tiering is strictly binary. You get full supply for the edit goal, and skeletons for each different reachable file. A hop 1 dependency and a hop 2 dependency obtain equivalent therapy as soon as they clear the resolver. Treating all reachable dependencies the identical retains the logic straightforward to cause about, even when it sacrifices some nuance at greater hop limits.

Operating It Your self

Each quantity on this article might be verified regionally. You solely want Python 3.9 or greater:

git clone https://github.com/Emmimal/context-compiler.git
cd context-compiler
python demo.py

That command builds the artificial take a look at repo utilized in Go 1 and Go 2, runs the pipeline, and finishes with a benchmark towards the compiler’s personal codebase.

To run it towards your individual mission:

python benchmark.py /path/to/repo /path/to/repo/target_file.py --max-hops 2

Go the repo root as the primary argument, and the file you’re actively modifying because the second. That file will get full-source therapy whereas the whole lot reachable will get skeletonized. That is the precise command used to generate the benchmark outcomes above.

What’s Subsequent

A kind-aware resolver would repair the name-collision difficulty. A cached module index would velocity issues up on bigger repos. Swapping in a real tokenizer would give precise numbers as an alternative of estimates. None of those additions change the underlying premise, they simply prolong it.

Compilers don’t exist to make applications shorter. They make them executable by isolating what the following stage really requires. A context compiler doesn’t make a codebase smaller, however it makes passing that code to an LLM sensible by filtering for what really belongs within the immediate.

Context limits will maintain shifting on vendor schedules, generally rising and infrequently shrinking. Counting on compiler self-discipline as an alternative of context window measurement protects your workflow no matter what limits an API exposes. That design precept will outlast any single benchmark determine on this put up.

Supply code, runnable demos, and the CLI can be found on https://github.com/Emmimal/context-compiler/

References

[1] GitHub, openai/codex, PR #33972 “Backport refreshed bundled mannequin metadata to 0.144” (merged July 18, 2026). https://github.com/openai/codex/pull/33972

[2] Karpathy, A. (2025). Context Engineering. https://x.com/karpathy/status/1937902205765607626

[3] OpenAI. (2023). tiktoken: Quick BPE tokeniser to be used with OpenAI’s fashions. https://github.com/openai/tiktoken

[4] Aho, A., Lam, M., Sethi, R., & Ullman, J. (2006). Compilers: Ideas, Methods, and Instruments (2nd ed.). Addison-Wesley, supply of the pass-based, tiered intermediate-representation framing used all through this text.

Disclosure

All code on this article is authentic work, written and examined on Python 3.12, on Home windows 11 and Linux. Each benchmark and terminal output proven is from an actual, captured run of demo.py or benchmark.py, reproducible by cloning the repository linked above; nothing right here is calculated or estimated besides the place explicitly marked as a heuristic. I’ve no monetary relationship with OpenAI, Anthropic, Cursor, Aider, or some other device talked about on this article.

banner
Top Selling Multipurpose WP Theme

Converter

Top Selling Multipurpose WP Theme

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

banner
Top Selling Multipurpose WP Theme

Leave a Comment

banner
Top Selling Multipurpose WP Theme

Latest

Best selling

22000,00 $
16000,00 $
6500,00 $

Top rated

6500,00 $
22000,00 $
900000,00 $

Products

Knowledge Unleashed
Knowledge Unleashed

Welcome to Ivugangingo!

At Ivugangingo, we're passionate about delivering insightful content that empowers and informs our readers across a spectrum of crucial topics. Whether you're delving into the world of insurance, navigating the complexities of cryptocurrency, or seeking wellness tips in health and fitness, we've got you covered.