Join AI Startup School & learn to vibe code and get paying customers for your apps ⤵️
https://www.skool.com/ai-startup-school
—— MY APPS ——
📲 Stay up to date on AI with my app Tensor AI
- on iOS: https://apps.apple.com/us/app/ai-news-tensor-ai/id6746403746
- on Android: https://play.google.com/store/apps/details?id=app.tensorai.tensorai
—— MY CLASSES ——
🚀 Claude Code Masterclass: https://www.masterclaudecode.com/
- Use coupon code L1BDDRX3 for 20% off
—————
CONNECT WITH ME
📸 Instagram: https://www.instagram.com/theramjad/
👨💻 LinkedIn: https://www.linkedin.com/in/rayamjad/
🌍 My website/blog: https://www.rayamjad.com/
—————
Links Mentioned:
- Tweet: https://x.com/sidbidasaria/status/1948495478146167251
- Docs: https://docs.anthropic.com/en/docs/claude-code/sub-agents
Timestamps:
00:00 - Introduction
00:44 - Checking Your Claude Code Version
01:10 - What Are Subagents?
02:23 - How to Create a New Subagent
03:31 - Configuring Subagent Tools & Permissions
04:25 - Reviewing the Generated Agent File
05:52 - How to Use a Subagent
06:15 - Subagent Examples
07:44 - Chaining Subagents Together
12:35 - Advanced Subagent Workflow Example
14:22 - Conclusion
Okay, so about four hours ago, Claude Code released a brand new feature called Custom Subagents, and we'll be going over that in this video and all the things you can do with it. The docs are also linked down below, so you can either read them or you can watch this entire video because I'll be going over the docs. And basically, it's a somewhat formalized approach from what people have been doing so far. So for example, this person, about one month ago, they said that you can spawn different subagents in parallel by basically telling Claude Code to do that. But in reality, it just spawned different tasks in parallel and had them running in parallel. And other people have been having like an agents. md file in their codebase and then having different instances of Claude Code running within different terminals and then having the agents coordinate via the agents. md file. So this approach that Claude Code implemented is somewhat different from that, and we'll be going through that. Basically,
you want to make sure before getting started that you are on the right version of Claude Code because the Claude Code version that was committed four hours ago is 1. 0. 60, and it says you can create custom subagents for specialized tasks over here. So if you run claude --version, you can see I'm on the correct version over here, which is 1. 0. 60. And if I run claude, then I should be able to write /agents and then see manage agent configurations over here. So before
getting started with showing you what it's like to run them, we'll read through the documentation first. Basically, Anthropic describes these subagents as pre-configured AI personalities that Claude Code can delegate tasks to do. Each one has its own specific purpose and expertise area. It uses its own context window separate from the main conversation. Which can be quite powerful because when the main conversation gets too long, then the performance of Claude Code can degrade unless you then summarize the whole conversation or compact it. Can be configured with specific tools it's allowed to use, which can be quite powerful for having like read-only agents or agents that can only perform web search. Or like basically there's a list of tools and I'll be going through that later. Includes a custom system prompt that guides its behavior. And basically when it encounters a task when Claude Code the main, like thread, encounters a task that matches a subagent's expertise, then it delegates a task to a subagent to do instead. Which works independently and then returns the results. So it says that each subagent operates in its own context preventing pollution of the main conversation. Subagents can be fine-tuned with detailed instructions leading to higher success rates on designated tasks. Subagents can be reused across different projects and shared with your team, which can be powerful because you want to make sure that people are using the same subagents with the same rules in the same way on the same codebase. And they have flexible permissions as well, which we'll be going over. So the first thing you can do is you
can go to your codebase. So I have Claude Code running in this codebase. And then write /agents over here to get started. And then you can see we have the built-in general purpose like Claude Code agent. That's always available down here. And we can create a new agent. So if we press enter, then we can create it either in this particular project, in the. claude/agents, or we can create one which is on our whole system, which will be stored in our home system directory. So I'll create it in this project over here. And then you can either do it manually or you can generate with Claude, which is a recommended approach. And then you describe what your subagent should be able to do. So if you actually scroll down, Claude or Anthropic basically recommends that you start with Claude-generated agents. We recommend you generate your initial subagent with Claude and then iterate on it to make it personally yours. This approach gives you the best results, a solid foundation that you can customize to your specific needs. So we're going to start off with a Claude-generated subagent. And I'm basically going to have a performance analyzer subagent. So it should be able to look through the codebase and then find performance improvements throughout the codebase. So I can say performance analyzer subagent that looks through the codebase and finds areas for performance improvements. And then press enter. I'm sure you can do better prompts over time. And Claude Code gives you some examples. But they're usually quite simple. And
now I can decide which tools I want the agent to be able to access. If I just press continue, then it will be all tools. I can do read-only tools, edit tools, execution tools, MCP tools. And I can show all the individual tools over here. So task, bash, multi-edit, webfetch, websearch, and so forth. So because I want this agent to be a read-only agent and not to make edits itself, I'm going to select to read-only tools over here. Press enter. And now you can see all these tools which are read-only related are selected, which is glob, grep, ls, read, exit plan mode, and so forth. And then I'm going to press continue up here. And now the nice thing is you can choose a color for your agent as well if you like that. You can choose automatic color or you can choose a specific one. So when you have multiple agents running, basically like in this example over here, you can see that each agent runs with a different color. So that can be useful for, I don't know, like color tracking or something. I'm going to choose purple over here. And then you can see
it shows the agent file over here. It shows a description of the agent which tells Claude when to use the agent. And then it has a system prompt which is cut off over here. But we can press enter. And now in the folder over here, so this is the folder that I just made the agent in, we have the performance analyzer agent. And it says, use this agent, blah, blah, blah. These are tools available. It's color purple over here. And then there's a big system prompt. So we can just continue to use the agent and then make refinements to it later on when we observe its behavior and notice that we want to make it perform in a certain way or not to perform in another way. And then of course, you can commit this file as well to your GitHub repository and then have other people in your team be able to use the same subagents in this particular project. And actually it seems that project subagents are given higher priority when deciding which agent to use over user subagents. So I guess if Claude Code thinks that you can use two different subagents for one particular task, then it will always choose a project specific one. Anyways, this is a file format that we just saw earlier. If you omit the tools part, then all tools will be available. These are the list of tools that you can see. So if you go to the tools documentation over here, you can see all the tools that are available that you can type in and what exactly they do. And then scrolling down, you can then manage your subagents as well. So if I were to press exit over here and then write agents again, then I can see the list of subagents that I have for this particular project. And if I had like user level subagents, I'd be able to see those as well. And if I press enter, then I can view, edit, delete, or go back. Now the
way to explicitly invoke a subagent is to use a subagent name. So you can say use a performance analyzer subagent to suggest improvements to a project. Press enter over here, and then it will call the subagent. And now you can see I'll use the performance analyzer agent. And now you can see it uses purple over here, which means the subagent is ready. It's initializing. And then you can see all the tasks that it's doing over here. And I'll let it run the commands in the directory. And whilst we're waiting for that, we can see what else there is over here. So you can have,
say, a code reviewer subagent. There's an example over here. A debugger subagent. A data scientist subagent. And the nice thing about it is you can have different system prompts for each of your subagents. So you can really fine tune and control behavior rather than having, like, one big prompt and then, like, messing around with them. And they have some best practices over here, which is using Claude-generated agents. Also design-focused subagents. So it's better to have subagents with single, clear responsibilities rather than trying to make one subagent do everything. That's the whole point of having subagents because it makes it more predictable and it just has better performance as well. Write detailed prompts. Include specific instructions, examples, and constraints in your system prompts for each of the subagents. The more guidance you provide, the better the subagent will perform. So I think this can be quite nice because over time, like, in the next few days and weeks, we will see people sharing subagents that they made for particular use cases. And then you can copy their system prompts over to your project if it needs to be. Limit tool access. Only grant tools necessary for the subagent's purpose. This will improve security and help the subagent focus on relevant actions. Because often when you have more tools available to an agent in general, or especially when you see, like, MCP tools, some people have, like, 20-30 MCP tools for their particular project. And the performance really degrades the more tools that you have available because the agent, I guess, has more choices to make or more decisions to make. And then to also version control your subagents as well. So your team can benefit and then also improve them collaboratively. Which means basically committing your subagents to GitHub. And one of the nice things you can do is you can chain subagents together.
So I'll go through an example of that shortly. And I guess over here where it says dynamic subagent selection, you can have your subagent implicitly called if you make sure your description feels are, like, specific and action-orientated. So the specific action-orientated, like, description that Claude Code generated for the subagent we made earlier is use this agent when you need to identify performance bottlenecks, optimization opportunities, and inefficient code patterns in your codebase. And then it gives some examples over here. And I'm not going to read through the whole thing. And it has some performance considerations over here. One of them being latency, because whenever you spawn a new subagent, it starts off with a clean slate each time. And it may need to, like, gather context about the codebase before being able to take any actions. So you want to bear that in mind. Because especially if you have your main thread running, it already has context about the codebase. When you spawn a subagent, it will, like, then gather the same context again. So we have the performance analyzer subagent that finished running over here. It took 3 minutes and 28 seconds. And used this many tokens. And it suggests some high-impact changes and also some quick wins. So we can actually make another subagent and chain them together. So I'll make two more subagents. And the first one will be being able to edit the codebase over here. So I'm going to call this... So I'm just going to call this optimizer subagent. And say, makes high-quality optimizations across a codebase whilst preserving intent. Press enter and have it generate the configuration for us. And I'm sure that over the next few days, as more people use this feature, they'll come out with better prompts about how you can make good subagents. And we're going to give it access to edit tools and execution tools over here. And I don't think MCPs would be necessary or other tools would be necessary over here. So we're just going to press continue. And then we will give it the color of pink. Actually cyan over here. And this is a file that it generated for us. So we can also read the file in our codebase. And let's make one more subagent, which is our release notes subagent. So this will write high-quality release notes based on the changes that were made since the last commit. So I'll press enter over here. And then have this subagent generated too. And we'll give it read-only tools because sometimes Claude Code or Claude for Sonnet can get overenthusiastic. And despite you telling it to only read, it can make some changes. So you don't want to give it more tools than necessary, as Anthropic says. So we're going to press continue over here after selecting read-only tools. And then make it green. And it made another agent file. And we'll press enter. And now we have a performance analyzer, code optimizer, and a release-notes-generator. If we go back to cursor over here, we can see we have the agent files over here. We have their system prompts. And over time, we can make improvements on these subagents as we want to change their behavior. So for example, in this release notes generator, we can basically give it a structure about how it should be able to write the release notes. So now I'm going to chain the three agents together by saying, can you analyze the performance of the codebase? Then make optimizations. And finally, write release notes for me in Markdown, all using subagents. And then press enter. And I think given that I did not give the release-notes-generator subagent the ability to edit files or create files, it will just give me the markdown in the terminal itself. So you can see it made a set of todos over here. It made the performance analyzer subagent, the code optimizer subagent, and the release-notes-generator subagent over here. So unfortunately, it decided to run all three of the agents in parallel. And I don't want that. So I'm going to have it run them one by one instead. So I'll just give it the same command, run them one by one. So it says it'll do the performance analysis first over here. And it's analyzing the performance. And this is much better than last time because, well, running all three of the agents in parallel or subagents in parallel would not yield a good performance because, like, it has to be run one by one for this particular task. But it's still nice to know that you can run different subagents in parallel with one another. And now you can see the performance analyzer subagent is done over here. And I think it passed whatever output or context it had onto the code optimizer subagent. So as we saw earlier, towards the beginning, where it says the performance analyzer has identified these critical bottlenecks and so forth, it would basically provide this output to the following subagent over here. So I wish I could see, like, what kind of thing was passed between chaining these subagents together. So you can see the code optimizer subagent completed all its to-dos over here. And it had 16 tool uses as well, which is quite interesting. But it's quite nice that each subagent has its own set of to-dos that I can keep track of. And that took about 3 minutes and 10 seconds to do. And now I think it should pass on to the final subagent, which is a release-notes-generator. And now you can see it made a set of release notes over here. So you may want to, like, change a system prompt for this particular subagent to improve the release notes. And it's interesting that it said, do you want to create a release notes. md file? Because a subagent should not have access to be able to write to a file. But we'll see what happens if we press yes. And it seems it did. I guess, like, by default, it just won't write to a file. Let me just double-check the subagent, actually, to make sure I did not give it those tools accidentally. And, oh, it actually seems that a release notes subagent can edit and do multi-edits. So I did not pay attention to that. But yeah, now it made a set of release notes and it made a bunch of improvements to the file. So basically,
the subagent chaining that we had over here is a performance analyzer, a code optimizer, and a release notes generator. And I imagine this feature will be getting more powerful in the future, and you can come up with subagents for your particular workflow. So, for example, you can have, like, a spec writer. So you can, like, have a subagent that helps you write out a spec, like, following some principles, whatever principles you may use for software design. And then you have another subagent that runs in parallel with an example finder. So the example finder goes online and finds example, like, high-quality code from GitHub or something, and maybe using some MCP tools. And you have a doc agent that uses something like Context7 over here to be able to find up-to-date documentation for whatever things are relevant to the spec. And then you have a coding. And then you have another set of subagents running in parallel. So you would have a README syncer that syncs any changes that were made by the coding subagent to your README. You'd have it generate some release notes. And then you may have an i18n translator. So many applications that are internationalized, they have, like, translation keys. And you may want to have a subagent that checks all the translation keys and then translates them and fills in any missing keys and so forth. And then you might want to make a subagent that just writes you some social media posts as well in a style that is applicable to you. So you might be posting on Twitter after you make this release and you want, like, 10 different draft tweets that you may write about this particular release that just happened. And you can have a subagent do that for you as well. And I've been seeing a lot more people using Claude Code for tasks that are not really relevant to coding and software engineering. So people have been using Claude Code to edit their Obsidian and do other things as well that are not coding-related. So it seems that Claude Code is just very powerful on its own. It, like, understands context well, executes it well. And these subagents and being able to come up with good subagent workflows will make it even more powerful over time. Anyways, because this feature is very new, not a lot of people have had a chance
to try it yet. But over the next week or so, people will, like, try it more and then share their thoughts and so forth. And I'm sure that there will be many powerful subagents and system prompts that people do share as well and their workflows. So in about a week or two weeks, I'll make another video where I share my own workflows and subagents and other ones that you can try in your own codebase. So basically, do subscribe for that content and I'll see you next time. Bye.