Using Subagents to Improve Claude Code Results: A Step-by-Step Guide A developer shares a step-by-step guide for using subagents to improve results from Claude Code, emphasizing context window minimization and delegation of tasks to independent subagents to enhance coding agent performance. Unless you’ve been living under a rock, you’re well aware of AI agents like Claude Code and Codex revolutionizing software development. These tools are undoubtedly easy to learn, but are also hard to master. There are a ton of nuances and best-practices that can help you get much better results from your coding agent. As someone who can be an obsessive perfectionist, I’ve spent too many hours reading up on and experimenting in this area. There are a ton of abstract ideas floating out there which I’ve learnt a lot from. Ideas like spec-driven-development, RPI, etc. But I’ve also noticed a dearth of step-by-step guides that show someone how to actually implement these abstract ideas. Hence why I decided to write this blog post. Disclaimer: I just started using Claude Code six months ago, and am still learning these best practices as well. I’m sure this guide has tremendous room for improvement, and will also become woefully out-of-date in the near future when new models and agents come out. I would love to hear your ideas on how to improve upon my setup. Guiding Principles Before we get into the actual step-by-step guide, let’s briefly discuss the guiding principles behind each step, and why it enables your agent to produce better results. Understanding these principles will help you make better use of coding agents in your day-to-day work. Context Use Minimization Each session in a coding agent has a context window. Every time you send a prompt to the agent, every time the agent does anything, it uses up a bit more of this context window. This is eerily analogous to your own cognitive load while working on a task. Just like with your own cognitive load, coding agents perform far worse when their context window starts filling up https://medium.com/dare-to-be-better/smart-zone-dumb-zone-64500416a5e9 . Hence why you should always strive to keep your context window usage as low as possible. Of course, this is easier said than done. If you simply /clear your context window before every prompt, it will be like having a conversation with someone who doesn’t remember anything you said one minute ago. Agents need useful context in order to do a good job. So you need to find ways to minimize their usage of the context window, while still keeping the stuff that is important. One extremely simple application of this principle: always /clear your context window before starting work on a new unrelated task. This is a good start, but there is also a lot more you can do. Sub-Agents The next best thing you can do is to use subagents or independent agents – each of which has its own independent context window. And delegate chunks of work to each subagent. Imagine if you have a large codebase, and your agent needs to find all information relevant to fooBar . If your main agent simply starts grepping and reading your codebase in order to find the information it needs, it will rapidly start filling up its context window with a ton of useless information. This violates our earlier principle: we want to keep our context window usage as low as possible. To achieve our goal, we can instead spin up a subagent whose sole job is to find all information relevant to fooBar , and send this relevant information back to the main agent. This way, all the useless information will only bloat that subagent’s context window. And the only information that lands in the main agent’s context window is the filtered and highly relevant information that was surfaced by the subagent. This same principle can be applied not just to “codebase grepping”, but to the entire software development workflow. For any significantly sized work, instead of doing it all on a single agent, you will get better results if you break up the work into multiple chunks, and assign each chunk to a different subagent. Intermediate Artifacts Of course, there is a downside to dividing up work among numerous subagents – the risk of misinterpretation and information loss when agents are sending results to one another. Anyone who has played a game of telephone knows how dangerous this risk is. To mitigate this, it is helpful to have each agent output its result in a text file. This way, other agents can read the relevant file directly, instead of relying on second-hand or third-hand information. As a byproduct, these text files are also great for us humans to audit the work that each agent did, and root-cause the source of any errors. Fresh Perspectives It is tempting to think of AI agents as being consistent. After all, that’s how most computer systems operate. But AI agents are different. Give the same agent the same instructions on two different occasions, and it can produce two completely different results. Ask an AI agent to critique the results that it just spat out a minute ago, and it may tell you all the reasons why its own results are wrong. This can certainly be frustrating, but we can also harness this to our benefit. An agent may make a mistake when working on a task. But if you ask the agent to review its own work, there is a good chance that it will find its own mistake – just like humans double-checking their own work. We can even take this one step further. In another eerie resemblance to humans, an AI agent reviewing “its own” work is likely to be defensive and biased. But if you spin up a fresh subagent with a fresh context window, and tell it to review “a different agent’s results”, it is more likely to find any mistakes that were made earlier. Even if the subagent is using the exact same model and harness as the agent that made the mistake in the first place. This is yet another fantastic use-case for subagents – reviewing the work output of other agents. In the exact same way that most software teams mandate that PRs be reviewed by someone other than the original author. Checks and Balances Power corrupts. And apparently this is true for LLMs as well. AI agents are known to sometimes engage in “ reward hacking https://www.anthropic.com/research/emergent-misalignment-reward-hacking ” – a fancy term for cheating. They pretend to have rigorously accomplished the user’s request, when they actually took shortcuts or failed entirely. One way to mitigate this problem is to use independent AI agents/subagents for testing vs implementation vs verification. This way, the agent performing the implementation cannot cheat by writing non-comprehensive tests. This works surprisingly well even if these different subagents are all using the exact same model. As another side-bonus, it turns out that agents do a much better job of writing code when they have tests in place that can alert them when they have made a mistake. Even if those tests were themselves written by an AI agent as well. Putting It All Together Now that we have covered the theory behind agentic best practices, here is how I have attempted to implement these best practices. It all starts with my global CLAUDE.md configs, in ~/.claude/CLAUDE.md , where I added the following section: Development workflowAt the start of any task that will edit a codebase — before any exploration, planning, or edits — invoke the dev-workflow skill and follow every step of it.Main conversation only: dispatched subagents skip this and follow their dispatch prompt instead. Preserving top-level contextKeep the top-level conversation's context window as small as possible — I value a long-lived, coherent root thread over token/$ cost. Delegate context-heavy or tool-heavy work broad searches, multi-file reads, command output, exploration to subagents that return only distilled summaries, never raw output. Higher cost from this delegation is acceptable. Exception: a single trivial call e.g. reading one small file may run in-root when spinning up a subagent would cost more overhead than it saves. Which points at the following skill which you should place in ~/.claude/skills/dev-workflow/SKILL.md : ---name: dev-workflowdescription: The mandatory 13-step development workflow research → plan → tests → implement → review loop → verify → docs for any task that edits a codebase. Invoke at the START of such a task, before any exploration, planning, or code edits — the workflow's research phase owns codebase exploration. Main-conversation orchestrator only; dispatched subagents must never invoke it.--- Development workflowWhenever making code changes, use the following workflow. Always follow every step Orchestrator only. This workflow is for the main conversation, which dispatches subagents per the steps below. If you are a dispatched subagent e.g. deep-explore, test-author, implementer, code-reviewer, code-review-judge, verifier, agent-docs-maintainer , do not follow this file — your dispatch prompt and agent definition own your job.Phase artifacts live in ~/.claude/thoughts/