April 16, 2025

Some Cool Things I Learned about How AI Coding Agents Work

While building AI coding tools, I discovered some clever tricks that popular coding agents use to understand your codebase instantly. It turns out they're doing some interesting things with system prompts and context windows behind the scenes. Here's what I learned about how they work and why it matters for building better developer tools.

CW

Chris Wood

Founder of qckfx

I've been spending a lot of time lately looking into how AI coding agents work under the hood. While building and testing these systems, I've come across some interesting patterns that I thought would be worth sharing, particularly around how system prompts work.

How Context Windows Work

Let me start with the basics. Every LLM-based coding agent has what we call a context window. It's pretty simple - there's a space for system messages (the instructions that tell the AI what to do) and then space for the back-and-forth conversation between the user and the AI. When you use tools, that gets added to the conversation too - the AI makes a tool call, gets back a result, and that all goes into the message history.

A Neat Trick from Claude Code

Here's something interesting I noticed while working with Claude Code. Try this: open it in a repo where you haven't set up a CLAUDE.md file yet, and ask it what files are in your top-level directory. Don't tell it to use any tools - just ask.

It can tell you right away! But how? Well, it turns out it's running a quick script to map your directory and putting that info right into the system prompt. It's a pretty efficient approach - you can map over 450 files in about 1-2 seconds.

How the System Prompts Are Organized

Anthropic's setup lets you stack multiple system prompts, which is pretty handy. They've got:

  • Basic instructions about what the agent does (this never changes)
  • A map of your files (gets set once when you start)
  • Contents of CLAUDE.md (updates when you change the file)
  • Git info about your repo

This setup helps keep things fast and efficient - the stuff that doesn't change stays cached, and only the parts that need updating get refreshed.

A diagram showing a layer cake of system prompts with basic instructions at the top, followed by a directory map, memory, and git state. There's an indication that the top prompts change infrequently and the bottom prompts change more frequently.

The Interesting Part About Context

Here's what I find really cool about all this: nothing in the context window has to stay the same. You can swap things in and out as needed, kind of like how your computer manages RAM. It's a simple idea, but it opens up a lot of possibilities for how these agents can work with your code.

What I'm Working On

I've been putting these ideas to use in qckfx, an open source project I'm building. We're working on a set of developer tools, and our first focus is making an autonomous bug fixer. The goal is pretty straightforward - we want it to be able to spot bugs, figure out what's wrong, and fix them without needing much input from you.

If you're interested in checking it out or maybe contributing some ideas, you can find the project on GitHub or reach out to me on Twitter @c_h_wood.

Stay Updated

Subscribe to receive new blog posts directly in your inbox.