Commands vs Skills vs Subagents0:08
All right, next step is Claude Subagents. But before we even get started, I think this can get a little confusing. You'll learn about commands. Fine. I got it. And then you'll learn about skills and you think, okay, I kind of get it. But then subagents come in and you're like, well, you know what? There's a little bit of overlap between these three. When would I use a command versus a skill versus a subagent?
There's a little bit of overlap between these three. When would I use a command versus a skill versus a subagent? It can definitely get a little bit confusing. All right, so let's go over it really, really quick. Your recap. A command is like a trigger, and the, the closest correlation I can think of is like an artisan command. If you're building a Laravel app, it's, it's something you trigger. Do this thing. Cool, we got that down next, a skill
it's something you trigger. Do this thing. Cool, we got that down next, a skill is a, a guidebook. It's a field guide. This is the way we go about doing things. When I ask you to do this, well, these are the steps that I want you to follow. So notice the difference there. I'm not telling it to do that thing. I'm saying when,
I'm not telling it to do that thing. I'm saying when, and if you need to do that thing, here's your field guide that you can look through to determine how we want it done. Got it. But now, subagents are a little bit tricky because they're sort of like commands, except they happen in isolation without clogging up the current context window. And there's definitely benefits to that. Alright, so if it helps, this is
Why Subagents Use Isolation1:23
And there's definitely benefits to that. Alright, so if it helps, this is how my dumb brain thinks of it. Uh, there are analogous to, to throwing something onto a queue. Think about it. If I throw a job onto a Laravel queue, what happens? Well, it's a way to say, uh, let's do this in the background so that I can return a response as quickly as possible. Well, subagents are a little bit like that,
so that I can return a response as quickly as possible. Well, subagents are a little bit like that, but it does have the benefit that when we spin up a subagent, it, it does all this work. It figures out what it needs to do, but it doesn't clog up the current context, the current chat. Think about it. What if AI decides it needs to figure out the answer to something, but that's gonna take two or three minutes
to figure out the answer to something, but that's gonna take two or three minutes and it's gonna ask itself all of these questions. Now I need to run this query. Now I need to go here. Now I need to do this. And you just blow it up the current context to figure out the answer to this one thing, right? Well, you could take that synchronous manual bloy approach, or instead you could spin up a subagent where you just push it off into isolation.
Creating a Code Review Agent2:21
or instead you could spin up a subagent where you just push it off into isolation. It has its own context. It figures out the answer, and then it returns a response to the main context. And then we can continue on. That's how I think of this. And maybe that helps. I'm gonna show you some examples. Now, Let's bring up the terminal and boot up Claude full screen. I'm gonna run the agent's command to create a new agent.
and boot up Claude full screen. I'm gonna run the agent's command to create a new agent. At the moment, we have none. All right, let's create one for this project. And we're gonna have, uh, claw generated. So we're basically gonna provide a prompt, and then it will, it will jumpstart this markdown file for us. All right? So I wanna create a new agent, uh, for code reviewing.
All right? So I wanna create a new agent, uh, for code reviewing. Uh, this is a common example, but actually I find it to be incredibly helpful for all of my projects. Act as a senior Laravel engineer and provide a comprehensive code review for any changed, um, GIT files or files and gi All right. That should be enough to get us started.
and gi All right. That should be enough to get us started. So yeah, it's just gonna use that as a prompt to, to build up the markdown file. And as you'll find out whether it's a command or a skill or an agent, it's still just a markdown file, which is, which is wild. Alright, next, what tools should it have, uh, access to? You might wanna start with just all tools. What model do you want it to use?
You might wanna start with just all tools. What model do you want it to use? I kind of use Opus for everything at the time of this recording. That's the best one. Next, what color do we want? Why don't we use yellow to represent a code review like warning? I'm gonna go over this, don't proceed. Don't push it yet. And here it is. So let's save it. And we now have an agent. Let's take a look. If I switch to full screen
And here it is. So let's save it. And we now have an agent. Let's take a look. If I switch to full screen and we bring up the sidebar, you'll now see a new Claude directory and here is our code reviewer. Alright, so notice once again, uh, we have a description, and this is very important. Use this agent when you need a comprehensive code review of recently changed files and git. This includes after completing a feature, fixing a blog. Yeah, it, it, it, it encompasses everything.
This includes after completing a feature, fixing a blog. Yeah, it, it, it, it encompasses everything. Um, you might want to add there. And you could even do something like, you must use this agent when you need a comprehensive code review. Sometimes little keywords like that actually activate it, which is really funny. All right, so let's have a look. You're a senior Laravel developer with 10 plus years of experience.
All right, so let's have a look. You're a senior Laravel developer with 10 plus years of experience. You have deep expertise. Here is your process. So you're gonna figure out, so again, notice it's kind of like an instruction. It's almost like a command. And we'll figure out how we might merge, uh, commands and agents in just a little bit. But yeah, figure out what changed, look at the files and then apply a review criteria using,
But yeah, figure out what changed, look at the files and then apply a review criteria using, uh, what you see here. And yet your job would be to go through this and pluck whatever you want to keep and get rid of whatever you don't. Um, so for example, some things I might do is like, uh, if you're a big advocate for type safety, then you'll wanna make sure you have a note here. And remember, maybe it adds it here, maybe it doesn't.
then you'll wanna make sure you have a note here. And remember, maybe it adds it here, maybe it doesn't. That's the way AI works. If it's not there and you're a big proponent of type safety, then include it there, right? Um, instructions review. Again, notice this is dynamic based upon my project here. Testing. We might even add a section here. Like, um, let's say finalize, um, you must, must run the finalize cloud command
Like, um, let's say finalize, um, you must, must run the finalize cloud command to confirm formatting and test suite passes. Okay? And that's part of the code review. Like does this actually work? Does it meet our style guide? Do all the tests pass? Sometimes, by the way, it helps if I scroll up, um, we'll say guidelines and, um, ensure that guidelines, um, from Claude MD are properly followed.
and, um, ensure that guidelines, um, from Claude MD are properly followed. Yeah, so ideally it should have done this already, but as you've probably experienced, sometimes it just seems like it will skip over a section where it's like I said in, in my guideline not to do this, but you still did it. So wherever you can, you want to further emphasize these things. So as part of our code review agent, we can say, yeah,
to further emphasize these things. So as part of our code review agent, we can say, yeah, just take a look at the guidelines and make sure that this adheres to it. So even if we're somewhat redundant, that's okay. And then at the very bottom, you might ask for some suggestions. Yeah, optional and enhancements and nice to haves. Alright, so here's the checklist. This is very nicely formatted if maybe a bit
Alright, so here's the checklist. This is very nicely formatted if maybe a bit more verbose than it needs to be. Final steps after reviewing all files. Yeah, we're gonna get rid of this entirely and that's good enough to get us going. Okay? So now we have an agent, uh, we have some guidelines or some, um, uh, hints as to when this agent should be deferred to, but of course you can also just tell, uh, Claude
to when this agent should be deferred to, but of course you can also just tell, uh, Claude to use this agent. So let, let's use an example here. Yeah, this is easy enough to understand. Alright, so we have this index action and you can see we fetch all of the chat messages for the current user and we return them as a, um, API resource collection. Okay? But imagine we're working on this
and we return them as a, um, API resource collection. Okay? But imagine we're working on this and maybe at one point we accidentally change the visibility and then maybe we decide, you know what, let's extract this into a messages variable length like this and that looks good and maybe we do some other things. But here's the thing. One issue is that this is the wrong visibility and we want our code reviewer to figure that out.
One issue is that this is the wrong visibility and we want our code reviewer to figure that out. And then next, maybe one of our guidelines is that we avoid using the helper functions. Instead we prefer the dedicated facades. So I actually wanna see off user rather than, uh, the helper function one's not necessarily better than the other, they're effectively identical, but pick one and stick with it, right? So nonetheless, our code reviewer should pick up on this.
Testing Agent With Guidelines8:19
but pick one and stick with it, right? So nonetheless, our code reviewer should pick up on this. So here's what we can do. I'm gonna go into my Laravel dot MD guidelines file and let's add a note about how we want it to handle facades. Okay? So we could say always favor, uh, Laravel facades over the helper function equivalence. And I always wanna give it an example. So I could say example, and let's see if it can do it for us.
So I could say example, and let's see if it can do it for us. Route get, ah, let's do something like this. Um, example, off user, over the helper function. Yeah, simple enough. So I am using Laravel Boost in this case, so I'm going to regenerate my guidelines file PHB Artisan boost install. Alright, that's done. So now think about it.
PHB Artisan boost install. Alright, that's done. So now think about it. We have some guidelines here. We have a code reviewer. Part of that code review, uh, instructs it to ensure that our guidelines are being followed, followed properly. So now why don't we test it out? So let's do the terminal instead. If I run get status, we can see that chat controller that we worked on. All right, let's boot up Claude.
that chat controller that we worked on. All right, let's boot up Claude. And this time I'm going to explicitly trigger it, but of course one of the benefits is that these agents can be treated almost like event listeners. When you get to this point, then I want you to in isolation, run this agent, okay? Run the code reviewer subagent to review any changed files
Run the code reviewer subagent to review any changed files and get, all right? And that is reasonably fast. So let's take a look at the code review. Uh, protected method breaks routing. Good job. It picked up on that, it's missing a return type. It noticed that our guidelines are not being followed and it's suggesting that maybe we should, uh, extract a dedicated form request class.
and it's suggesting that maybe we should, uh, extract a dedicated form request class. Uh, and maybe that's declared by Laravel Boost, but I don't think it's necessarily, uh, paramount. Let's say fix one and two from your list. All right? And that's fixed. Very cool. But here's one other thing we could do as well. So here we have just one agent, but of course you could create more if you want. But yeah, if you look at it, it's sort
Combining Subagent and Command10:36
but of course you could create more if you want. But yeah, if you look at it, it's sort of like a command, right? And that's where there's a little bit of overlap. So here's one thing that might be cool. What if we made this available as a sub agent but also a command? Here's what we might do. I'm gonna select all of this, remove it and create a new command code review.md.
I'm gonna select all of this, remove it and create a new command code review.md. Our description will be perform a code review on changed files, and I'm gonna paste all of that in right here. Okay? So now if I did nothing else, I can trigger this as a command. Lemme show you, bring up the terminal, Claude, and if I run code review, there it is. Cool. So now what we could do is on our subagent, we can simply have it defer to the command.
Cool. So now what we could do is on our subagent, we can simply have it defer to the command. We keep this one, but now I can say run the, uh, code review Claude command to begin the review. Cool. So now we have a sub agent that defers to an existing command. Perfect. So yeah. Now if I were to bring back our chat controller, I will undo it, bring it back to everything that we had before.
I will undo it, bring it back to everything that we had before. There we go. Now let's trigger it again. Claude code review and now it's going to perform that task, but of course it's going to happen inside of the current context window. Okay, good to know. Okay, so now here's some potential use cases that you might like. Keep in mind that Claude will defer to subagents
Running Multiple Subagents Concurrently12:06
so now here's some potential use cases that you might like. Keep in mind that Claude will defer to subagents as it deems necessary, right? So you don't constantly have to tell it to do so. However, sometimes it can be useful when you're brainstorming. For example, imagine you want to consider a new feature and you wanna see maybe two or three different implementations. Well, what you could do is tell your agents
or three different implementations. Well, what you could do is tell your agents to boot up three subagents that take different approaches so that you can then review and choose which approach you like the most. Or you can even have Claude do that, compare the results of three uh, approaches, and then choose the cleanest one, right? All of those would happen effectively, um, asynchronously or at the same time concurrently.
All of those would happen effectively, um, asynchronously or at the same time concurrently. Uh, and it, it's a cool way to go. You can even do this for design related stuff as well. Okay, let's try it out. And let's see. Uh, currently when messaging our telegram bot, a web hook is sent to the server that gets converted into a command and then a responses returned, right? I would like to build a dashboard
and then a responses returned, right? I would like to build a dashboard to monitor these interactions. I want you to spin up, uh, two sub-agents to plan out how this will be implemented. And then I'd like to review both to determine the best option. Also I'd like you to recommend which one, uh, seems to be the cleanest approach to you. All right, so I have plan mode turned on
to be the cleanest approach to you. All right, so I have plan mode turned on and in cloud code I can shift tab to choose plan mode and let's give it a run. So it's gonna first explore the code base and then it's gonna launch two plan agents with different approaches. Okay? So I fast forwarded, but take a look here. It's now running two plan agents concurrently. So we have one with a minimal dashboard approach,
It's now running two plan agents concurrently. So we have one with a minimal dashboard approach, and then we have another plan that's a bit more feature rich. And notice though, you are gonna be using more tokens, so be aware of that, but we can review the token usage for each, uh, as they run. As they run. Alright, here we go. So we had two plane agents run concurrently. Uh, let me summarize and provide recommendations.
So we had two plane agents run concurrently. Uh, let me summarize and provide recommendations. Yeah, this is very cool. Here's approach one using minimal blade or approach two with live wire, uh, recommendation approach. Number one, here are the benefits, but it would enhance it slightly with response time tracking from approach two. Yeah, very cool. So it's merging both of them slightly to make, uh, something even better, uh,
Yeah, very cool. So it's merging both of them slightly to make, uh, something even better, uh, than either approaches individually. So here's the updated plan, everything it would follow, it's so incredibly cool. And then of course, we can review ourselves each plan and choose the one that best fits, uh, the way that we might go about it. Okay? So hopefully that clears things up. Now here's the reality.
Okay? So hopefully that clears things up. Now here's the reality. I think commands you will use the most, right? Commands are just sort of like snippets. They're aliases for things you do all the time. A skill once again, is a guidebook and maybe you don't have many field guides in your application, that's okay. But if there is a dedicated way for how we do things here, whether it's uh, creating an open graph image,
But if there is a dedicated way for how we do things here, whether it's uh, creating an open graph image, maybe you have a a system where this needs to be created, then you gotta visit this URL and you gotta boot up this server. If that's the case, document it. It's knowledge. Skills are knowledge commands are triggers, and then sub agents are sort of like tasks, but they happen in isolation. And again, the biggest win in my opinion is it doesn't clog
but they happen in isolation. And again, the biggest win in my opinion is it doesn't clog up the current context window. It doesn't muddy it. Uh, but also as we've just seen, uh, another win is that we can run different agents concurrently to speed things up. So let me know what you think and if you will be reaching for a subagent.
and if you will be reaching for a subagent.
