back to indexClaude Code best practices | Code w/ Claude

00:00:06.840 |
Welcome, everyone, to Cloud Code Best Practices. 00:00:12.520 |
In this talk, I'm going to talk about kind of what 00:00:26.160 |
we're going to talk about good use cases for Cloud Code 00:00:38.000 |
But before I get started, I'd like to introduce myself 00:00:40.120 |
real quick and talk about how I ended up on the stage. 00:00:44.760 |
And I joined Anthropic about a year and a half ago 00:00:53.960 |
our team's mission is to help our customers and partners build 00:01:00.160 |
So what that really means is I spend a lot of my day prompting 00:01:04.360 |
Cloud to get the absolute best outputs out of these models. 00:01:08.440 |
That said, I also love to code, and I'm definitely 00:01:11.080 |
one of those coders that starts a lot of projects, 00:01:14.160 |
has some crazy idea, and then just never finishes them. 00:01:16.720 |
So I have this graveyard of just like code that I started, 00:01:24.720 |
and I was hearing about this new tool that a few people are using. 00:01:29.600 |
And so on a Friday night, I downloaded the tool that would become Cloud Code, 00:01:33.680 |
and I threw it at this kind of new note-taking app that I wanted to build. 00:01:37.400 |
And that whole weekend just kind of totally changed the way that I code and think about software engineering. 00:01:43.240 |
I was carrying around my laptop with me all weekend. 00:01:46.240 |
I was super addicted to just watching Cloud Code work. 00:01:49.240 |
And I would press enter, and I'd switch over to my browser and refresh. 00:01:53.120 |
And I watched this huge, powerful application come together in front of my eyes. 00:01:58.240 |
And I got way farther into this thing than I ever would have on my own. 00:02:03.920 |
And while I was doing this, I was a little worried. 00:02:05.760 |
I was like, you know, I kind of know how these things work. 00:02:10.680 |
I hope I don't get in trouble or anyone notices. 00:02:13.040 |
I'm not really contributing to Anthropic Code. 00:02:16.200 |
But what I didn't know is that the Cloud Code team had built this internal leaderboard, 00:02:21.600 |
tracking how much all the Anthropic employees were using this. 00:02:27.640 |
And so through that, I got to meet Boris and Kat and some of the early Cloud Code team. 00:02:32.040 |
And I was able to start talking to them and say, hey, I love this tool. 00:02:41.960 |
And now I'm one of the core contributors on the team. 00:02:44.760 |
And I do a lot of-- I work a lot on the prompting, the system prompts, 00:02:48.840 |
how the tools work, the tool descriptions and tool results, 00:02:51.920 |
as well as I work on how we evaluate this tool. 00:02:55.000 |
So when we think about changing the prompts, how do we know 00:02:57.960 |
we made things better or the same, and we didn't totally ruin Cloud Code? 00:03:05.480 |
So here's my current mental model of Cloud Code 00:03:08.400 |
and how I describe it to people when people ask me. 00:03:12.880 |
Cloud Code is like that coworker that does everything on the terminal. 00:03:17.600 |
It's the sort of person that just never touches the GUI. 00:03:21.400 |
I think of when I was a junior engineer, I had this mentor. 00:03:24.360 |
And I would walk over his desk and I would say, hey, Tony, 00:03:31.260 |
And he'd be doing all these crazy bash commands 00:03:34.980 |
And I'd always walk away thinking, wow, that was crazy. 00:03:43.960 |
is kind of like having Tony next to you all the time. 00:03:46.620 |
So how does Cloud Code kind of work under the hood? 00:03:54.620 |
At Anthropic, we try to always do what we call the simple thing 00:04:02.760 |
it's what we would consider a very pure agent. 00:04:06.740 |
And Anthropic, when we talk about agents, what we really mean 00:04:24.080 |
that someone that was really good at a terminal 00:04:27.380 |
Tools to create and edit files, to use the terminal, 00:04:30.580 |
and then you can also do things like pull in other things 00:04:35.120 |
Now, on top of that, there's how Cloud understands the code base. 00:04:40.560 |
And if you're going to build a coding agent or a coding tool 00:04:43.800 |
a year ago, you'd probably have ideas like, well, OK, 00:04:47.500 |
I'm going to get this user message about something 00:04:50.540 |
about this code base, and I'll need to figure out 00:04:53.380 |
So maybe I'll index the whole code base and embed it 00:04:56.620 |
and do this fancy, like, kind of rag retrieval thing. 00:05:03.860 |
Instead, Cloud kind of explores and understands the code base 00:05:09.100 |
how you, if you were new to a team and new to a code base, 00:05:15.580 |
It's the same sort of search tools you or I would use, 00:05:26.620 |
that really means the model can go do some searches, 00:05:29.580 |
and then it can look at the results and say, hmm, 00:05:32.180 |
maybe I need to figure out a few more things. 00:05:33.960 |
I'm going to go do some more searching and then come back. 00:05:50.700 |
that allows the agent to work and allows and kind of forces 00:05:54.660 |
the human to butt in when the agent is doing something 00:05:58.020 |
And then on top of that, we also care a lot about security 00:06:02.220 |
And so because Cloud Code is just such a lightweight kind 00:06:09.000 |
that our model is available not just behind Anthropic APIs, 00:06:12.180 |
but also with our cloud providers, AWS and GCP, 00:06:16.500 |
it's very easy and native to point Cloud Code 00:06:21.000 |
feel more comfortable consuming Cloud that way. 00:06:33.280 |
And the reality is, it's kind of great at everything. 00:06:43.900 |
be dropped into a new code base, whether that 00:06:45.880 |
means you're switching teams, you're switching companies, 00:06:52.060 |
And probably when you're first getting started 00:06:56.620 |
where things are in the code base, what patterns kind 00:07:06.040 |
You can ask Cloud, hey, where is this feature implemented? 00:07:12.720 |
and look at the Git history, and just kind of tell me 00:07:20.400 |
One thing you can use Cloud Code for-- and I think 00:07:22.520 |
this is underrated-- is instead of just diving in 00:07:32.540 |
or we're going to change something up, I'll open up Cloud, 00:07:34.920 |
and it'll say, hey, Cloud, I'm thinking about implementing 00:07:39.000 |
Can you just kind of search around and kind of figure out 00:07:49.440 |
And Cloud will go off and use those agentic search 00:07:54.840 |
And then I can work with Cloud to kind of validate things, 00:08:00.960 |
Of course, Cloud Code is great at building and writing code. 00:08:04.320 |
And I would say this on two different fronts. 00:08:06.640 |
One, it can do the zero to one sort of stuff. 00:08:09.120 |
You drop it in an empty directory, and you say, hey, 00:08:19.740 |
is Cloud Code good working in existing code bases. 00:08:27.680 |
And the Cloud Code team, we have in our code base 00:08:31.160 |
abnormally high, I would say, unit test coverage. 00:08:36.420 |
it so easy and just straightforward to add unit tests. 00:08:43.020 |
And then the other thing we have in Cloud Code, 00:08:44.740 |
in our own code base, is we have great commits and PR messages. 00:08:48.200 |
Because when we finish working, we'll just say, hey, 00:08:54.240 |
We also see great opportunities to use Cloud Code 00:08:58.020 |
in kind of the deployments and in other parts of the lifecycle. 00:09:02.880 |
And this is-- a few other people have talked about this. 00:09:08.160 |
So using it headlessly, using it programmatically, 00:09:11.240 |
being able to sprinkle in a coding agent anywhere. 00:09:16.560 |
And so that's things like sprinkling it into CI/CD 00:09:19.160 |
to use it in GitHub, for instance, to help people programmatically. 00:09:24.820 |
And then finally, it's great kind of with support and scale. 00:09:30.420 |
One thing that we saw when we started giving Cloud Code to customers 00:09:34.160 |
and talking to them about it, we didn't totally predict this. 00:09:36.740 |
It was a lot of customers or potential customers said, hey, 00:09:39.920 |
we've been kind of putting off this large code base migration, people that are on old versions 00:09:45.580 |
of Java trying to get to a new one, or a team that's on PHP and they're trying to get to React 00:09:51.480 |
We've talked to multiple teams like this, and having a tool like Cloud Code makes projects 00:09:56.900 |
like that a little more digestible when you go to your team and you say, hey, we're going to spend a month 00:10:00.960 |
of refactoring or rewriting large parts of the code base. 00:10:06.620 |
And then on top of that-- and this kind of matters across all these-- is once again, remember, 00:10:13.280 |
And that means it's going to be great at all those different CLI tools, things like Git, Docker, 00:10:20.420 |
I never have to worry about, oh, I'm going to get myself-- how do I get myself out of this sticky rebase? 00:10:26.280 |
I'll just fire up Cloud Code and tell it the situation and be like, hey, can you fix this for me? 00:10:36.980 |
And the first one is not going to be a surprise, but the first one is use Cloud.MD files. 00:10:43.840 |
So remember that Cloud Code, like I said, is an agent, and it has some tools. 00:10:48.720 |
It has some lightweight instructions in the prompt, but it doesn't really have memory. 00:10:53.340 |
And so the main way we share state across kind of sessions 00:10:57.660 |
or across our team when we fire up Cloud Code in the same code base 00:11:04.620 |
So when we start Cloud, what happens is if there's this Cloud.MD file 00:11:08.780 |
in the working directory, it's just plopped into context. 00:11:13.060 |
And basically what it says is, hey, Cloud, by the way, 00:11:15.500 |
these are important instructions the developer left for you. 00:11:21.680 |
And there's various places you can put the Cloud.MD file. 00:11:24.300 |
You can put it in a project and check it in so all your teammates share it. 00:11:28.220 |
You could put one in your home directory if there's things you just want Cloud 00:11:31.300 |
to always know about, regardless of what you're working on. 00:11:34.360 |
And the things you put in here are things like, hey, by the way, 00:11:40.100 |
Or just so you know, to make kind of your searching and life easier, 00:11:43.820 |
here's just like an overview of kind of how this project is laid out, where the tests live, 00:11:48.580 |
what different modules are, things like that. 00:11:51.360 |
Or here's our style guide, all sorts of things like that to just make Cloud's life a bit easier. 00:12:01.360 |
The other thing you can do which is important is permission management. 00:12:04.980 |
When you're running Cloud code, there's all sorts of different kind of permission things flying by. 00:12:09.900 |
Kind of out of the box, what happens when you start our tool is for read actions. 00:12:14.620 |
If Cloud is searching or reading, we just let it go. 00:12:17.980 |
But once it starts writing or running bash commands or doing things that could change stuff on your machine, potentially, 00:12:26.400 |
that's when we kick in this UI and it says something like, yes, yes, always allow this, or no, I want to do something else. 00:12:35.520 |
And using that permission management and being smart about it can help you work faster. 00:12:40.440 |
So there's something called auto accept mode, where if you're working with Cloud code and you press shift tab, 00:12:47.980 |
There's things you can do like you can configure Cloud in the settings where specific commands, 00:12:53.100 |
like on bash, like if you just are like tired of saying, yes, run NPM run test, 00:13:00.540 |
So fiddling with your permission management is a great way to kind of speed up your workflow. 00:13:07.680 |
So one thing that is going to help you get the most out of Cloud code is remember that it's great at the terminal. 00:13:13.800 |
And if there's applications that you use which have kind of a way to access them through CLI-- and GitHub is a great example 00:13:20.720 |
of that, they have a powerful tool called GH-- you can basically give more work to Cloud code. 00:13:27.100 |
And you can do that either by just installing more CLI tools or you can attach more MCP servers. 00:13:33.720 |
I would say just through experience that if you're using something like a CLI tool that's well-known 00:13:40.640 |
and well-documented and you're trying to choose between the CLI tool and just installing it on your machine and grabbing an MCP server, 00:13:51.440 |
And then also if you internally have your own tools at Anthropic-- we have something called Koo that does a whole bunch of stuff for us-- 00:13:59.440 |
you can also tell Cloud about that and that's the sort of thing you'd put in Cloud.md. 00:14:03.440 |
And then context management-- so remember that Claude is an agent. 00:14:10.360 |
And what it does, it calls these tools and the context builds up and up over time. 00:14:16.360 |
And at least for Anthropic, our models have a context window of 200,000 tokens and you can max this thing out. 00:14:22.360 |
So you kind of have two options when you're in a long session with Cloud and you're working and you're going back and forth. 00:14:29.280 |
You'll see in the bottom right, you'll start to get this little warning that'll say, hey, you're starting to fill out the context window. 00:14:35.280 |
And kind of depending on what's going on, you have two options. 00:14:38.280 |
You can run /clear and just start over and that clears everything out except for, for instance, Claude.md. 00:14:44.280 |
Or you can run /compact and what'll happen is basically it's like a user message is inserted and it just says something like, 00:14:52.280 |
hey, I need to go summarize everything we've been up to. 00:14:55.600 |
I'm going to give this to another developer and they're going to pick up where I left off. 00:14:59.200 |
And then that summary is what kind of seeds the next session and you can go from there. 00:15:03.200 |
We spend a lot of time tuning this kind of compact functionality so that as you max out the context window 00:15:09.200 |
and then run compact, you can start back over and keep going. 00:15:14.760 |
Efficient workflows, what can you do with Cloud Code and how do you get the most out of it? 00:15:19.240 |
So using planning and to-dos, I talked a little bit about this before, but one of the best things you can do is when you open up Cloud Code, 00:15:26.160 |
instead of saying, hey, I need you to fix this bug, you can say, hey, I have this bug. 00:15:31.160 |
Can you search around, figure out what's causing it and just like tell me a plan how we're going to fix it? 00:15:35.560 |
And this can save you a lot of time because you can verify, you can read Cloud's plan and you can verify what it's going to do. 00:15:42.480 |
And then the other thing that we have is we have this to-do list feature. 00:15:46.400 |
So often when Cloud's working on a big task, it will create a to-do list. 00:15:51.400 |
And if you're kind of paying attention, you can kind of watch this to-do list. 00:15:55.400 |
And if you see anything kind of weirder in there or something that doesn't make sense, 00:15:58.400 |
that's when you can press escape and say, hey, Cloud, let's change the to-do list. 00:16:06.080 |
So it's very tempting and it's very powerful to just let Cloud work and press Enter and see what happens at the end. 00:16:12.400 |
I think there's a few things that can help make this better. 00:16:14.880 |
And there's, I think, a talk later today about just this for 30 minutes. 00:16:19.520 |
But doing things like having test-driven development, 00:16:22.440 |
having Cloud make small changes, run the tests, make sure they pass, 00:16:26.640 |
always having Cloud do things like check the TypeScript and the linting, 00:16:32.160 |
So that if it's kind of going off the rails, you can always fall back and try again. 00:16:39.560 |
So Cloud is built on top of our models, which are multimodal. 00:16:43.460 |
You can always just grab a screenshot, paste it in. 00:16:45.880 |
Or if you have a file somewhere that's an image, you can just say, hey, Cloud, 00:16:49.240 |
look at this mock.png, and then build the website for me or whatever. 00:16:56.960 |
OK, so as you're getting used to using Cloud, what are some things 00:17:00.500 |
you can think about to kind of push things to the next level? 00:17:04.440 |
And one of the things we see both internally and with customers 00:17:07.920 |
is when you've started to use this tool for a while, 00:17:10.460 |
it's going to be very tempting to use multiple Clouds at once. 00:17:14.720 |
And so I know people at Anthropic and a few customers that run four Clouds at the same time. 00:17:21.320 |
You can have it in Tmocs or just different tabs, all sorts of crazy things. 00:17:25.860 |
So I would challenge you to try getting multiple Clouds running at once 00:17:29.920 |
and kind of be orchestrating all these things. 00:17:32.960 |
I can only do two, but I know people that do four. 00:17:40.300 |
While Cloud is working, you can kind of keep an eye on what it's up to, 00:17:44.280 |
and you can press escape to stop it and interject and say, hey, 00:17:47.960 |
I think you're going on the wrong path or I want you to do something else. 00:17:51.520 |
Knowing when the right time to press escape is versus just letting Cloud figure it out 00:17:59.920 |
Not too many people know about it, but if you press escape twice, 00:18:03.280 |
you can actually jump back in your conversation. 00:18:13.120 |
If you feel like with Bash and with the tools that Cloud has that it still 00:18:17.440 |
can't do something, this is when you should start looking at MCP servers. 00:18:23.680 |
I think this is the thing we're most excited about, 00:18:26.240 |
but also we are still trying to wrap our heads around internally, 00:18:29.960 |
which is how can we use Cloud programmatically? 00:18:35.040 |
We want to figure out other creative places we can start using it. 00:18:43.600 |
So with that said, I'm going to jump over to my computer because there's one other best 00:18:48.640 |
practice, which is it's always good to stay on top of everything that's new. 00:18:56.080 |
I'm just going to go over a few things that are new as of today. 00:18:59.840 |
One thing is when you're in Cloud now and you fire it up, you can do /model. 00:19:12.000 |
You can do the same thing in /config, switch it here. 00:19:19.200 |
Make sure you're running the model that works for you. 00:19:21.200 |
There's another thing that's new about these models, 00:19:32.320 |
we've had this like think hard or extended thinking. 00:19:36.320 |
Now, this is great, but with our past models, 00:19:40.080 |
we wouldn't let our model think between tool calls. 00:19:42.560 |
And that's probably when the thinking matters most. 00:19:44.560 |
So starting with Cloud 4, our models now think between tool calls. 00:19:59.760 |
And so the way you know you triggered thinking 00:20:02.320 |
is you'll see kind of this lighter gray text. 00:20:12.560 |
So I encourage you, when you're working on tasks and solving bugs, 00:20:21.920 |
We'll just throw it up real quick, is I have this in VS Code. 00:20:28.880 |
But we have these new great integrations with VS Code and JetBrains. 00:20:34.320 |
We can do things like, Claude's going to know what file I'm in. 00:20:38.720 |
That is not what I meant to say, but Claude's going to figure it out. 00:20:58.080 |
So these are the sort of things I would encourage you to stay on top of. 00:21:01.680 |
We have a public kind of GitHub project called Claude Code under Anthropic. 00:21:07.520 |
You can post issues there, but we also post our changelog there. 00:21:10.720 |
And so I check this once a week and make sure that I'm on top of all the new stuff we're shipping, 00:21:17.120 |
So with that said, we have like four minutes left. 00:21:20.640 |
I'm happy to answer questions about anything Claude Code related. 00:21:24.480 |
I can live demo some stuff if you're interested. 00:21:33.840 |
This might be obvious, but multiple Claude.md files in a project, I presume that's possible 00:21:44.400 |
Of course, like in the same directory, you couldn't. 00:21:48.400 |
But you could have one here and one in a subdirectory. 00:21:56.320 |
And I think we changed this so that all the subdirectory ones aren't read in, 00:22:02.960 |
And people would open it at the top and blow up their context with all the Claude MDs. 00:22:07.760 |
So we encourage Claude when it's searching around and it discovers Claude.md files 00:22:13.280 |
in child directories that are relevant to be sure to read them. 00:22:17.920 |
But by default, it just reads the Claude.md file in the current working directory when you fire it up. 00:22:23.600 |
And then also you can set one in like your home directory. 00:22:29.600 |
Like in your Claude.md, you can start referencing other files. 00:22:34.880 |
So you could, for instance, do something like this with an @ sign. 00:22:39.520 |
If you have other Claude.md files that you just kind of know you always want to read in, 00:22:49.440 |
I have not had luck getting Claude to respect my Claude.md. 00:22:54.480 |
Like there's one thing particular where I'll ask it to refactor something, 00:22:58.640 |
and then it will leave inline comments explaining the what of it is. 00:23:02.720 |
And it's like something that's extremely obvious. 00:23:05.280 |
And so I'll tell it like, go and remove any inline comments that describe the what of what's happening. 00:23:10.400 |
And then it will remove it and then immediately do it again in like the same path. 00:23:13.920 |
So do you have any strategies for dealing with that? 00:23:18.880 |
So that was actually kind of a model problem. 00:23:22.160 |
We have actually a lot in the prompts for 3.7 that said, whoa, do not leave comments. 00:23:27.200 |
And despite that, the model just loves to leave comments. 00:23:29.600 |
So it doesn't surprise me that your Claude.md didn't help much either. 00:23:33.920 |
I did a lot of work to try to tamp it down from what happens out of the box. 00:23:42.800 |
Now, there might be some new weird behavior quirks. 00:23:45.200 |
But the other thing we made better in Claude 4 is it's just better at following instructions. 00:23:49.120 |
And we've gotten a lot of feedback from early testers that all of a sudden, whoa, 00:23:54.640 |
my Claude.md is being followed way more closely. 00:23:57.280 |
And it might be a good chance to go look in your Claude.md and decide, do I still need this stuff? 00:24:06.880 |
So moving over to the new models might be a good time to take another look at what's in there and 00:24:13.680 |
For the record, I'm trying to think of something that you might not have thought of. 00:24:18.560 |
We're doing multi-agent execution and parallelization. 00:24:22.240 |
Can you make it so that for four agents, say, agents two and three use the context from agent one? 00:24:28.160 |
Maybe agent four uses the context from agent two at a certain point? 00:24:34.960 |
We're trying to-- so kind of like I said at the beginning, we're trying to do the simple thing 00:24:39.360 |
that works, which is just one agent that's great at coding and does everything. 00:24:46.080 |
Probably what's going to happen is if you wanted to do that, you would ask all your 00:24:50.800 |
agents to probably write to a shared markdown file or something like that so they can all 00:24:57.200 |
Sometimes I'll be working with Claude and I'll just say, "Hey, I need you to write 00:25:03.120 |
some stuff in Ticket.md for another developer." 00:25:06.160 |
And then I'll fire up another Claude code and I'll be like, "Hey, read Ticket.md. 00:25:14.000 |
So I would think about trying to write that state to a file and then just kind of like 00:25:18.160 |
count on the model's ability to just like read files and make sense to them. 00:25:21.600 |
It's probably the best you can do today and maybe we'll figure out clever ways to expose that 00:25:35.200 |
And with that said, I have some rare Claude code stickers that I found in my backpack.