در حال بارگذاری ...

Introducing Custom Commands0:08

Now because JetBrains AI supports Claude as one of its agents, well, that means we have access to Claude features. For example, let's take a look at the terminal and boot up claw to code. And if I hit forward slash we can see all of the various built-in CLA commands that we can run. Now, you maybe didn't know this, but you can also write your own custom commands. And don't worry, this isn't,

Creating Commands Directory0:30

but you can also write your own custom commands. And don't worry, this isn't, this isn't a scary thing at all, really. Uh, command and Claude is just an alias for a prompt that you frequently write. It's just not much more complicated than that. I'll show you a couple examples Back to my editor. If you've ever run Claude Code in your project, you will have a dot Claude directory as you see here. Otherwise, just create it on your own.

you will have a dot Claude directory as you see here. Otherwise, just create it on your own. Within here we're gonna add a new directory called commands. And within here, let's create a markdown file that represents, again, some kind of prompt that, uh, we frequently write. Why don't we call this one? Let's do something simple to start. How about learn? So just to get us started and to demonstrate how incredibly simple this is,

So just to get us started and to demonstrate how incredibly simple this is, I'm just gonna say something dumb like all you need to do is say hello to me, do nothing else. Yeah, that's it. Just to get us going and to show you, you can add front matter if you want front matter, but you don't have to, this will be fine. Okay. So the simple fact that we now have a commands directory

Okay. So the simple fact that we now have a commands directory with a single command, that's all we need. It will now show up and Claude code like this. Let's boot up Claude one more time, and if I hit forward slash sure enough, the top option is learn. All you need to do is say hello to me. All right, so notice that is taking the place of the description, but

All right, so notice that is taking the place of the description, but of course we could add some YAML front matter to, to be explicit about that. Anyways, if I give this a run, it's going to read that file and do what it says like a prompt. That's it. And it says hello. So it really is incredibly simple. All right, let's add, uh, if you want, uh, YAML front matter.

Adding YAML Front Matter2:11

All right, let's add, uh, if you want, uh, YAML front matter. If you're not familiar with this format, it is three dashes at the top of a file. Often it's used for static blogs and things like that to declare, uh, meta information. So in this case, we can declare the description, a simple demo greeting. Alright, back to Claude boot up, Claude, one more time. Let's review our commands

Building a Learn Command2:29

Alright, back to Claude boot up, Claude, one more time. Let's review our commands and sure enough, now we are setting the description so you get how that works. Okay, so now why don't we say, I'm gonna type learn and I want, um, Claude to teach me about that file and how it works. So maybe something like this, and I'm just gonna paste this in to save ourselves some keystrokes. Alright, so we're going to explain a file or simple

in to save ourselves some keystrokes. Alright, so we're going to explain a file or simple and plain English, uh, your senior developer, explain the purpose of whatever I pass in. And notice I can use just simple common, uh, references here, like dollar one to reference the first argument you pass in dollar two to reference the second argument. And it's probably familiar to you anyways. If, uh, the argument is a file path, summarize what it does.

And it's probably familiar to you anyways. If, uh, the argument is a file path, summarize what it does. Uh, if it looks like it's a function or a symbol, describe its purpose and then give me three quick things to check next. And that's it. So again, um, you know what, this actually might be more useful than you'd think. Okay, so let's give it a shot. Why don't we go into App Telegram and learn about help command.

Why don't we go into App Telegram and learn about help command. Let's just figure out what it's, okay. So back to the terminal OpenCL. I wanna learn about help command. There it is. We'll give it a run. So notice this is effectively an argument and that will be sent through as dollar one. It's gonna read that and explain what the file does. All right, and we're done. So help command is a telegram bot command handler

All right, and we're done. So help command is a telegram bot command handler that responds when the user types, hello, blah, blah, blah, you get the idea. And then at the bottom, this is kind of cool, three things to check. Next, well, here's two other commands, and then also an app service provider to see how Nut Graham discovers and registers the command handlers. Okay, pretty cool, right? Uh, maybe we could do one more.

how Nut Graham discovers and registers the command handlers. Okay, pretty cool, right? Uh, maybe we could do one more. Let's learn about how about, uh, bootstrap slash app PHP. All right, that's done. So we're gonna go super quick. Uh, bootstrap file, central configuration hub for Laravel. Uh, this is how we use it. Here's the entry points and maybe some other files you should check out next. It could be helpful. Okay,

Creating a Format Command4:37

and maybe some other files you should check out next. It could be helpful. Okay, let's do one a bit more practical now though. So if I open up Composer, do Jason. Yeah, you'll see within the script section I have added a composer script called Format that simply defers to Rector and then PHP Stan and Pint. Uh, it's a good habit to get into. Just run these whenever you're working on a commit, uh, and you're ready to push it up.

Just run these whenever you're working on a commit, uh, and you're ready to push it up. Okay, so you'll remember in the, what was it, the developer driven AI episode. We had AI work on some telegram commands, but notice it's not honoring our formatting. So of course we could update our guidelines, but every once in a while it will ignore those as well. So it would be nice if we could ask AI to always run this. So here's one thing we could do.

So it would be nice if we could ask AI to always run this. So here's one thing we could do. We could register it as a command right here. Create a new file, we'll call it format. All right? So I'm gonna paste this in. You don't wanna watch me write this out by hand. It's a little painful. Uh, but we now have a a format command that will format test and prepare for a get push. It'll do that by running that composer run

and prepare for a get push. It'll do that by running that composer run format, uh, script. If PHP stand triggers some kind of warning it needs to fix the issue and then rerun until everything passes successfully. And then I want it to run pest. Now if the tests fail, it needs to fix the tests. And then rerun, composer, run format just in case any discrepancies were introduced.

And then rerun, composer, run format just in case any discrepancies were introduced. Yeah, so again, this is the sort of thing that we could paste into a prompt ourselves. And maybe you've done this many times where you say, Hey, do this and then this and then this, right? Well, with a command, we're just wrapping it in an alias of sorts that we can trigger. But also the AI or Claude can trigger itself. Let's give it a shot. So if I open up help command,

But also the AI or Claude can trigger itself. Let's give it a shot. So if I open up help command, I just want you to notice that the formatting is not correct. So we boot up Claude, run our commands, and here is format. All right? And that's done. So take a look real quick. It ran our format script, it ran rector and all that stuff. It ran pint. Um, then it ran our test suite, which returned to green. Here are the results. Fixed some

Reusing Commands in Workflows6:44

then it ran our test suite, which returned to green. Here are the results. Fixed some files, pint, fixed some files. There were no PHP spanishes. Uh, this is great, right? And here's the cool thing. Yes, we can, we can trigger it like a traditional command. So I can say format or I can say learn, but also I can instruct it to run this command as part of a different task. So I could say, work on blah and blah.

as part of a different task. So I could say, work on blah and blah. And when you're done, um, run format to finalize all of your changes, right? And it will be smart enough to know, okay, I need to work on whatever blah, blah is, and then at the very end, I'm gonna run this format command. All we have to do is tell it to do that and it will figure it out. Uh, so this is incredibly helpful for a couple of reasons.

and it will figure it out. Uh, so this is incredibly helpful for a couple of reasons. One, we are formalizing common prompts, so we are saving ourselves some keystrokes. And second, we can commit this diversion control so that it can be shared against, uh, or across all members of our team. Tell me what you think.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟