WEBVTT

00:00:00.120 --> 00:00:04.040
So as you work on projects with Claude
Code, from time to

00:00:04.140 --> 00:00:07.980
time,
you might wanna use Claude Code to perform

00:00:08.220 --> 00:00:11.940
because, of course,
it can also take a look at your code

00:00:12.000 --> 00:00:15.620
wrote, I guess,
and give you some feedback on that.

00:00:15.680 --> 00:00:19.400
So you might wanna send a prompt like this
to Claude Code or

00:00:19.440 --> 00:00:23.200
maybe a more elaborate one where you
describe in a bit

00:00:23.300 --> 00:00:26.500
more detail how that code review should be
performed.

00:00:26.540 --> 00:00:29.740
The problem with this approach is,
however, that you probably

00:00:29.880 --> 00:00:33.730
wanna perform code reviews over
and over again from

00:00:33.760 --> 00:00:37.629
time to time. Not all the time,
but maybe every day or so.

00:00:37.680 --> 00:00:41.320
So you will probably repeat
that prompt from time to time, and

00:00:41.420 --> 00:00:44.040
sentence, that's not too bad, but what
if it should be more

00:00:44.100 --> 00:00:47.920
elaborate?
That's where custom commands come

00:00:47.960 --> 00:00:51.440
into play. Just as you can add agents
and skills

00:00:51.560 --> 00:00:55.540
to your Claude setup,
you can also add custom commands, which

00:00:55.740 --> 00:00:58.880
are in a nutshell just reusable prompts.

00:00:58.920 --> 00:01:02.860
You can add them locally in your project
as I'm doing it here, or again

00:01:02.900 --> 00:01:05.970
globally in your user Claude folder.

00:01:06.020 --> 00:01:09.790
And a custom command
is really just a prompt

00:01:09.880 --> 00:01:13.460
which could look like this, but there
are a couple of things going on here, of

00:01:13.500 --> 00:01:17.300
course. And of course,
you also find this command attached.

00:01:17.340 --> 00:01:20.580
Let's start with the metadata. This
is entirely optional.

00:01:20.590 --> 00:01:24.330
You don't need it. In its simplest form,
a custom command could look like this,

00:01:24.440 --> 00:01:28.250
just a prompt,
but you can give it a description

00:01:28.260 --> 00:01:31.760
show up when you cycle through your
commands and you can

00:01:31.800 --> 00:01:35.600
restrict the tools
that can be used by Claude Code after you

00:01:35.660 --> 00:01:39.640
invoked this command. By default,
it can use all the tools of

00:01:39.700 --> 00:01:43.690
the surrounding context, so all the tools,
for example, if you use it in

00:01:43.700 --> 00:01:47.660
the main agent. But
if you add allowedTools,

00:01:47.700 --> 00:01:51.340
tools you specify here.
So for a code review command, I

00:01:51.580 --> 00:01:55.550
might wanna narrow this down to just read
access so that

00:01:55.580 --> 00:01:59.180
it can't write any files.
And then you have your prompt here.

00:01:59.190 --> 00:02:03.060
Now this is a bit more elaborate prompt
here also

00:02:03.100 --> 00:02:06.550
because of this weird thing. Your commands

00:02:06.660 --> 00:02:09.800
can, but don't have to accept arguments.

00:02:09.810 --> 00:02:13.420
You can use this special $arguments
placeholder

00:02:13.500 --> 00:02:17.410
here and this field will be replaced with
any

00:02:17.480 --> 00:02:21.200
arguments,
any input you passed to your command,

00:02:21.340 --> 00:02:24.080
show you how you can do
that in just a second.

00:02:24.100 --> 00:02:27.600
So this will be replaced with your actual
arguments, and this allows you to

00:02:27.680 --> 00:02:31.580
build flexible dynamic commands just like
functions in a

00:02:31.620 --> 00:02:35.080
programming language,
which also can accept parameters.

00:02:35.160 --> 00:02:38.750
Here, for example,
I expect to get a mode and

00:02:38.840 --> 00:02:42.740
then in my prompt I tell Claude Code what
to do based

00:02:42.800 --> 00:02:46.400
on the value mode has,
and maybe I write it like this.

00:02:46.440 --> 00:02:49.080
So if mode is bugs,
it should just look for bugs.

00:02:49.100 --> 00:02:51.530
If it's security,
it should look for security.

00:02:51.680 --> 00:02:55.670
I also wanna allow for combined modes to
look for bugs and

00:02:55.760 --> 00:02:59.680
security issues, for example.
And then I got some additional

00:02:59.720 --> 00:03:03.620
down here, and it's just a prompt.
You can tweak this however you want and

00:03:03.660 --> 00:03:05.329
you can build any commands you want.

00:03:05.360 --> 00:03:09.200
A command is simply a markdown file in the
command's folder.

00:03:09.340 --> 00:03:13.300
With your command defined,
you can close your Claude

00:03:13.360 --> 00:03:17.280
session and start a new one.
You must do this to make sure

00:03:17.320 --> 00:03:20.780
are properly loaded. And then
if you type a forward slash,

00:03:21.480 --> 00:03:24.820
your command will show up here amongst all
the other

00:03:24.860 --> 00:03:28.700
commands.
They will not be auto discovered by Claude

00:03:28.840 --> 00:03:32.790
be executed by Claude. They
are meant to be executed by you.

00:03:32.820 --> 00:03:36.470
So that's how that works.
And therefore with that, I can

00:03:36.540 --> 00:03:40.440
choose this code review command here
and I could now hit enter

00:03:40.560 --> 00:03:42.620
or I could provide some arguments.

00:03:42.660 --> 00:03:46.280
Because remember, you can use arguments in

00:03:46.320 --> 00:03:48.720
there. You don't have to, but you can.

00:03:48.760 --> 00:03:51.829
So here I could say bugs, security

00:03:52.280 --> 00:03:56.140
because these are the kinds of values I
accept in my prompt

00:03:56.200 --> 00:03:59.800
here.
And if I now hit enter Claude Code will go

00:03:59.880 --> 00:04:03.840
ahead and use that prompt
and therefore now look

00:04:03.900 --> 00:04:07.790
for bugs and security issues, and
that prompt was executed behind

00:04:07.800 --> 00:04:11.000
the scenes and that's, of course,
therefore an easy way of reusing such a

00:04:11.080 --> 00:04:14.220
prompt.
And now it explores my code base

00:04:14.280 --> 00:04:18.220
hopefully generate a good report about any
potential

00:04:18.300 --> 00:04:21.060
issues it finds in there. So here we go.

00:04:21.459 --> 00:04:25.430
I got my report and further above I also
have

00:04:25.460 --> 00:04:28.390
some details on all these findings.

00:04:28.400 --> 00:04:30.880
And of course,
you should still take a look at them.

00:04:30.940 --> 00:04:34.830
They're not necessarily all issues,
or in our case here,

00:04:34.860 --> 00:04:37.030
of course, the app is also not done yet.

00:04:37.040 --> 00:04:40.480
But of course,
it's good to have these findings,

00:04:40.540 --> 00:04:43.430
decide whether you want to act upon them
or not.

00:04:43.460 --> 00:04:47.320
So for example,
here I don't worry too much about this

00:04:47.360 --> 00:04:51.340
to a public note page because I haven't
worked on that page

00:04:51.400 --> 00:04:53.800
yet. That's a feature that's yet to come.

00:04:53.880 --> 00:04:57.740
So here in my case, I actually added a

00:04:57.820 --> 00:05:01.600
.inf file. Well,
I did it earlier already

00:05:01.700 --> 00:05:05.480
off secret in there with, uh,
at least 32 characters long

00:05:05.540 --> 00:05:07.700
string that is needed by better off.

00:05:07.760 --> 00:05:11.320
And I added this DB path variable since
that was one of the

00:05:11.340 --> 00:05:15.250
findings here that I have a hardcoded
relative DB path and I

00:05:15.280 --> 00:05:19.260
don't want that.
I therefore crafted a new response prompt

00:05:19.340 --> 00:05:21.860
I tell it to tackle these three problems.

00:05:21.960 --> 00:05:25.740
Actually, I added one more
and told it to update use

00:05:25.940 --> 00:05:28.180
state to use common best practices.

00:05:28.200 --> 00:05:31.960
And with that,
I'll switch to plan mode

00:05:31.980 --> 00:05:35.480
And of course, now this
is a new prompt so the old tool

00:05:35.520 --> 00:05:38.620
restrictions from the custom command no
longer apply.

00:05:38.840 --> 00:05:42.740
It now has full access to all tools again,
and it can therefore make

00:05:42.780 --> 00:05:45.910
that plan and then later also implement
the plan.

00:05:45.960 --> 00:05:49.820
So here we go.
It presents me with a plan and

00:05:49.830 --> 00:05:52.200
I'll accept that and let it continue.

00:05:52.300 --> 00:05:55.980
So with that done, this all

00:05:56.080 --> 00:05:59.820
still seems to work.
I can go to the dashboard, can log out,

00:06:00.540 --> 00:06:04.400
can log in, and add new notes
and therefore the app is working

00:06:04.440 --> 00:06:07.770
like before,
but hopefully now with less problems.

00:06:07.820 --> 00:06:11.790
Obviously,
you should still always also manually

00:06:11.840 --> 00:06:15.700
AI can make mistakes
and it certainly doesn't give you the best

00:06:15.760 --> 00:06:19.599
code all of the time. But with that,
we can now move on.
