And we have now arrived at the part of today that I am affectionately calling the spicy part
where we're going to go through a few demos of other related things that we're not fully
covering on this course but it's nice for you to know about. So you can be, you don't need to
take all of this in knowing to remember anything, this is just to give you a quick tour of related
stuff starting with the Claude Agents SDK that you might have heard of that and you might be
wondering how that fits in and how it fits into other agent frameworks that I cover in my other
courses. And the answer is of course that it's not really an agent framework at all even though
it's called the Claude Agents SDK which which can certainly give you the impression that it's an
agent framework but what it is is a way to programmatically drive Claude code, have access
to all of the power of the agents in Claude code but do it by writing code. Okay let me show you
exactly what that means. I've got here in VS Code a project I've just created called space
and true to the name space we're looking at a completely empty totally empty directory with
nothing in it whatsoever and we're going to fill up this space with something let me show you. And
I'm going to use a uv project which you know I like uv if you don't listen then then google it
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
python pin 3.13 let's go with and now it's time to uv add which is the equivalent of pip install
a few things we will have python.emv to handle keys we will have um requests because you always
want requests and then let's go with Claude agent sdk uh it used to be called Claude code sdk and
they called it they changed the name to Claude agent sdk and it's worth knowing that agent is
singular I think I might have even said agents earlier because I'm used to opening our agents
sdk but it's singular Claude agent sdk we've just done it we've built everything we have ourselves
a .vemv and so we are ready to build something all right and I just copied in my .emv file from
somewhere else which has a few keys in it like my anthropic key and I've also written a .gitignore
file to to get ignore that even though we don't have a git repo this is just an empty folder
but still it's a good practice okay now new file let's have a main.py this is where we're going to
write some code and what's our code gonna do we're effectively gonna like drive Claude code
using code all right so I'm gonna have some imports here I'm gonna uh first of all do the
whole like load .emv uh to bring in my environment variables and I like to say override equals true
so that the .emv overrides anything that's set up as like a system environment variable otherwise
trouble trouble okay and yeah we're gonna want an async here it's filling it all in that's not
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
the meaning of life is not going to be my prompt uh and uh stop stop stop filling in uh-huh uh and
we're also going to want to have um we're gonna want to have that the the tools that it can use
so I'm going to have tools equals and that is indeed going to be some kind of a list
okay so what's the prompt and what are the tools okay the prompt is going to be make a vanilla
html plus js plus css website for a game of space invaders nope not pace of it is space invaders
that's why the read this folder is called space uh full stop we won't give it any more than that
we'll just give it that to work with now I know what you're thinking you're thinking I said on
week one day one that that was going to be the only frivolous thing that that uh that we were
going to build and everything else is going to be commercial well sue me all right and now tools
for tools we're going to have all of these tools we'll let it have all of those those are the tools
we're going to let our claude code through code have access to all right let's let's write the
main function all right I'm going to start by saying options equals claude agent options this
is where we specify what we want done you can see all those parameters that we can have including
permission mode a whole lot of stuff mcp servers we can pass in all these different things and we
can describe the model we're just going to go with defaults for everything except we're going
to say allowed tools equals tools that's what we're doing and with that we now say async for
message in query this is going to loop through the query where we're going to pass in the prompt
equals the prompt and just as it's saying the options equals the options and then we're going
to print the message that really is it that is our main function right there okay let's do some final
tidy up uh oh look this looks wrong doesn't it that should just be dot emv like so um let's let's
just say make a vanilla html for a game of space editors and let's just tell it write the um uh
write the code to files in the current directory including index dot html uh so it's very clear
what it has to do let's say in here do i remember that we could say model equals is that one of the
options here i think so model equals and let's not use claude 2 let's go with claude opus 4.6
as our model that seems like a good bet to me you should not do this by the way you should use a
cheap model i'm splashing out for your entertainment it doesn't mean that you should please don't do
this especially if you have a tight loop like this not a good idea unless you are crazy okay and then
finally um async io oops spell it right async io dot run main there we go that should be everything
does that look right to you have i missed anything i think that's probably good all right let's give
it a whirl here we go uv run uv what uv run main.py okay and so again it's like we're calling
claude code but instead of asking claude code the question we've got it here and these are the tools
that can do we are driving claude code using code that's the idea we've equipped it with the tools
that it may use like read write edit and we're letting it do its thing and you can see here that
it's sending back messages oh a file just got created it's doing stuff and that was our plan
so this this is how you can write code so that you're not interacting in a terminal but rather
you're structuring things as code and it's obviously it's not something you necessarily
need to do day to day but if you were building something that you wanted to take advantage of
this whole ecosystem with skills with with the ability to have plugins and you wanted to have
that functionality and build an app built on top of that then you could use the claude agent sdk
to achieve that and also should you want a space invaders game and you don't want to have to type
it into a terminal and interact with claw code then then take this code as it is right here
i think we'll soon find out uh let it do its thing i will see you back here in a second okay
and that has now completed took a couple of minutes and uh i will uh i i do indeed see that
there is as you can see an index.html i've got that up here in this little window here here's a
browser window for your viewing pleasure i will double click here and up comes space invaders
enter or click to start uh it is a bit reminiscent of that first uh thing we had at the very
beginning all right let's see let me press enter okay oh it's got sound how about that and the
arrow keys work i didn't tell anything about keys oh look at the score as well a score and look
there's the alien at the top that is absolutely brilliant absolutely brilliant and the colors as
well everything here is great the astute amongst you will probably note that this is probably
in some form in its training data uh nonetheless i should stop playing getting distracted nonetheless
very cool very cool result nice outcome that of course is generated oh whoops uh generated
look at that look at that flickering uh generated by claude code wonderfully a fully working game
in vanilla html and js and css built by claude code using claude agent sdk