Four Context Engineering Techniques That Cut LLM Costs by 90%
Watch on TikTok
Context engineering is about controlling exactly which tokens reach your LLM. This video walks through four specific techniques that reduce token counts dramatically without losing the information your model actually needs.
Technique 1: Compress Statistically, Keep Anomalies
Start with a hundred log entries totaling 19,000 characters. Ninety-nine of them say "status info, everything is normal." One, buried at position 67, is a fatal error: database crashed. Your LLM needs that one line, not the other 99.
The compression logic: keep the first three entries for structural context, keep the last two for recency, scan for anything containing "error," "warning," or "fatal" and always preserve those, then find statistical outliers where values spike above normal.

Result: six entries, 1,100 characters. The fatal error at position 67 is still there. That is a 94% reduction with zero information loss.

Technique 2: Factor Out Repeated Fields
You have 2,000 files from a code search. Every single one includes type: file and language: python repeated in its metadata. That is the same two fields written 2,000 times.
Factor out the constants. Mention type: file and language: python once at the top in a _constants object, then list just the file names. Thousands of tokens saved on pure repetition.

Technique 3: Stabilize Your Prompt Prefix
Your system prompt says "You are a helpful assistant. Today is January 28th, 2025." Tomorrow it says January 29th. The beginning of your prompt changed by one word. Cache broken. Full reprice.
Move the date to the end of your prompt. The beginning stays identical every day. Anthropic gives 90% off cached tokens. OpenAI gives 50% off. Same prompt, large savings, just by reordering.
Technique 4: Cache Before You Compress
You compressed 1,000 files down to 15. The user asks about a JWT authentication file. It was not in your top 15. Normally you would say "I don't have that anymore."
Instead: before compressing, save the original 1,000 files in a local cache. Give your LLM a retrieval tool. When the user asks about JWT, the model calls that tool, searches the local cache, and pulls back the file. Nothing is ever lost.

You can compress aggressively because retrieval is always possible.
Key Takeaways
- Compress logs and data statistically while preserving anomalies, errors, and outliers
- Factor out repeated metadata fields into a single constants block
- Keep the beginning of your system prompt stable to maximize cache hit rates
- Always cache original data before compressing so the LLM can retrieve anything on demand
Resources
- the_enterprise.ai school community -- Full breakdown of these techniques (link in bio)
Published May 25, 2026. Writeup generated from a favorited TikTok.