Trick or Tokens: Five Monsters Eating Your Context Window

As we near Halloween here in the US, I wanted to give you some tricks for saving tokens when you develop with AI coding agents like Claude Code and GitHub Copilot. The treat is the tokens you’ll save.

Below are five monsters that eat your context window, each with the tricks that beat it.

Where Do the Tokens Go?

I recently ran rtk gain to see how much a little command-line tool called RTK has saved me. RTK sits between Claude Code and my shell and squeezes the output of commands like ls, grep, and git diff before the model ever sees it. Over 3,106 commands, it saved me 300,000 tokens. That’s 13.2%.

RTK's token savings summary: 3,106 commands, 300.0K tokens saved, 13.2% efficiency

The README says RTK “cuts up to 90% of the bash output your agent reads,” and it’s upfront that this isn’t the same as cutting your bill by 90%. Command output is only one place tokens go, and a tool like RTK can only squeeze what passes through it. The bigger savings come from changing how you work.

Why Fewer Tokens Means Better Output

Tokens aren’t only a billing problem. Every token in your context window is something the model has to weigh when it decides what to do next. A smaller context costs less, but it also means the model is more likely to remember the instructions you care about (which I wrote about last month in Tell AI Everything Twice). The habits that save you tokens get you better output, too.

If you use Claude Code, run /context before you change anything. It draws a grid of what’s filling your context window, broken down by instruction files, tools, and conversation, so you can see which context-eating monsters you’re dealing with.

Claude Code's /context command showing a grid of context usage by category: system prompt, tools, memory files, skills, messages, and free space

So, let’s meet the monsters…

1. Zombie Conversations

A zombie conversation is the session that won’t die. A bug fix turns into some “while you’re in there” refactoring, then tests, then a question about the deploy pipeline, all in the same chat. Every new message drags that whole history along behind it: file contents from tasks you finished, test output from a bug that’s already fixed, and plans you dropped hours ago.

The model doesn’t remember anything between messages, because the API is stateless. Every time you send one, Claude Code sends your full conversation back to the model, and it sends it again each time the agent uses a tool, so a single message can mean many round trips. Prompt caching makes those repeats cheaper, but the model still reads the whole thing every time.

Bar chart: message 1 sends one message, message 2 sends two, and so on, until message 5 sends all five. Five messages in, the model has been sent 15 messages' worth of tokens.

The Trick: One Conversation per Task

When a task is done, clear the session (/clear in Claude Code) and start fresh. If you really need to keep going, compact it (/compact) so the model keeps a summary and drops the rest. Starting over feels like throwing away progress, but the progress is saved in your code and your commits.

Don’t wait for the window to fill up, either. Claude Code compacts on its own, but only when you approach the context limit, and Anthropic’s own best-practices guide says performance degrades as the context fills. A good rule of thumb is to compact at a natural stopping point once /context shows you past about 60%. Compacting earlier is cheaper, too, since /compact has to read everything it summarizes. And if you’ve corrected the agent twice on the same thing and it still has it wrong, the guide’s advice is to /clear and start over with a better prompt.

2. The Haunted Instruction File

Your agent loads your CLAUDE.md, AGENTS.md, or copilot-instructions.md into every session, on every request. That’s what makes it useful, and it’s also what makes it expensive.

Instruction files go wrong in two ways. First, they get big. The one in a project repo I’ve been working in lately is 4,762 words, which /context says comes to about 14,300 tokens on every request. Prompt caching makes that cheaper, but the model still has to read all of it every time.

Second, they go stale. That same file still describes infrastructure the project has moved off of, plus next steps from a proof of concept that’s long finished. The model can’t tell which instructions are out of date, so it has to guess which ones to follow.

The Trick: Keep It Short and Current

Hold on to the rules and guardrails, delete the project history (that’s what git is for), and put a reminder on your calendar to reread the file once a month, because nobody notices it going stale.

For anything you only need some of the time, use a skill. The agent only sees a skill’s short description until the skill is needed, and then it loads the rest. A typical skill costs a couple hundred tokens until it’s used. Good candidates include your release checklist or the steps for a database migration. Once a skill loads, it stays in context for the rest of the session, so keep skills lean too. Claude and GitHub Copilot both support the open Agent Skills standard.

In Claude Code, you can also split rules into files under .claude/rules/ and give each one a paths: list, so it only loads when the agent works on matching files. Rules for your backend don’t need to ride along while you fix CSS. Skip @ imports for this, though. They make a long file easier to organize, but the docs point out that imported files still load at launch.

CLAUDE.md              <- loads in every session
.claude/rules/
  backend.md           <- loads only when the agent works in backend/
  frontend.md          <- loads only when the agent works in frontend/

Each rule file says which paths it covers in its frontmatter:

---
paths:
  - "backend/**"
---
# Backend rules
- Validate input on every endpoint
- Use the shared error response format

3. Vampire Tools

Every MCP server you connect adds tools, and every tool has a definition that takes up context. They pile up fast, too: a server for your issue tracker, one for the browser, one for the database, each added for one task and never removed.

Claude Code now holds those definitions back until a tool gets used, so they cost almost nothing up front. Without that, the definitions alone can run to tens of thousands of tokens, and not every AI coding tool holds them back.

The Trick: Connect Only What You Need

Connect the servers this project needs and turn off the rest. You can always turn one back on. And when a command-line tool does the same job, like gh for GitHub, Claude Code’s cost guidance recommends it over the MCP server, because it uses less context.

4. The Blob That Ate Your Context

In the 1958 movie, the Blob grows by swallowing everything in its path. In your context window, the blob is tool output: a full test run with every stack trace, a 2,000-line build log, or an entire file read just to find one method. Every bit of it lands in your context, and it stays there until you clear the session.

RTK was built for this monster, and my numbers show where it helps. It saved 70 to 86% on ls and 57% on git diff, because those outputs are mostly noise. On file reads it saved about 5%. File reads were also by far my most common command (1,087 of them), so the bigger win there is reading less.

The Trick: Tell the Agent Where to Look

Asking the agent to “fix the rounding bug in CalculateTax in OrderService.cs” lets it read one method, while “fix the tax bug” sends it reading whole files to find the problem. Run the one failing test instead of the whole suite. When you paste in a log, paste the error and the twenty lines around it, not the whole thing. And if you want to try RTK, go in expecting something more like the 13% I experienced, not 90%. Either way, it’s worth it.

For a broad search across the codebase, hand the job to a subagent. It reads all those files in its own context and sends back just the answer, so the blob never reaches yours.

5. The Curse of the Do-Over

Rework usually costs more tokens than anything else on this list. When an agent builds the wrong thing, you pay for the first attempt and then pay again for the second. And unless you clear the session in between, the failed attempt stays in your context and gets sent along with every request after it.

The Trick: Plan Before You Build

Ask for a plan first (Claude Code has a plan mode for exactly this), read it, fix it, and only then let the agent write code. Reading a plan costs a few thousand tokens. Reading, rejecting, and redoing an implementation costs a whole lot more, plus the coffee you drank while you waited.

While you’re at it, use a different model for each of those two steps. Pick a big model like Opus 5.5 for the plan and for the nasty debugging. Once the plan is settled and it’s time to write code, switch to Sonnet 5.5 (/model in Claude Code), or to Haiku 4.5 for the small stuff. As of October 2026, Sonnet 5.5 costs half what Opus 5.5 does per token, and Haiku 4.5 costs a quarter. If you’re on a flat subscription instead of paying per token, you’ll usually feel the difference in how fast you hit your usage limits. GitHub Copilot and most other tools let you pick a model too, so the trick works no matter which tool you use.

Other Tools Worth a Look

RTK isn’t the only tool going after these monsters. Here are a few open-source options, RTK included, all under active development as of this writing:

ToolWhat it does
RTKCompresses shell command output before the agent reads it
CavemanA skill that makes the agent’s replies terse, plus a proxy that shrinks logs, test output, and diffs
HeadroomCompresses tool output, logs, and files before they reach the model
SerenaAn MCP server that lets the agent find and edit code by symbol instead of reading whole files
code-review-graphBuilds a map of your codebase so the agent knows which files it needs to read
ccusageReports your Claude Code token usage and cost from local logs, so you know where to look first

All but the last one attack the Blob, which makes sense, since it’s the easiest monster to fix with a tool. The other four are mostly about habits.

The tools work at different points, though. Caveman and Headroom are proxies: they run on your machine between your agent and the AI provider’s API, and they shrink the tool output inside each request before it goes out. RTK works one step earlier. It hooks into the shell commands your agent runs and compresses their output before the agent reads it. Serena and code-review-graph don’t compress anything; they give the agent better ways to find code, so it reads less in the first place. And ccusage only reads your local Claude Code logs after the fact.

Because a proxy sees every request, including your code, check where it runs before you point your agent at it. Caveman and Headroom both run locally.

Those are five monsters worth hunting down to save tokens and free up your context window.

Bringing These Habits to Your Team

Our engineers at Trailhead use GitHub Copilot, Claude, and Cursor every day, and habits like these are part of how we deliver work faster without giving up quality. When we build alongside a client’s developers, their team usually picks the habits up too.

If your team has adopted AI coding tools and the bills, or the results, aren’t what you hoped for, let’s talk. We can work next to your developers so the practices stick, or take the project on ourselves. You can also read more about how we use AI.

Picture of Jonathan "J." Tower

Jonathan "J." Tower

Jonathan, or J. as he's known to friends, is a founding partner of Trailhead Technology Partners, a custom software consulting company with employees across the U.S., Europe, and South America. He is Vice President of the .NET Foundation, a 13-time recipient of the Microsoft MVP award for his work with .NET and AI, and a frequent speaker at software conferences around the world. He doesn’t mind the travel, though, as it allows him to share what he's been learning and also gives him the chance to visit beautiful places like national parks—one of his passions. So far, he's visited 58 of the 63 U.S. national parks. J. is also passionate about building the software community. Over the years, he has served on several non-profit boards, including more than a decade as president of the board for Beer City Code, Western Michigan's largest professional software conference. Outside of work, J. enjoys hiking, reading, photography, and watching all the Best Picture nominees before the Oscars ceremony each year.

Free Consultation

Sign up for a FREE consultation with one of Trailhead's experts.

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Related Blog Posts

We hope you’ve found this to be helpful and are walking away with some new, useful insights. If you want to learn more, here are a couple of related articles that others also usually find to be interesting:

Our Gear Is Packed and We're Excited to Explore With You

Ready to come with us? 

Together, we can map your company’s software journey and start down the right trails. If you’re set to take the first step, simply fill out our contact form. We’ll be in touch quickly – and you’ll have a partner who is ready to help your company take the next step on its software journey. 

We can’t wait to hear from you! 

Main Contact

This field is for validation purposes and should be left unchanged.

Together, we can map your company’s tech journey and start down the trails. If you’re set to take the first step, simply fill out the form below. We’ll be in touch – and you’ll have a partner who cares about you and your company. 

We can’t wait to hear from you! 

Montage Portal

Montage Furniture Services provides furniture protection plans and claims processing services to a wide selection of furniture retailers and consumers.

Project Background

Montage was looking to build a new web portal for both Retailers and Consumers, which would integrate with Dynamics CRM and other legacy systems. The portal needed to be multi tenant and support branding and configuration for different Retailers. Trailhead architected the new Montage Platform, including the Portal and all of it’s back end integrations, did the UI/UX and then delivered the new system, along with enhancements to DevOps and processes.

Logistics

We’ve logged countless miles exploring the tech world. In doing so, we gained the experience that enables us to deliver your unique software and systems architecture needs. Our team of seasoned tech vets can provide you with:

Custom App and Software Development

We collaborate with you throughout the entire process because your customized tech should fit your needs, not just those of other clients.

Cloud and Mobile Applications

The modern world demands versatile technology, and this is exactly what your mobile and cloud-based apps will give you.

User Experience and Interface (UX/UI) Design

We want your end users to have optimal experiences with tech that is highly intuitive and responsive.

DevOps

This combination of Agile software development and IT operations provides you with high-quality software at reduced cost, time, and risk.

Trailhead stepped into a challenging project – building our new web architecture and redeveloping our portals at the same time the business was migrating from a legacy system to our new CRM solution. They were able to not only significantly improve our web development architecture but our development and deployment processes as well as the functionality and performance of our portals. The feedback from customers has been overwhelmingly positive. Trailhead has proven themselves to be a valuable partner.

– BOB DOERKSEN, Vice President of Technology Services
at Montage Furniture Services

Technologies Used

When you hit the trails, it is essential to bring appropriate gear. The same holds true for your digital technology needs. That’s why Trailhead builds custom solutions on trusted platforms like .NET, Angular, React, and Xamarin.

Expertise

We partner with businesses who need intuitive custom software, responsive mobile applications, and advanced cloud technologies. And our extensive experience in the tech field allows us to help you map out the right path for all your digital technology needs.

  • Project Management
  • Architecture
  • Web App Development
  • Cloud Development
  • DevOps
  • Process Improvements
  • Legacy System Integration
  • UI Design
  • Manual QA
  • Back end/API/Database development

We partner with businesses who need intuitive custom software, responsive mobile applications, and advanced cloud technologies. And our extensive experience in the tech field allows us to help you map out the right path for all your digital technology needs.

Our Gear Is Packed and We're Excited to Explore with You

Ready to come with us? 

Together, we can map your company’s tech journey and start down the trails. If you’re set to take the first step, simply fill out the contact form. We’ll be in touch – and you’ll have a partner who cares about you and your company. 

We can’t wait to hear from you! 

Thank you for reaching out.

You’ll be getting an email from our team shortly. If you need immediate assistance, please call (616) 371-1037.