You type a prompt into Claude Code. Thirty seconds later, a test that was failing passed, the file was formatted, and your team got a message about it in Slack.
Here’s the interesting part: the model didn’t do any of that. Claude, the model, can only write text. It can’t open a file, run a command, or read your test output. Everything that actually touches your project is done by something else, something that sits between you and the model, reads your files, runs your commands, checks every action against your rules, and keeps looping until the job is done.
That something is called the harness. And once you see how it’s built, a lot of what feels like “the AI being smart” turns out to be well just engineering, well-designed loop with a handful of extension points around it.
This article walks through that loop, piece by piece, using one real example: fixing a failing test in auth.test.ts. It’s a companion to a longer video (coming soon) and an interactive visual I built, linked at the end.
The loop underneath Claude Code
Strip away every feature, and Claude Code is one loop, repeated:
Build context. The harness assembles a system prompt, the list of tools Claude can use, your CLAUDE.md file, and your message.
The model decides. It reads all of that and replies, either with plain text, or with a request to use a tool.
Permission check. Before anything runs, the harness checks whether that tool call is allowed.
The tool runs. Read a file, run a command, edit code, against your real project.
The result goes back into context. And the loop repeats from step 2.
The turn only ends when the model replies with text instead of another tool call. Let’s cover the end-to-end flow with an example prompt and see how it works visually. Before we do that though..
Want to actually build a harness?
I’m running a live, 60-minute session on this exact topic: Build an Agent Harness Like Claude Code, October 20, 2026, 11:00 AM.
We’ll go past “here’s how it works” and into reverse-engineering the harness so you can build one for your own product. We’ll trace exactly how a prompt turns into context and tool calls, and why the loop only ends when the model stops asking. We’ll use permissions and hooks to block risky actions, and decide what loads every turn versus only on demand. And by the end, you’ll have a working model of Claude Code’s harness you can adapt for whatever you’re building.
Most teams build this layer from scratch and learn its failure modes in production. Claude Code is one you can inspect step by step first.



