1
00:00:00,000 --> 00:00:06,559
And we have now arrived at the part of today that I am affectionately calling the spicy part

2
00:00:06,559 --> 00:00:11,520
where we're going to go through a few demos of other related things that we're not fully

3
00:00:11,520 --> 00:00:17,440
covering on this course but it's nice for you to know about. So you can be, you don't need to

4
00:00:17,440 --> 00:00:23,040
take all of this in knowing to remember anything, this is just to give you a quick tour of related

5
00:00:23,040 --> 00:00:29,440
stuff starting with the Claude Agents SDK that you might have heard of that and you might be

6
00:00:29,440 --> 00:00:34,319
wondering how that fits in and how it fits into other agent frameworks that I cover in my other

7
00:00:34,319 --> 00:00:38,880
courses. And the answer is of course that it's not really an agent framework at all even though

8
00:00:38,880 --> 00:00:43,520
it's called the Claude Agents SDK which which can certainly give you the impression that it's an

9
00:00:43,520 --> 00:00:50,159
agent framework but what it is is a way to programmatically drive Claude code, have access

10
00:00:50,159 --> 00:00:57,840
to all of the power of the agents in Claude code but do it by writing code. Okay let me show you

11
00:00:57,840 --> 00:01:04,080
exactly what that means. I've got here in VS Code a project I've just created called space

12
00:01:04,080 --> 00:01:10,879
and true to the name space we're looking at a completely empty totally empty directory with

13
00:01:10,879 --> 00:01:16,000
nothing in it whatsoever and we're going to fill up this space with something let me show you. And

14
00:01:16,000 --> 00:01:22,800
I'm going to use a uv project which you know I like uv if you don't listen then then google it

15
00:01:22,800 --> 00:01:30,000
uh I'm going to do a uv init dash dash bear that sets me up with a nice empty project let's do uv

16
00:01:30,000 --> 00:01:38,720
python pin 3.13 let's go with and now it's time to uv add which is the equivalent of pip install

17
00:01:38,720 --> 00:01:46,639
a few things we will have python.emv to handle keys we will have um requests because you always

18
00:01:46,639 --> 00:01:56,000
want requests and then let's go with Claude agent sdk uh it used to be called Claude code sdk and

19
00:01:56,000 --> 00:02:00,319
they called it they changed the name to Claude agent sdk and it's worth knowing that agent is

20
00:02:00,319 --> 00:02:04,879
singular I think I might have even said agents earlier because I'm used to opening our agents

21
00:02:04,879 --> 00:02:10,880
sdk but it's singular Claude agent sdk we've just done it we've built everything we have ourselves

22
00:02:10,880 --> 00:02:19,360
a .vemv and so we are ready to build something all right and I just copied in my .emv file from

23
00:02:19,360 --> 00:02:25,360
somewhere else which has a few keys in it like my anthropic key and I've also written a .gitignore

24
00:02:25,360 --> 00:02:30,080
file to to get ignore that even though we don't have a git repo this is just an empty folder

25
00:02:30,080 --> 00:02:37,279
but still it's a good practice okay now new file let's have a main.py this is where we're going to

26
00:02:37,279 --> 00:02:43,440
write some code and what's our code gonna do we're effectively gonna like drive Claude code

27
00:02:44,080 --> 00:02:49,199
using code all right so I'm gonna have some imports here I'm gonna uh first of all do the

28
00:02:49,199 --> 00:02:57,199
whole like load .emv uh to bring in my environment variables and I like to say override equals true

29
00:02:57,199 --> 00:03:02,399
so that the .emv overrides anything that's set up as like a system environment variable otherwise

30
00:03:02,399 --> 00:03:07,759
trouble trouble okay and yeah we're gonna want an async here it's filling it all in that's not

31
00:03:07,759 --> 00:03:14,000
what I want I don't want that I'm I'm gonna type myself I want to have like a prompt uh what is

32
00:03:14,000 --> 00:03:21,839
the meaning of life is not going to be my prompt uh and uh stop stop stop filling in uh-huh uh and

33
00:03:21,839 --> 00:03:28,639
we're also going to want to have um we're gonna want to have that the the tools that it can use

34
00:03:28,639 --> 00:03:33,839
so I'm going to have tools equals and that is indeed going to be some kind of a list

35
00:03:33,839 --> 00:03:39,440
okay so what's the prompt and what are the tools okay the prompt is going to be make a vanilla

36
00:03:40,320 --> 00:03:52,720
html plus js plus css website for a game of space invaders nope not pace of it is space invaders

37
00:03:52,800 --> 00:03:58,800
that's why the read this folder is called space uh full stop we won't give it any more than that

38
00:03:58,800 --> 00:04:03,199
we'll just give it that to work with now I know what you're thinking you're thinking I said on

39
00:04:03,199 --> 00:04:07,839
week one day one that that was going to be the only frivolous thing that that uh that we were

40
00:04:07,839 --> 00:04:13,119
going to build and everything else is going to be commercial well sue me all right and now tools

41
00:04:13,119 --> 00:04:18,239
for tools we're going to have all of these tools we'll let it have all of those those are the tools

42
00:04:18,239 --> 00:04:24,160
we're going to let our claude code through code have access to all right let's let's write the

43
00:04:24,160 --> 00:04:31,119
main function all right I'm going to start by saying options equals claude agent options this

44
00:04:31,119 --> 00:04:36,559
is where we specify what we want done you can see all those parameters that we can have including

45
00:04:36,559 --> 00:04:43,040
permission mode a whole lot of stuff mcp servers we can pass in all these different things and we

46
00:04:43,040 --> 00:04:47,760
can describe the model we're just going to go with defaults for everything except we're going

47
00:04:47,760 --> 00:04:57,279
to say allowed tools equals tools that's what we're doing and with that we now say async for

48
00:04:57,279 --> 00:05:04,720
message in query this is going to loop through the query where we're going to pass in the prompt

49
00:05:04,720 --> 00:05:09,920
equals the prompt and just as it's saying the options equals the options and then we're going

50
00:05:09,920 --> 00:05:16,720
to print the message that really is it that is our main function right there okay let's do some final

51
00:05:16,720 --> 00:05:24,000
tidy up uh oh look this looks wrong doesn't it that should just be dot emv like so um let's let's

52
00:05:24,000 --> 00:05:30,399
just say make a vanilla html for a game of space editors and let's just tell it write the um uh

53
00:05:30,399 --> 00:05:43,279
write the code to files in the current directory including index dot html uh so it's very clear

54
00:05:43,279 --> 00:05:49,920
what it has to do let's say in here do i remember that we could say model equals is that one of the

55
00:05:49,920 --> 00:05:59,679
options here i think so model equals and let's not use claude 2 let's go with claude opus 4.6

56
00:05:59,679 --> 00:06:04,559
as our model that seems like a good bet to me you should not do this by the way you should use a

57
00:06:04,559 --> 00:06:09,440
cheap model i'm splashing out for your entertainment it doesn't mean that you should please don't do

58
00:06:09,440 --> 00:06:16,000
this especially if you have a tight loop like this not a good idea unless you are crazy okay and then

59
00:06:16,000 --> 00:06:25,679
finally um async io oops spell it right async io dot run main there we go that should be everything

60
00:06:25,679 --> 00:06:29,519
does that look right to you have i missed anything i think that's probably good all right let's give

61
00:06:29,519 --> 00:06:38,720
it a whirl here we go uv run uv what uv run main.py okay and so again it's like we're calling

62
00:06:38,799 --> 00:06:43,359
claude code but instead of asking claude code the question we've got it here and these are the tools

63
00:06:43,359 --> 00:06:51,040
that can do we are driving claude code using code that's the idea we've equipped it with the tools

64
00:06:51,040 --> 00:06:56,640
that it may use like read write edit and we're letting it do its thing and you can see here that

65
00:06:56,640 --> 00:07:03,600
it's sending back messages oh a file just got created it's doing stuff and that was our plan

66
00:07:03,600 --> 00:07:09,679
so this this is how you can write code so that you're not interacting in a terminal but rather

67
00:07:09,679 --> 00:07:15,119
you're structuring things as code and it's obviously it's not something you necessarily

68
00:07:15,119 --> 00:07:19,519
need to do day to day but if you were building something that you wanted to take advantage of

69
00:07:19,519 --> 00:07:26,640
this whole ecosystem with skills with with the ability to have plugins and you wanted to have

70
00:07:26,640 --> 00:07:33,040
that functionality and build an app built on top of that then you could use the claude agent sdk

71
00:07:33,119 --> 00:07:38,000
to achieve that and also should you want a space invaders game and you don't want to have to type

72
00:07:38,000 --> 00:07:43,920
it into a terminal and interact with claw code then then take this code as it is right here

73
00:07:43,920 --> 00:07:49,440
i think we'll soon find out uh let it do its thing i will see you back here in a second okay

74
00:07:49,440 --> 00:07:56,160
and that has now completed took a couple of minutes and uh i will uh i i do indeed see that

75
00:07:56,160 --> 00:08:01,040
there is as you can see an index.html i've got that up here in this little window here here's a

76
00:08:01,040 --> 00:08:08,239
browser window for your viewing pleasure i will double click here and up comes space invaders

77
00:08:08,239 --> 00:08:14,720
enter or click to start uh it is a bit reminiscent of that first uh thing we had at the very

78
00:08:14,720 --> 00:08:22,079
beginning all right let's see let me press enter okay oh it's got sound how about that and the

79
00:08:22,079 --> 00:08:29,359
arrow keys work i didn't tell anything about keys oh look at the score as well a score and look

80
00:08:29,359 --> 00:08:35,119
there's the alien at the top that is absolutely brilliant absolutely brilliant and the colors as

81
00:08:35,119 --> 00:08:39,919
well everything here is great the astute amongst you will probably note that this is probably

82
00:08:39,919 --> 00:08:46,159
in some form in its training data uh nonetheless i should stop playing getting distracted nonetheless

83
00:08:46,159 --> 00:08:53,520
very cool very cool result nice outcome that of course is generated oh whoops uh generated

84
00:08:53,520 --> 00:08:59,840
look at that look at that flickering uh generated by claude code wonderfully a fully working game

85
00:08:59,840 --> 00:09:07,840
in vanilla html and js and css built by claude code using claude agent sdk