Ray Amjad on Code Mode in Claude Code
videoRay Amjad · 15 min · Nov 16, 2026 · youtu.be · Saved Nov 19, 2026
code mode, claude code
Description
🔥 Black Friday Offer: https://www.agenticcoding.school/black-friday?v=DRNbxPk9Ab8
✉️ My newsletter 👉 https://www.agenticcoding.school/newsletter?v=DRNbxPk9Ab8
To keep my takes honest, I've never accepted a sponsor. My videos are made possible by the following...
—— CLASSES ——
🚀 My cohort: https://www.agenticcoding.school/cohort?v=DRNbxPk9Ab8
🚃 Train Your Engineering Team: https://www.agenticcoding.school/company-training?v=DRNbxPk9Ab8
—— PRODUCTS FROM MY HOLDCO ——
We mostly sell to enterprises but here are a few...
🧑🤝🧑 Selves, your customers, simulated: https://www.selves.dev/?utm_source=youtube&utm_campaign=DRNbxPk9Ab8
📦 Impello AI, low-cost high-performance sandboxes for your agents: https://www.impello.ai/?utm_source=youtube&utm_campaign=DRNbxPk9Ab8
💬 AgentStack, create customer experience agents: https://www.agentstack.build/?utm_source=youtube&utm_campaign=DRNbxPk9Ab8
—————
CONNECT WITH ME
🐦 X: https://x.com/rayamjad
👥 LinkedIn: https://www.linkedin.com/in/rayamjad/
📸 Instagram: https://www.instagram.com/theramjad/
🌍 My website/blog: https://www.rayamjad.com/
—————
Turn on Code Mode (Claude Code 2.1.323 or later):
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 claude
The documentation: https://code.claude.com/docs/en/code-mode
Cloudflare, Code Mode: the better way to use MCP: https://blog.cloudflare.com/code-mode/
Cloudflare, Code Mode MCP server (2,600 tools in 2): https://blog.cloudflare.com/code-mode-mcp/
Executor: https://executor.sh/
Browser Use 1.0: https://x.com/browser_use/status/2119983662162952278
Unharnessed tweet: https://x.com/RayaneRachid_/status/2122024268368380148
Prime Agent: https://github.com/PrimeIntellect-ai/prime-agent
The Mismanaged Geniuses Hypothesis (Alex Zhang): https://alexzhang13.github.io/blog/2026/mgh/
My dynamic workflows video: https://www.youtube.com/watch?v=c0gVowvMR-g
Recursive Language Models paper: https://arxiv.org/abs/2512.24601
Context Language Models (Meta): https://arxiv.org/html/2609.37725
Anthropic context editing: https://platform.claude.com/docs/en/build-with-claude/context-editing
Timestamps:
0:00 Intro
0:50 The problem with normal tool calls
2:13 Cloudflare's Code Mode
3:45 Server-side vs client-side code mode
5:22 Code Mode in Claude Code
5:46 How to turn it on
6:54 What is the REPL?
8:09 Why not just a bash script?
8:24 The Poll tool
8:37 My results: about 30% cheaper
10:06 Contexts: what's coming next
11:17 Recursive language models
14:07 Where this is heading
Transcript
Intro
0:00 Okay, so Anthropic just added something that makes Cloud Code smarter whilst also being cheaper for the same model, and that is by rewriting a decent chunk of the harness in a feature called code mode. So I basically want to go through what exactly that is in this video because I think it follows a trend that we're seeing more and more whereby the model is swallowing the harness, and I think that this is a pretty good example of that. Now do you want to mention that this concept has been around for over one year and this Cloudflare article kind of popularized it and it has been implemented to varying degrees inside of different harnesses like Codex, OpenAI, Prime Agent, but in this video I want to focus on Cloud Code's implementation because I like talking about Cloud Code.
0:36 As a really short aside, I will be doing a Black Friday deal this year, so if you want to be the first to hear about it, then there will be a link down below. Now if you already know what code mode is and you want to know how Cloud Code implemented it, then you can skip to a timestamp on the screen right now, but if you don't know what it is, then I'm basically going to explain that. So
The problem with normal tool calls
0:50 because I like to explain things problem first, solution second, I want to give some motivation for why code mode even matters. So right now many harnesses are a bunch of separate tools like read, edit, bash, web fetch with some other things attached, and the model is just basically looping through these tools until it decides it's done. Now this is fine and all, but it becomes a problem when your agent is connected to dozens of tools, specifically MCP servers, each of which can have dozens of tools inside because if your agent now wants to chain many different tools together from different MCP servers, then it has to pass the result of each one through the context window. So for example, you may do one tool call to pull in some data from the Stripe MCP server and then that would go into the context window and
1:31 then the model will decide, okay, I'm going to do this other tool call to pull in some data from like Cloudflare. That would go inside and then it may combine the data in some way with a script and then pass it to another MCP server. Now the problem is that the output of every tool call is just sitting inside of the context window. So the next time a tool is called, the model rereads the entire conversation and this can continue over and over again. And even though these tokens are cashed and they're charged at 10% of the usual rate, you're still needlessly paying for things that shouldn't have to inside of the context window. So it would be much better if the model, instead of doing many different tool calls and using the context window as a intermediary, could pass a result of one tool call directly
2:10 to next one without it ever entering the context window. And that was one of the
Cloudflare's Code Mode
2:14 big ideas and motivation behind the article by Cloudflare called a code mode, the better way to use MCP, where they basically say it turns out we've all been using MCP wrong. And essentially they were like, okay, what if instead of our MCP servers having like a thousand different tools, each of them being called one at a time and then being passed by the context window, we had a single execute tool instead?
2:34 Whereby since the models are already really good at writing code, they can combine many different tools together inside of a bit of code whereby the MCP tools are actually functions. So you can chain many different MCP tools together inside of a single execute tool. And then a couple of months later, Cloudflare applied this idea to their own MCP server whereby they managed to reduce the number of tools from 2,600 costing 1.1 million tokens to two tools costing 1,000 tokens. So if you install the Cloudflare MCP server inside Cloud Code, then you would see that it only has a search tool and a execute tool.
3:09 And the search tool allows Cloud Code to search across the 2,600 tools that Cloudflare has available and the execute tool allows it to combine the relevant ones. And when it comes to executing, Cloud will find the relevant tools, write a bit of code whereby the tools are essentially functions, and then this bit of code would run inside of a sandbox that Cloudflare has on their servers and it would pass the final result back to you. Now this means that we can chain many different tools together really efficiently. So then a bunch of companies that offer a lot of tools inside of their MCP servers, kind of like Datadog, started using this idea as well, replacing all of their MCP tools with just two of them. But now we
Server-side vs client-side code mode
3:46 kind of have a problem whereby some MCP servers offer a server-side code mode that runs inside of a sandbox. Some don't offer any code mode and it would be much better if we had some kind of client-side code mode that spanned across every single MCP server that we have installed. So that means you could have the Stripe MCP, Post-doc MCP, Superbase, and a bunch more, and then your agent would be able to do a single execute tool call that combines data from all of the sources in some kind of way without any intermediate results entering the main conversation. And this idea of a client-side code mode that spans across all MCP servers was then implemented in a bunch of different harnesses, but it was never really implemented inside of Cloud Code. So then what a bunch of people did instead is they used a MCP gateway kind of like
4:30 executor.sh, whereby you can then basically connect all of your MCP servers to it kind of like this, and then executor would act as its own MCP server with a code mode that spans across all the MCP servers that you have connected. Now I don't really recommend many tools in channel, but I actually really like this one, especially because you can self-host it. So I have it self-hosted over here with over 33 MCP servers connected. And one of the nice things is you can kind of make these connection packages whereby you can give different people on the team access to a different set of MCP servers. Now just to show you what this looks like, if I go to /mcp inside of Cloud Code, go over here, this is my own self-hosted version of executor. Go to view tools, I have a search tool and then a execute tool. And
5:11 this execute tool would allow Cloud Code to write some JavaScript that basically combines many of the tools I have connected to my executor.sh, and then it runs on the server and passes the results back to Cloud. But in this case,
Code Mode in Claude Code
5:22 we have code mode only for MCP servers. Now then what some companies did, including Infratopik, they thought to themselves, what if instead of having code mode across only the MCP servers, we had it across every single tool that we have in the harness? So the normal tools like read, write, edit, bash would all be behind code mode as well in addition to all of the harness level tools. And that is essentially what code mode inside of Cloud Code now does. Now
How to turn it on
5:46 I want to go through the setup inside of Cloud Code before explaining further. So you want to copy over this command over here. It will be down below as well. And then go over to your terminal and then paste in the command. Now in this case, it gives me a warning saying that it's not enabled because I have to disable one of my mods that are using Cloud Code hooks. So I'm going to copy this message and then basically paste it in here and say, what mod is this? And then it'll ask you to disable the irrelevant mod and then try again. And then after you disable the irrelevant mods, you will get a message kind of like this saying that code mode is now enabled. So if you say you what tools do you have, then it will say that it has only two tools,
6:20 which is a REPL and a poll. So I will be explaining them in just a second. And I can see this in action when it comes to normal data analysis or when it comes to coding because I can say something like combining the stripe data with the post hoc data, can you write a HTML file showing me the highest lifetime value customers and where they came from? And then if I press control O, then you can basically see that it's writing some code over here. And if I press click to show, this is what it kind of looks like over here. So you can see that it's writing some JavaScript in some kind of while loop to find all the relevant customers. And this is another example where it's able to do things much more efficiently and make better use of the
What is the REPL?
6:56 context window. So what exactly is this REPL? It stands for read evaluate print loop and it's basically a JavaScript console that Claude is writing code into that stays open for the entire session. So all the previous tools such as a bash tool, read, edit, web fetch, MCP calls are now functions that can be called inside of this REPL tool. And one of the nice things about this client-side code mode is that because it's a long-running JavaScript session, Claude could define a variable inside of a earlier REPL that a later REPL can then use to kind of loop over and filter. And this is not possible with server-side code mode kind of like we see on Cloudflare or executed .sh. Now because everything that Claude is writing into this REPL tool is code, it can do everything code is good at like looping over hundreds of files,
7:42 running a bunch of tool calls in parallel, removing any duplicates, filtering down stuff to just rows that matter. And this can all be done before anything comes back into a context window, thereby saving on context and also round trips. And this is really helpful for any badly designed MCP servers that end up pretending way too much stuff back into a context window because then Claude can assign any results over to a variable, preview a bit of that variable, and then run some more code against that variable all whilst having very little come back into the context window. Now some of you may
Why not just a bash script?
8:10 be thinking, okay, couldn't Claude already just write a bash script to achieve some of this? And whilst it could, it would not have access to all the harness level tools kind of like any MCP servers or spawning sub agents, but code mode gives it that wider access.
The Poll tool
8:24 Now the second tool that Claude has is poll. So some of these scripts may be running for a really long time because it's looping for a bunch of data and if a script ends up running for too long, then it basically detaches, goes into background and then Claude can use a poll to check up on it. Now when code
My results: about 30% cheaper
8:38 mode first appeared in the binary about 11 days ago, I basically had my agent do a whole bunch of experimentation with and without code mode by solving real issues on real open source projects and I basically found that having code mode enabled used about half of the input tokens and came to 71% of the total cost of normal mode. So we're basically saving that 30%. Now we already kind of seeing this happening outside of Anthropic. So for example, recently Browser use deleted about 90% of their old library and now their agent just writes a Python repl on their raw Chrome Devs protocol and this means that for the same models, it's up to 50% better whilst being two to five times cheaper and also being faster as well. And there's another example here of someone giving Opus 5.5 a single Python repl kind of like Prime agent and they found
9:21 that normal Claude code without code mode gets 65% on terminal bench, whereas with their repl it gets 71% instead whilst costing a tiny bit less per task too. Now a pretty nice article for thinking about where these performance gains are coming from is this one by Alex Zhang from MIT who did a whole bunch of work on recursive language models, which we'll talk more about at the end of the video. But in this article that I recommend reading called the Mismanaged Genius Hypothesis, he says that a lot of the limitations of the models today come from the ways in which we use them and not the inherent capabilities of the models. And his main point is basically if we learn how to manage these models better, then they could already solve a much wider range of tasks than before and I think that code mode is a pretty good example of
10:02 that because it's already giving a very capable model a lot more freedom. Now
Contexts: what's coming next
10:06 where I think the video gets pretty interesting is that inside of code mode, they're going to be adding three additional functions called spawn context, list context, and release context. And this appeared in the binary the same time code mode was added but has not been released yet. So basically it looks like sub agents are now being turned into contexts and they can be triggered programmatically and be combined programmatically kind of like dynamic workflows. Now if you have seen my dynamic workflows video when they were first announced then this should feel very familiar because we can basically wrap sub agents with code to coordinate even more sub agents than before without the main context window filling up. But one of the differences is that if we spawn a context inside of the repl then we have the option of forking the main conversation which means that cloud code could do something
10:51 kind of like if you asked it to make it faster then it could fork the main conversation five or 10 times, explore a bunch of different approaches and then only return the top three approaches that sped it up the most back to the main conversation. We also have a difference whereby any other sub agents are spawned can talk to the main coordinator if they want to which isn't really possible with a dynamic workflow either. There are a bunch of small differences as well but it may be likely that they combine both of them together
Recursive language models
11:17 in some way. Now for the astute among you or the ones who really like to stay at the edge of all this you may be thinking to yourself hold on this is starting to look like a recursive language model and this is the same idea that Alex Zang had at MIT inside of his pretty popular paper from December of last year. And basically he said that for a RLM recursive language model the three things that have to come together.
11:38 The first is a repl that persists between different calls and we've seen this in cloud code so far with the repl tool whereby cloud can define a variable and that variable can be used in another repl. The second is sub agents that get called from inside of a repl so your code can launch them and manage them which means that if the repl were to read like 20 different files we could quickly launch 20 different sub agents and this maybe added to cloud code soon with the free different context tools that we mentioned. And the third thing for a RLM is that your prompt has to live inside of a variable so the model never actually has to read all of it, and instead can just write code over your prompts. So basically it seems that we're going to have two of the three, but the missing piece here is a third.
12:19 So what exactly does a third one mean? So right now if you were to paste in a prompt of 2 million tokens into Claude Code, then it would quickly fill up the context window, whereas in a RLM, Claude would be told something like, hey, there's a prompt of this length for 2 million tokens that's sitting inside of this variable, and then Claude can use code to kind of figure out what to do with it. By cutting up the variable into different parts, it may hand it over to different sub agents and do a bunch of stuff with it. So this means that Claude would be able to work with much larger prompts than it can do today. And the exact same thing here goes for the conversation history. Now we know that we still have some kind of compaction, and compaction whilst it is getting
12:55 better, can still be a bit bad. It'd be much better if the model can manage its own context window. So if we define the conversation history as a variable and then allow Claude to manipulate the variable and also slice and cut anything from it, it would mean that if Claude notices that the context window is filling up, then it can simply delete something from the context window earlier on. So this means that if it kind of saw a bunch of noisy tool calls that weren't really relevant to the conversation anymore, then it could basically replace them with something much shorter or just delete them instead. And this would kind of mean that we no longer need compaction because the model can just decide what to remove and replace inside of a context window. But now one of the problems can be that we end up breaking
13:34 the prompt cache. And there's a pretty good research paper by Meta about this called context language models where they talk about having a prefix cache and a suffix cache of the part where we actually changed. I won't really go into this. I think this deserves its own video, but it will be linked down below if you do want to read it. Now in public do kind of have something like this inside of their API called context editing. So I think they're kind of interested in this idea as well. But of course they do mention that it breaks the cache and they kind of want to evaluate the cost benefit of removing something from the context window if it is breaking the cache for the next time.
Where this is heading
14:07 So maybe in 2027 they will allow the Repl to treat the prompts that you put in Claude Code as a variable and also the conversation history. Now if they were to add and I don't think it'd get fully there, Alex Zheng also makes a point that RLMs only really begin to work once a model is post-trained around them. So if Anthropic were to train Opus 6 or Opus 7 inside of its new version of Claude Code where it can manage sub-agents from a REPL and also the context window and prompts, then this whole code mode thing would be even more powerful and it would mean that Claude can do even more ambitious work for cheaper. So it may be the case that over time Claude becomes some kind of RLM.
14:43 Now if you do like this kind of stuff, then you may want to join my email newsletter because there are a bunch of ideas that I share inside of here that don't quite make it onto YouTube but are still very helpful. There will also be a link down below for those interested.