3 must-have tools for a leaner AI agent context

Three tools that cut token spend and keep your coding agent focused - output compression, context compression and long-lasting memory

Updated 5 min read

Every session starts from zero

Every new session starts with an empty context. Whatever the agent needs to know about your project, it has to go and find out - read files, run commands, grep through the codebase. Each of these errands costs input and output tokens and each of them stays in the context for the rest of the conversation.

Newer models get smarter, but they also get pricier. Running them on autopilot, without any consideration for what goes in the context window, can become expensive very quickly.

This article explores three tools that I consider a must-have for local dev with AI agents like Claude Code - rtk(opens in new tab), headroom(opens in new tab) and mempalace(opens in new tab).

Spending tokens where they matter

In the last several months I’ve been working on personal and professional projects and studying (even created a micro-website to compile learning materials(opens in new tab)), which caused my blogging to lag behind. I started a few articles that never saw the light of day, and trying to finish them kept me from writing anything new.

After a couple of months off, I’m getting back to writing, and the topic that has been on my mind the most is token efficiency.

There are three layers where the noise piles up in my day-to-day work:

  • Shell output - git status, ls, test runners and linters dump hundreds of lines, of which the agent needs a handful
  • Context - tool results, file reads and large payloads get sent to the model over and over again
  • Memory - every new session re-discovers what the previous one already knew, including the reasons behind decisions

Each of the tools below addresses one of these layers.

When the shell says too much

Terminal output is written for people skimming a screen, not for a model that pays for every token. rtk (Rust Token Killer) bridges that gap.

The idea is simple. When Claude Code runs git status, it doesn’t need the full output with hints on how to unstage files, it needs to know what’s changed. rtk gets it there by grouping, truncating and deduplicating the output.

Installing it takes a minute:

sh
brew install rtk
rtk init -g

The init command installs a Claude Code hook that transparently rewrites commands, so git status becomes rtk git status without the agent being aware of it. Integrations for Gemini CLI, Codex, Cursor and others are available as well.

My favourite part is rtk gain - it shows how many tokens you’ve actually saved. Here are my numbers at the time of writing:

sh
Total commands:    1052
Tokens saved:      446.7K (55.7%)

Not quite the advertised 60-90%, but still more than half of my shell output never made it to the model. There’s also rtk discover, which goes through your Claude Code history and finds commands that could have been optimised, but weren’t.

Making room in the context window

Once the shell is quiet, the next source of bloat is the traffic itself - this is where headroom comes in.

In proxy mode, you run it locally and point your client to it, instead of the provider:

sh
headroom proxy
OPENAI_BASE_URL=http://localhost:8787/v1 your-app

This works well with pretty much anything that talks to an OpenAI-compatible API - your own agents, scripts and self-hosted AI setups. It also comes with a dashboard, savings statistics and commands to inspect what has been compressed and how.

Remembering the why

When it comes to pure memory organisation, one project stands out - mempalace, released by Milla Jovovich(opens in new tab).

My git log and task tracker tell the agent what has been done, but not why things are built the way they are. Without that, the same decisions get re-explained every session, or the agent re-reads half the codebase to infer them.

Getting started:

sh
uv tool install mempalace
mempalace init ~/projects/myapp
mempalace mine ~/.claude/projects/ --mode convos

The last command mines your existing Claude Code sessions, so you don’t start from scratch. There’s also a Claude Code plugin in the repository’s marketplace, which is how I run it.

Leaner context, sharper agents

Each of these tools deals with a different kind of waste: rtk trims what commands return, headroom trims what gets sent and mempalace cuts down what has to be re-discovered. None of them is a silver bullet, but together they keep context windows lean and agents focused.

Keep in mind that these are young, fast-moving projects, so expect rough edges. Measure, don’t assume - both rtk and headroom give you the numbers.

For the rest of my setup, check out spec-driven development and devcontainers. If you’ve found other tools worth adding to the list, let me know in the comments. Happy coding!

Around this post

Links in this post · 5

Post history

Comments