So as you work on projects with Claude Code, from time to
time, you might wanna use Claude Code to perform
because, of course, it can also take a look at your code
wrote, I guess, and give you some feedback on that.
So you might wanna send a prompt like this to Claude Code or
maybe a more elaborate one where you describe in a bit
more detail how that code review should be performed.
The problem with this approach is, however, that you probably
wanna perform code reviews over and over again from
time to time. Not all the time, but maybe every day or so.
So you will probably repeat that prompt from time to time, and
sentence, that's not too bad, but what if it should be more
elaborate? That's where custom commands come
into play. Just as you can add agents and skills
to your Claude setup, you can also add custom commands, which
are in a nutshell just reusable prompts.
You can add them locally in your project as I'm doing it here, or again
globally in your user Claude folder.
And a custom command is really just a prompt
which could look like this, but there are a couple of things going on here, of
course. And of course, you also find this command attached.
Let's start with the metadata. This is entirely optional.
You don't need it. In its simplest form, a custom command could look like this,
just a prompt, but you can give it a description
show up when you cycle through your commands and you can
restrict the tools that can be used by Claude Code after you
invoked this command. By default, it can use all the tools of
the surrounding context, so all the tools, for example, if you use it in
the main agent. But if you add allowedTools,
tools you specify here. So for a code review command, I
might wanna narrow this down to just read access so that
it can't write any files. And then you have your prompt here.
Now this is a bit more elaborate prompt here also
because of this weird thing. Your commands
can, but don't have to accept arguments.
You can use this special $arguments placeholder
here and this field will be replaced with any
arguments, any input you passed to your command,
show you how you can do that in just a second.
So this will be replaced with your actual arguments, and this allows you to
build flexible dynamic commands just like functions in a
programming language, which also can accept parameters.
Here, for example, I expect to get a mode and
then in my prompt I tell Claude Code what to do based
on the value mode has, and maybe I write it like this.
So if mode is bugs, it should just look for bugs.
If it's security, it should look for security.
I also wanna allow for combined modes to look for bugs and
security issues, for example. And then I got some additional
down here, and it's just a prompt. You can tweak this however you want and
you can build any commands you want.
A command is simply a markdown file in the command's folder.
With your command defined, you can close your Claude
session and start a new one. You must do this to make sure
are properly loaded. And then if you type a forward slash,
your command will show up here amongst all the other
commands. They will not be auto discovered by Claude
be executed by Claude. They are meant to be executed by you.
So that's how that works. And therefore with that, I can
choose this code review command here and I could now hit enter
or I could provide some arguments.
Because remember, you can use arguments in
there. You don't have to, but you can.
So here I could say bugs, security
because these are the kinds of values I accept in my prompt
here. And if I now hit enter Claude Code will go
ahead and use that prompt and therefore now look
for bugs and security issues, and that prompt was executed behind
the scenes and that's, of course, therefore an easy way of reusing such a
prompt. And now it explores my code base
hopefully generate a good report about any potential
issues it finds in there. So here we go.
I got my report and further above I also have
some details on all these findings.
And of course, you should still take a look at them.
They're not necessarily all issues, or in our case here,
of course, the app is also not done yet.
But of course, it's good to have these findings,
decide whether you want to act upon them or not.
So for example, here I don't worry too much about this
to a public note page because I haven't worked on that page
yet. That's a feature that's yet to come.
So here in my case, I actually added a
.inf file. Well, I did it earlier already
off secret in there with, uh, at least 32 characters long
string that is needed by better off.
And I added this DB path variable since that was one of the
findings here that I have a hardcoded relative DB path and I
don't want that. I therefore crafted a new response prompt
I tell it to tackle these three problems.
Actually, I added one more and told it to update use
state to use common best practices.
And with that, I'll switch to plan mode
And of course, now this is a new prompt so the old tool
restrictions from the custom command no longer apply.
It now has full access to all tools again, and it can therefore make
that plan and then later also implement the plan.
So here we go. It presents me with a plan and
I'll accept that and let it continue.
So with that done, this all
still seems to work. I can go to the dashboard, can log out,
can log in, and add new notes and therefore the app is working
like before, but hopefully now with less problems.
Obviously, you should still always also manually
AI can make mistakes and it certainly doesn't give you the best
code all of the time. But with that, we can now move on.