Code Mode Makes Claude Code Smarter & Cheaper — Transcript
Full transcript
- 0:00Okay, so Anthropic just added something
- 0:01that makes Cloud Code smarter whilst
- 0:04also being cheaper for the same model,
- 0:06and that is by rewriting a decent chunk
- 0:08of the harness in a feature called code
- 0:10mode. So I basically want to go through
- 0:11what exactly that is in this video
- 0:13because I think it follows a trend that
- 0:14we're seeing more and more whereby the
- 0:15model is swallowing the harness, and I
- 0:18think that this is a pretty good example
- 0:19of that. Now do you want to mention that
- 0:20this concept has been around for over
- 0:22one year and this Cloudflare article
- 0:24kind of popularized it and it has been
- 0:26implemented to varying degrees inside of
- 0:28different harnesses like Codex, OpenAI,
- 0:31Prime Agent, but in this video I want to
- 0:33focus on Cloud Code's implementation
- 0:35because I like talking about Cloud Code.
- 0:36As a really short aside, I will be doing
- 0:38a Black Friday deal this year, so if you
- 0:40want to be the first to hear about it,
- 0:41then there will be a link down below.
- 0:42Now if you already know what code mode
- 0:43is and you want to know how Cloud Code
- 0:45implemented it, then you can skip to a
- 0:46timestamp on the screen right now, but
- 0:48if you don't know what it is, then I'm
- 0:49basically going to explain that. So
- 0:50because I like to explain things problem
- 0:52first, solution second, I want to give
- 0:54some motivation for why code mode even
- 0:56matters. So right now many harnesses are
- 0:59a bunch of separate tools like read,
- 1:01edit, bash, web fetch with some other
- 1:03things attached, and the model is just
- 1:05basically looping through these tools
- 1:06until it decides it's done. Now this is
- 1:08fine and all, but it becomes a problem
- 1:09when your agent is connected to dozens
- 1:11of tools, specifically MCP servers, each
- 1:14of which can have dozens of tools inside
- 1:16because if your agent now wants to chain
- 1:18many different tools together from
- 1:20different MCP servers, then it has to
- 1:22pass the result of each one through the
- 1:24context window. So for example, you may
- 1:26do one tool call to pull in some data
- 1:28from the Stripe MCP server and then that
- 1:30would go into the context window and
- 1:31then the model will decide, okay, I'm
- 1:33going to do this other tool call to pull
- 1:34in some data from like Cloudflare. That
- 1:36would go inside and then it may combine
- 1:38the data in some way with a script and
- 1:40then pass it to another MCP server. Now
- 1:43the problem is that the output of every
- 1:44tool call is just sitting inside of the
- 1:46context window. So the next time a tool
- 1:48is called, the model rereads the entire
- 1:50conversation and this can continue over
- 1:52and over again. And even though these
- 1:54tokens are cashed and they're charged at
- 1:5610% of the usual rate, you're still
- 1:58needlessly paying for things that
- 1:59shouldn't have to inside of the context
- 2:01window. So it would be much better if
- 2:02the model, instead of doing many
- 2:04different tool calls and using the
- 2:05context window as a intermediary, could
- 2:08pass a result of one tool call directly
- 2:10to next one without it ever entering the
- 2:12context window. And that was one of the
- 2:14big ideas and motivation behind the
- 2:15article by Cloudflare called a code
- 2:17mode, the better way to use MCP, where
- 2:19they basically say it turns out we've
- 2:21all been using MCP wrong. And
- 2:22essentially they were like, okay, what
- 2:24if instead of our MCP servers having
- 2:26like a thousand different tools, each of
- 2:28them being called one at a time and then
- 2:30being passed by the context window, we
- 2:32had a single execute tool instead?
- 2:34Whereby since the models are already
- 2:36really good at writing code, they can
- 2:37combine many different tools together
- 2:39inside of a bit of code whereby the MCP
- 2:42tools are actually functions. So you can
- 2:45chain many different MCP tools together
- 2:47inside of a single execute tool. And
- 2:49then a couple of months later,
- 2:50Cloudflare applied this idea to their
- 2:52own MCP server whereby they managed to
- 2:54reduce the number of tools from 2,600
- 2:57costing 1.1 million tokens to two tools
- 3:00costing 1,000 tokens. So if you install
- 3:02the Cloudflare MCP server inside Cloud
- 3:04Code, then you would see that it only
- 3:06has a search tool and a execute tool.
- 3:09And the search tool allows Cloud Code to
- 3:11search across the 2,600 tools that
- 3:13Cloudflare has available and the execute
- 3:15tool allows it to combine the relevant
- 3:17ones. And when it comes to executing,
- 3:19Cloud will find the relevant tools,
- 3:21write a bit of code whereby the tools
- 3:23are essentially functions, and then this
- 3:25bit of code would run inside of a
- 3:27sandbox that Cloudflare has on their
- 3:29servers and it would pass the final
- 3:31result back to you. Now this means that
- 3:32we can chain many different tools
- 3:34together really efficiently. So then a
- 3:36bunch of companies that offer a lot of
- 3:37tools inside of their MCP servers, kind
- 3:40of like Datadog, started using this idea
- 3:42as well, replacing all of their MCP
- 3:44tools with just two of them. But now we
- 3:46kind of have a problem whereby some MCP
- 3:48servers offer a server-side code mode
- 3:50that runs inside of a sandbox. Some
- 3:52don't offer any code mode and it would
- 3:54be much better if we had some kind of
- 3:55client-side code mode that spanned
- 3:57across every single MCP server that we
- 3:59have installed. So that means you could
- 4:01have the Stripe MCP, Post-doc MCP,
- 4:03Superbase, and a bunch more, and then
- 4:06your agent would be able to do a single
- 4:08execute tool call that combines data
- 4:10from all of the sources in some kind of
- 4:12way without any intermediate results
- 4:14entering the main conversation. And this
- 4:16idea of a client-side code mode that
- 4:18spans across all MCP servers was then
- 4:20implemented in a bunch of different
- 4:22harnesses, but it was never really
- 4:23implemented inside of Cloud Code. So
- 4:25then what a bunch of people did instead
- 4:27is they used a MCP gateway kind of like
- 4:30executor.sh, whereby you can then
- 4:32basically connect all of your MCP
- 4:33servers to it kind of like this, and
- 4:35then executor would act as its own MCP
- 4:38server with a code mode that spans
- 4:40across all the MCP servers that you have
- 4:41connected. Now I don't really recommend
- 4:43many tools in channel, but I actually
- 4:45really like this one, especially because
- 4:47you can self-host it. So I have it
- 4:48self-hosted over here with over 33 MCP
- 4:51servers connected. And one of the nice
- 4:52things is you can kind of make these
- 4:54connection packages whereby you can give
- 4:56different people on the team access to a
- 4:58different set of MCP servers. Now just
- 5:00to show you what this looks like, if I
- 5:01go to /mcp inside of Cloud Code, go over
- 5:04here, this is my own self-hosted version
- 5:06of executor. Go to view tools, I have a
- 5:08search tool and then a execute tool. And
- 5:11this execute tool would allow Cloud Code
- 5:13to write some JavaScript that basically
- 5:15combines many of the tools I have
- 5:17connected to my executor.sh, and then it
- 5:19runs on the server and passes the
- 5:20results back to Cloud. But in this case,
- 5:22we have code mode only for MCP servers.
- 5:25Now then what some companies did,
- 5:26including Infratopik, they thought to
- 5:28themselves, what if instead of having
- 5:29code mode across only the MCP servers,
- 5:32we had it across every single tool that
- 5:34we have in the harness? So the normal
- 5:36tools like read, write, edit, bash would
- 5:39all be behind code mode as well in
- 5:41addition to all of the harness level
- 5:42tools. And that is essentially what code
- 5:44mode inside of Cloud Code now does. Now
- 5:46I want to go through the setup inside of
- 5:47Cloud Code before explaining further. So
- 5:49you want to copy over this command over
- 5:51here. It will be down below as well. And
- 5:52then go over to your terminal and then
- 5:54paste in the command. Now in this case,
- 5:56it gives me a warning saying that it's
- 5:57not enabled because I have to disable
- 5:59one of my mods that are using Cloud Code
- 6:01hooks. So I'm going to copy this message
- 6:03and then basically paste it in here and
- 6:04say, what mod is this? And then it'll
- 6:07ask you to disable the irrelevant mod
- 6:08and then try again. And then after you
- 6:10disable the irrelevant mods, you will
- 6:12get a message kind of like this saying
- 6:13that code mode is now enabled. So if you
- 6:15say you what tools do you have, then it
- 6:18will say that it has only two tools,
- 6:20which is a REPL and a poll. So I will be
- 6:23explaining them in just a second. And I
- 6:25can see this in action when it comes to
- 6:26normal data analysis or when it comes to
- 6:28coding because I can say something like
- 6:30combining the stripe data with the post
- 6:32hoc data, can you write a HTML file
- 6:34showing me the highest lifetime value
- 6:36customers and where they came from? And
- 6:38then if I press control O, then you can
- 6:40basically see that it's writing some
- 6:41code over here. And if I press click to
- 6:43show, this is what it kind of looks like
- 6:45over here. So you can see that it's
- 6:46writing some JavaScript in some kind of
- 6:48while loop to find all the relevant
- 6:50customers. And this is another example
- 6:52where it's able to do things much more
- 6:54efficiently and make better use of the
- 6:56context window. So what exactly is this
- 6:58REPL? It stands for read evaluate print
- 7:01loop and it's basically a JavaScript
- 7:03console that Claude is writing code into
- 7:05that stays open for the entire session.
- 7:07So all the previous tools such as a bash
- 7:09tool, read, edit, web fetch, MCP calls
- 7:12are now functions that can be called
- 7:14inside of this REPL tool. And one of the
- 7:16nice things about this client-side code
- 7:18mode is that because it's a long-running
- 7:20JavaScript session, Claude could define
- 7:22a variable inside of a earlier REPL that
- 7:25a later REPL can then use to kind of
- 7:27loop over and filter. And this is not
- 7:29possible with server-side code mode kind
- 7:31of like we see on Cloudflare or executed
- 7:33.sh. Now because everything that Claude
- 7:35is writing into this REPL tool is code,
- 7:38it can do everything code is good at
- 7:40like looping over hundreds of files,
- 7:42running a bunch of tool calls in
- 7:43parallel, removing any duplicates,
- 7:45filtering down stuff to just rows that
- 7:47matter. And this can all be done before
- 7:48anything comes back into a context
- 7:50window, thereby saving on context and
- 7:52also round trips. And this is really
- 7:54helpful for any badly designed MCP
- 7:56servers that end up pretending way too
- 7:58much stuff back into a context window
- 8:00because then Claude can assign any
- 8:01results over to a variable, preview a
- 8:03bit of that variable, and then run some
- 8:05more code against that variable all
- 8:07whilst having very little come back into
- 8:08the context window. Now some of you may
- 8:10be thinking, okay, couldn't Claude
- 8:12already just write a bash script to
- 8:13achieve some of this? And whilst it
- 8:15could, it would not have access to all
- 8:17the harness level tools kind of like any
- 8:19MCP servers or spawning sub agents, but
- 8:22code mode gives it that wider access.
- 8:24Now the second tool that Claude has is
- 8:25poll. So some of these scripts may be
- 8:27running for a really long time because
- 8:29it's looping for a bunch of data and if
- 8:31a script ends up running for too long,
- 8:33then it basically detaches, goes into
- 8:34background and then Claude can use a
- 8:36poll to check up on it. Now when code
- 8:38mode first appeared in the binary about
- 8:3911 days ago, I basically had my agent do
- 8:41a whole bunch of experimentation with
- 8:43and without code mode by solving real
- 8:45issues on real open source projects and
- 8:47I basically found that having code mode
- 8:49enabled used about half of the input
- 8:50tokens and came to 71% of the total cost
- 8:54of normal mode. So we're basically
- 8:55saving that 30%. Now we already kind of
- 8:57seeing this happening outside of
- 8:58Anthropic. So for example, recently
- 9:00Browser use deleted about 90% of their
- 9:02old library and now their agent just
- 9:04writes a Python repl on their raw Chrome
- 9:07Devs protocol and this means that for
- 9:08the same models, it's up to 50% better
- 9:11whilst being two to five times cheaper
- 9:13and also being faster as well. And
- 9:15there's another example here of someone
- 9:17giving Opus 5.5 a single Python repl
- 9:20kind of like Prime agent and they found
- 9:22that normal Claude code without code
- 9:24mode gets 65% on terminal bench, whereas
- 9:26with their repl it gets 71% instead
- 9:29whilst costing a tiny bit less per task
- 9:31too. Now a pretty nice article for
- 9:33thinking about where these performance
- 9:34gains are coming from is this one by
- 9:36Alex Zhang from MIT who did a whole
- 9:38bunch of work on recursive language
- 9:40models, which we'll talk more about at
- 9:41the end of the video. But in this
- 9:43article that I recommend reading called
- 9:44the Mismanaged Genius Hypothesis, he
- 9:46says that a lot of the limitations of
- 9:48the models today come from the ways in
- 9:50which we use them and not the inherent
- 9:52capabilities of the models. And his main
- 9:54point is basically if we learn how to
- 9:55manage these models better, then they
- 9:57could already solve a much wider range
- 9:59of tasks than before and I think that
- 10:01code mode is a pretty good example of
- 10:03that because it's already giving a very
- 10:05capable model a lot more freedom. Now
- 10:07where I think the video gets pretty
- 10:08interesting is that inside of code mode,
- 10:10they're going to be adding three
- 10:11additional functions called spawn
- 10:13context, list context, and release
- 10:15context. And this appeared in the binary
- 10:17the same time code mode was added but
- 10:19has not been released yet. So basically
- 10:21it looks like sub agents are now being
- 10:23turned into contexts and they can be
- 10:25triggered programmatically and be
- 10:27combined programmatically kind of like
- 10:29dynamic workflows. Now if you have seen
- 10:31my dynamic workflows video when they
- 10:32were first announced then this should
- 10:34feel very familiar because we can
- 10:35basically wrap sub agents with code to
- 10:38coordinate even more sub agents than
- 10:39before without the main context window
- 10:42filling up. But one of the differences
- 10:43is that if we spawn a context inside of
- 10:46the repl then we have the option of
- 10:48forking the main conversation which
- 10:49means that cloud code could do something
- 10:51kind of like if you asked it to make it
- 10:53faster then it could fork the main
- 10:55conversation five or 10 times, explore a
- 10:58bunch of different approaches and then
- 10:59only return the top three approaches
- 11:02that sped it up the most back to the
- 11:03main conversation. We also have a
- 11:05difference whereby any other sub agents
- 11:06are spawned can talk to the main
- 11:08coordinator if they want to which isn't
- 11:10really possible with a dynamic workflow
- 11:12either. There are a bunch of small
- 11:13differences as well but it may be likely
- 11:15that they combine both of them together
- 11:17in some way. Now for the astute among
- 11:19you or the ones who really like to stay
- 11:21at the edge of all this you may be
- 11:22thinking to yourself hold on this is
- 11:24starting to look like a recursive
- 11:25language model and this is the same idea
- 11:28that Alex Zang had at MIT inside of his
- 11:30pretty popular paper from December of
- 11:32last year. And basically he said that
- 11:33for a RLM recursive language model the
- 11:36three things that have to come together.
- 11:38The first is a repl that persists
- 11:40between different calls and we've seen
- 11:42this in cloud code so far with the repl
- 11:43tool whereby cloud can define a variable
- 11:46and that variable can be used in another
- 11:47repl. The second is sub agents that get
- 11:50called from inside of a repl so your
- 11:53code can launch them and manage them
- 11:54which means that if the repl were to
- 11:56read like 20 different files we could
- 11:58quickly launch 20 different sub agents
- 12:01and this maybe added to cloud code soon
- 12:03with the free different context tools
- 12:04that we mentioned. And the third thing
- 12:06for a RLM is that your prompt has to
- 12:08live inside of a variable so the model
- 12:11never actually has to read all of it,
- 12:13and instead can just write code over
- 12:14your prompts. So basically it seems that
- 12:16we're going to have two of the three,
- 12:17but the missing piece here is a third.
- 12:19So what exactly does a third one mean?
- 12:21So right now if you were to paste in a
- 12:23prompt of 2 million tokens into Claude
- 12:25Code, then it would quickly fill up the
- 12:27context window, whereas in a RLM, Claude
- 12:30would be told something like, hey,
- 12:31there's a prompt of this length for 2
- 12:33million tokens that's sitting inside of
- 12:35this variable, and then Claude can use
- 12:37code to kind of figure out what to do
- 12:39with it. By cutting up the variable into
- 12:41different parts, it may hand it over to
- 12:42different sub agents and do a bunch of
- 12:44stuff with it. So this means that Claude
- 12:46would be able to work with much larger
- 12:47prompts than it can do today. And the
- 12:49exact same thing here goes for the
- 12:50conversation history. Now we know that
- 12:52we still have some kind of compaction,
- 12:54and compaction whilst it is getting
- 12:55better, can still be a bit bad. It'd be
- 12:58much better if the model can manage its
- 12:59own context window. So if we define the
- 13:01conversation history as a variable and
- 13:04then allow Claude to manipulate the
- 13:05variable and also slice and cut anything
- 13:08from it, it would mean that if Claude
- 13:09notices that the context window is
- 13:11filling up, then it can simply delete
- 13:13something from the context window
- 13:14earlier on. So this means that if it
- 13:15kind of saw a bunch of noisy tool calls
- 13:17that weren't really relevant to the
- 13:19conversation anymore, then it could
- 13:20basically replace them with something
- 13:22much shorter or just delete them
- 13:24instead. And this would kind of mean
- 13:25that we no longer need compaction
- 13:27because the model can just decide what
- 13:29to remove and replace inside of a
- 13:31context window. But now one of the
- 13:32problems can be that we end up breaking
- 13:34the prompt cache. And there's a pretty
- 13:36good research paper by Meta about this
- 13:39called context language models where
- 13:40they talk about having a prefix cache
- 13:42and a suffix cache of the part where we
- 13:45actually changed. I won't really go into
- 13:47this. I think this deserves its own
- 13:48video, but it will be linked down below
- 13:50if you do want to read it. Now in public
- 13:52do kind of have something like this
- 13:53inside of their API called context
- 13:55editing. So I think they're kind of
- 13:57interested in this idea as well. But of
- 13:58course they do mention that it breaks
- 14:00the cache and they kind of want to
- 14:01evaluate the cost benefit of removing
- 14:03something from the context window if it
- 14:05is breaking the cache for the next time.
- 14:07So maybe in 2027 they will allow the
- 14:09Repl to treat the prompts that you put
- 14:11in Claude Code as a variable and also
- 14:13the conversation history. Now if they
- 14:15were to add and I don't think it'd get
- 14:17fully there, Alex Zheng also makes a
- 14:18point that RLMs only really begin to
- 14:20work once a model is post-trained around
- 14:23them. So if Anthropic were to train Opus
- 14:256 or Opus 7 inside of its new version of
- 14:28Claude Code where it can manage
- 14:30sub-agents from a REPL and also the
- 14:32context window and prompts, then this
- 14:33whole code mode thing would be even more
- 14:35powerful and it would mean that Claude
- 14:36can do even more ambitious work for
- 14:38cheaper. So it may be the case that over
- 14:40time Claude becomes some kind of RLM.
- 14:43Now if you do like this kind of stuff,
- 14:44then you may want to join my email
- 14:45newsletter because there are a bunch of
- 14:47ideas that I share inside of here that
- 14:49don't quite make it onto YouTube but are
- 14:50still very helpful. There will also be a
- 14:52link down below for those interested.
About this transcript
This page contains the full transcript of Code Mode Makes Claude Code Smarter & Cheaper by Ray Amjad, generated from the public captions YouTube serves with the video. The transcript has 3,401 words across 472 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.