YouTube2Text

Code Mode Makes Claude Code Smarter & Cheaper — Transcript

by Ray Amjad · 3,401 words · 472 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Okay, so Anthropic just added something
  2. 0:01that makes Cloud Code smarter whilst
  3. 0:04also being cheaper for the same model,
  4. 0:06and that is by rewriting a decent chunk
  5. 0:08of the harness in a feature called code
  6. 0:10mode. So I basically want to go through
  7. 0:11what exactly that is in this video
  8. 0:13because I think it follows a trend that
  9. 0:14we're seeing more and more whereby the
  10. 0:15model is swallowing the harness, and I
  11. 0:18think that this is a pretty good example
  12. 0:19of that. Now do you want to mention that
  13. 0:20this concept has been around for over
  14. 0:22one year and this Cloudflare article
  15. 0:24kind of popularized it and it has been
  16. 0:26implemented to varying degrees inside of
  17. 0:28different harnesses like Codex, OpenAI,
  18. 0:31Prime Agent, but in this video I want to
  19. 0:33focus on Cloud Code's implementation
  20. 0:35because I like talking about Cloud Code.
  21. 0:36As a really short aside, I will be doing
  22. 0:38a Black Friday deal this year, so if you
  23. 0:40want to be the first to hear about it,
  24. 0:41then there will be a link down below.
  25. 0:42Now if you already know what code mode
  26. 0:43is and you want to know how Cloud Code
  27. 0:45implemented it, then you can skip to a
  28. 0:46timestamp on the screen right now, but
  29. 0:48if you don't know what it is, then I'm
  30. 0:49basically going to explain that. So
  31. 0:50because I like to explain things problem
  32. 0:52first, solution second, I want to give
  33. 0:54some motivation for why code mode even
  34. 0:56matters. So right now many harnesses are
  35. 0:59a bunch of separate tools like read,
  36. 1:01edit, bash, web fetch with some other
  37. 1:03things attached, and the model is just
  38. 1:05basically looping through these tools
  39. 1:06until it decides it's done. Now this is
  40. 1:08fine and all, but it becomes a problem
  41. 1:09when your agent is connected to dozens
  42. 1:11of tools, specifically MCP servers, each
  43. 1:14of which can have dozens of tools inside
  44. 1:16because if your agent now wants to chain
  45. 1:18many different tools together from
  46. 1:20different MCP servers, then it has to
  47. 1:22pass the result of each one through the
  48. 1:24context window. So for example, you may
  49. 1:26do one tool call to pull in some data
  50. 1:28from the Stripe MCP server and then that
  51. 1:30would go into the context window and
  52. 1:31then the model will decide, okay, I'm
  53. 1:33going to do this other tool call to pull
  54. 1:34in some data from like Cloudflare. That
  55. 1:36would go inside and then it may combine
  56. 1:38the data in some way with a script and
  57. 1:40then pass it to another MCP server. Now
  58. 1:43the problem is that the output of every
  59. 1:44tool call is just sitting inside of the
  60. 1:46context window. So the next time a tool
  61. 1:48is called, the model rereads the entire
  62. 1:50conversation and this can continue over
  63. 1:52and over again. And even though these
  64. 1:54tokens are cashed and they're charged at
  65. 1:5610% of the usual rate, you're still
  66. 1:58needlessly paying for things that
  67. 1:59shouldn't have to inside of the context
  68. 2:01window. So it would be much better if
  69. 2:02the model, instead of doing many
  70. 2:04different tool calls and using the
  71. 2:05context window as a intermediary, could
  72. 2:08pass a result of one tool call directly
  73. 2:10to next one without it ever entering the
  74. 2:12context window. And that was one of the
  75. 2:14big ideas and motivation behind the
  76. 2:15article by Cloudflare called a code
  77. 2:17mode, the better way to use MCP, where
  78. 2:19they basically say it turns out we've
  79. 2:21all been using MCP wrong. And
  80. 2:22essentially they were like, okay, what
  81. 2:24if instead of our MCP servers having
  82. 2:26like a thousand different tools, each of
  83. 2:28them being called one at a time and then
  84. 2:30being passed by the context window, we
  85. 2:32had a single execute tool instead?
  86. 2:34Whereby since the models are already
  87. 2:36really good at writing code, they can
  88. 2:37combine many different tools together
  89. 2:39inside of a bit of code whereby the MCP
  90. 2:42tools are actually functions. So you can
  91. 2:45chain many different MCP tools together
  92. 2:47inside of a single execute tool. And
  93. 2:49then a couple of months later,
  94. 2:50Cloudflare applied this idea to their
  95. 2:52own MCP server whereby they managed to
  96. 2:54reduce the number of tools from 2,600
  97. 2:57costing 1.1 million tokens to two tools
  98. 3:00costing 1,000 tokens. So if you install
  99. 3:02the Cloudflare MCP server inside Cloud
  100. 3:04Code, then you would see that it only
  101. 3:06has a search tool and a execute tool.
  102. 3:09And the search tool allows Cloud Code to
  103. 3:11search across the 2,600 tools that
  104. 3:13Cloudflare has available and the execute
  105. 3:15tool allows it to combine the relevant
  106. 3:17ones. And when it comes to executing,
  107. 3:19Cloud will find the relevant tools,
  108. 3:21write a bit of code whereby the tools
  109. 3:23are essentially functions, and then this
  110. 3:25bit of code would run inside of a
  111. 3:27sandbox that Cloudflare has on their
  112. 3:29servers and it would pass the final
  113. 3:31result back to you. Now this means that
  114. 3:32we can chain many different tools
  115. 3:34together really efficiently. So then a
  116. 3:36bunch of companies that offer a lot of
  117. 3:37tools inside of their MCP servers, kind
  118. 3:40of like Datadog, started using this idea
  119. 3:42as well, replacing all of their MCP
  120. 3:44tools with just two of them. But now we
  121. 3:46kind of have a problem whereby some MCP
  122. 3:48servers offer a server-side code mode
  123. 3:50that runs inside of a sandbox. Some
  124. 3:52don't offer any code mode and it would
  125. 3:54be much better if we had some kind of
  126. 3:55client-side code mode that spanned
  127. 3:57across every single MCP server that we
  128. 3:59have installed. So that means you could
  129. 4:01have the Stripe MCP, Post-doc MCP,
  130. 4:03Superbase, and a bunch more, and then
  131. 4:06your agent would be able to do a single
  132. 4:08execute tool call that combines data
  133. 4:10from all of the sources in some kind of
  134. 4:12way without any intermediate results
  135. 4:14entering the main conversation. And this
  136. 4:16idea of a client-side code mode that
  137. 4:18spans across all MCP servers was then
  138. 4:20implemented in a bunch of different
  139. 4:22harnesses, but it was never really
  140. 4:23implemented inside of Cloud Code. So
  141. 4:25then what a bunch of people did instead
  142. 4:27is they used a MCP gateway kind of like
  143. 4:30executor.sh, whereby you can then
  144. 4:32basically connect all of your MCP
  145. 4:33servers to it kind of like this, and
  146. 4:35then executor would act as its own MCP
  147. 4:38server with a code mode that spans
  148. 4:40across all the MCP servers that you have
  149. 4:41connected. Now I don't really recommend
  150. 4:43many tools in channel, but I actually
  151. 4:45really like this one, especially because
  152. 4:47you can self-host it. So I have it
  153. 4:48self-hosted over here with over 33 MCP
  154. 4:51servers connected. And one of the nice
  155. 4:52things is you can kind of make these
  156. 4:54connection packages whereby you can give
  157. 4:56different people on the team access to a
  158. 4:58different set of MCP servers. Now just
  159. 5:00to show you what this looks like, if I
  160. 5:01go to /mcp inside of Cloud Code, go over
  161. 5:04here, this is my own self-hosted version
  162. 5:06of executor. Go to view tools, I have a
  163. 5:08search tool and then a execute tool. And
  164. 5:11this execute tool would allow Cloud Code
  165. 5:13to write some JavaScript that basically
  166. 5:15combines many of the tools I have
  167. 5:17connected to my executor.sh, and then it
  168. 5:19runs on the server and passes the
  169. 5:20results back to Cloud. But in this case,
  170. 5:22we have code mode only for MCP servers.
  171. 5:25Now then what some companies did,
  172. 5:26including Infratopik, they thought to
  173. 5:28themselves, what if instead of having
  174. 5:29code mode across only the MCP servers,
  175. 5:32we had it across every single tool that
  176. 5:34we have in the harness? So the normal
  177. 5:36tools like read, write, edit, bash would
  178. 5:39all be behind code mode as well in
  179. 5:41addition to all of the harness level
  180. 5:42tools. And that is essentially what code
  181. 5:44mode inside of Cloud Code now does. Now
  182. 5:46I want to go through the setup inside of
  183. 5:47Cloud Code before explaining further. So
  184. 5:49you want to copy over this command over
  185. 5:51here. It will be down below as well. And
  186. 5:52then go over to your terminal and then
  187. 5:54paste in the command. Now in this case,
  188. 5:56it gives me a warning saying that it's
  189. 5:57not enabled because I have to disable
  190. 5:59one of my mods that are using Cloud Code
  191. 6:01hooks. So I'm going to copy this message
  192. 6:03and then basically paste it in here and
  193. 6:04say, what mod is this? And then it'll
  194. 6:07ask you to disable the irrelevant mod
  195. 6:08and then try again. And then after you
  196. 6:10disable the irrelevant mods, you will
  197. 6:12get a message kind of like this saying
  198. 6:13that code mode is now enabled. So if you
  199. 6:15say you what tools do you have, then it
  200. 6:18will say that it has only two tools,
  201. 6:20which is a REPL and a poll. So I will be
  202. 6:23explaining them in just a second. And I
  203. 6:25can see this in action when it comes to
  204. 6:26normal data analysis or when it comes to
  205. 6:28coding because I can say something like
  206. 6:30combining the stripe data with the post
  207. 6:32hoc data, can you write a HTML file
  208. 6:34showing me the highest lifetime value
  209. 6:36customers and where they came from? And
  210. 6:38then if I press control O, then you can
  211. 6:40basically see that it's writing some
  212. 6:41code over here. And if I press click to
  213. 6:43show, this is what it kind of looks like
  214. 6:45over here. So you can see that it's
  215. 6:46writing some JavaScript in some kind of
  216. 6:48while loop to find all the relevant
  217. 6:50customers. And this is another example
  218. 6:52where it's able to do things much more
  219. 6:54efficiently and make better use of the
  220. 6:56context window. So what exactly is this
  221. 6:58REPL? It stands for read evaluate print
  222. 7:01loop and it's basically a JavaScript
  223. 7:03console that Claude is writing code into
  224. 7:05that stays open for the entire session.
  225. 7:07So all the previous tools such as a bash
  226. 7:09tool, read, edit, web fetch, MCP calls
  227. 7:12are now functions that can be called
  228. 7:14inside of this REPL tool. And one of the
  229. 7:16nice things about this client-side code
  230. 7:18mode is that because it's a long-running
  231. 7:20JavaScript session, Claude could define
  232. 7:22a variable inside of a earlier REPL that
  233. 7:25a later REPL can then use to kind of
  234. 7:27loop over and filter. And this is not
  235. 7:29possible with server-side code mode kind
  236. 7:31of like we see on Cloudflare or executed
  237. 7:33.sh. Now because everything that Claude
  238. 7:35is writing into this REPL tool is code,
  239. 7:38it can do everything code is good at
  240. 7:40like looping over hundreds of files,
  241. 7:42running a bunch of tool calls in
  242. 7:43parallel, removing any duplicates,
  243. 7:45filtering down stuff to just rows that
  244. 7:47matter. And this can all be done before
  245. 7:48anything comes back into a context
  246. 7:50window, thereby saving on context and
  247. 7:52also round trips. And this is really
  248. 7:54helpful for any badly designed MCP
  249. 7:56servers that end up pretending way too
  250. 7:58much stuff back into a context window
  251. 8:00because then Claude can assign any
  252. 8:01results over to a variable, preview a
  253. 8:03bit of that variable, and then run some
  254. 8:05more code against that variable all
  255. 8:07whilst having very little come back into
  256. 8:08the context window. Now some of you may
  257. 8:10be thinking, okay, couldn't Claude
  258. 8:12already just write a bash script to
  259. 8:13achieve some of this? And whilst it
  260. 8:15could, it would not have access to all
  261. 8:17the harness level tools kind of like any
  262. 8:19MCP servers or spawning sub agents, but
  263. 8:22code mode gives it that wider access.
  264. 8:24Now the second tool that Claude has is
  265. 8:25poll. So some of these scripts may be
  266. 8:27running for a really long time because
  267. 8:29it's looping for a bunch of data and if
  268. 8:31a script ends up running for too long,
  269. 8:33then it basically detaches, goes into
  270. 8:34background and then Claude can use a
  271. 8:36poll to check up on it. Now when code
  272. 8:38mode first appeared in the binary about
  273. 8:3911 days ago, I basically had my agent do
  274. 8:41a whole bunch of experimentation with
  275. 8:43and without code mode by solving real
  276. 8:45issues on real open source projects and
  277. 8:47I basically found that having code mode
  278. 8:49enabled used about half of the input
  279. 8:50tokens and came to 71% of the total cost
  280. 8:54of normal mode. So we're basically
  281. 8:55saving that 30%. Now we already kind of
  282. 8:57seeing this happening outside of
  283. 8:58Anthropic. So for example, recently
  284. 9:00Browser use deleted about 90% of their
  285. 9:02old library and now their agent just
  286. 9:04writes a Python repl on their raw Chrome
  287. 9:07Devs protocol and this means that for
  288. 9:08the same models, it's up to 50% better
  289. 9:11whilst being two to five times cheaper
  290. 9:13and also being faster as well. And
  291. 9:15there's another example here of someone
  292. 9:17giving Opus 5.5 a single Python repl
  293. 9:20kind of like Prime agent and they found
  294. 9:22that normal Claude code without code
  295. 9:24mode gets 65% on terminal bench, whereas
  296. 9:26with their repl it gets 71% instead
  297. 9:29whilst costing a tiny bit less per task
  298. 9:31too. Now a pretty nice article for
  299. 9:33thinking about where these performance
  300. 9:34gains are coming from is this one by
  301. 9:36Alex Zhang from MIT who did a whole
  302. 9:38bunch of work on recursive language
  303. 9:40models, which we'll talk more about at
  304. 9:41the end of the video. But in this
  305. 9:43article that I recommend reading called
  306. 9:44the Mismanaged Genius Hypothesis, he
  307. 9:46says that a lot of the limitations of
  308. 9:48the models today come from the ways in
  309. 9:50which we use them and not the inherent
  310. 9:52capabilities of the models. And his main
  311. 9:54point is basically if we learn how to
  312. 9:55manage these models better, then they
  313. 9:57could already solve a much wider range
  314. 9:59of tasks than before and I think that
  315. 10:01code mode is a pretty good example of
  316. 10:03that because it's already giving a very
  317. 10:05capable model a lot more freedom. Now
  318. 10:07where I think the video gets pretty
  319. 10:08interesting is that inside of code mode,
  320. 10:10they're going to be adding three
  321. 10:11additional functions called spawn
  322. 10:13context, list context, and release
  323. 10:15context. And this appeared in the binary
  324. 10:17the same time code mode was added but
  325. 10:19has not been released yet. So basically
  326. 10:21it looks like sub agents are now being
  327. 10:23turned into contexts and they can be
  328. 10:25triggered programmatically and be
  329. 10:27combined programmatically kind of like
  330. 10:29dynamic workflows. Now if you have seen
  331. 10:31my dynamic workflows video when they
  332. 10:32were first announced then this should
  333. 10:34feel very familiar because we can
  334. 10:35basically wrap sub agents with code to
  335. 10:38coordinate even more sub agents than
  336. 10:39before without the main context window
  337. 10:42filling up. But one of the differences
  338. 10:43is that if we spawn a context inside of
  339. 10:46the repl then we have the option of
  340. 10:48forking the main conversation which
  341. 10:49means that cloud code could do something
  342. 10:51kind of like if you asked it to make it
  343. 10:53faster then it could fork the main
  344. 10:55conversation five or 10 times, explore a
  345. 10:58bunch of different approaches and then
  346. 10:59only return the top three approaches
  347. 11:02that sped it up the most back to the
  348. 11:03main conversation. We also have a
  349. 11:05difference whereby any other sub agents
  350. 11:06are spawned can talk to the main
  351. 11:08coordinator if they want to which isn't
  352. 11:10really possible with a dynamic workflow
  353. 11:12either. There are a bunch of small
  354. 11:13differences as well but it may be likely
  355. 11:15that they combine both of them together
  356. 11:17in some way. Now for the astute among
  357. 11:19you or the ones who really like to stay
  358. 11:21at the edge of all this you may be
  359. 11:22thinking to yourself hold on this is
  360. 11:24starting to look like a recursive
  361. 11:25language model and this is the same idea
  362. 11:28that Alex Zang had at MIT inside of his
  363. 11:30pretty popular paper from December of
  364. 11:32last year. And basically he said that
  365. 11:33for a RLM recursive language model the
  366. 11:36three things that have to come together.
  367. 11:38The first is a repl that persists
  368. 11:40between different calls and we've seen
  369. 11:42this in cloud code so far with the repl
  370. 11:43tool whereby cloud can define a variable
  371. 11:46and that variable can be used in another
  372. 11:47repl. The second is sub agents that get
  373. 11:50called from inside of a repl so your
  374. 11:53code can launch them and manage them
  375. 11:54which means that if the repl were to
  376. 11:56read like 20 different files we could
  377. 11:58quickly launch 20 different sub agents
  378. 12:01and this maybe added to cloud code soon
  379. 12:03with the free different context tools
  380. 12:04that we mentioned. And the third thing
  381. 12:06for a RLM is that your prompt has to
  382. 12:08live inside of a variable so the model
  383. 12:11never actually has to read all of it,
  384. 12:13and instead can just write code over
  385. 12:14your prompts. So basically it seems that
  386. 12:16we're going to have two of the three,
  387. 12:17but the missing piece here is a third.
  388. 12:19So what exactly does a third one mean?
  389. 12:21So right now if you were to paste in a
  390. 12:23prompt of 2 million tokens into Claude
  391. 12:25Code, then it would quickly fill up the
  392. 12:27context window, whereas in a RLM, Claude
  393. 12:30would be told something like, hey,
  394. 12:31there's a prompt of this length for 2
  395. 12:33million tokens that's sitting inside of
  396. 12:35this variable, and then Claude can use
  397. 12:37code to kind of figure out what to do
  398. 12:39with it. By cutting up the variable into
  399. 12:41different parts, it may hand it over to
  400. 12:42different sub agents and do a bunch of
  401. 12:44stuff with it. So this means that Claude
  402. 12:46would be able to work with much larger
  403. 12:47prompts than it can do today. And the
  404. 12:49exact same thing here goes for the
  405. 12:50conversation history. Now we know that
  406. 12:52we still have some kind of compaction,
  407. 12:54and compaction whilst it is getting
  408. 12:55better, can still be a bit bad. It'd be
  409. 12:58much better if the model can manage its
  410. 12:59own context window. So if we define the
  411. 13:01conversation history as a variable and
  412. 13:04then allow Claude to manipulate the
  413. 13:05variable and also slice and cut anything
  414. 13:08from it, it would mean that if Claude
  415. 13:09notices that the context window is
  416. 13:11filling up, then it can simply delete
  417. 13:13something from the context window
  418. 13:14earlier on. So this means that if it
  419. 13:15kind of saw a bunch of noisy tool calls
  420. 13:17that weren't really relevant to the
  421. 13:19conversation anymore, then it could
  422. 13:20basically replace them with something
  423. 13:22much shorter or just delete them
  424. 13:24instead. And this would kind of mean
  425. 13:25that we no longer need compaction
  426. 13:27because the model can just decide what
  427. 13:29to remove and replace inside of a
  428. 13:31context window. But now one of the
  429. 13:32problems can be that we end up breaking
  430. 13:34the prompt cache. And there's a pretty
  431. 13:36good research paper by Meta about this
  432. 13:39called context language models where
  433. 13:40they talk about having a prefix cache
  434. 13:42and a suffix cache of the part where we
  435. 13:45actually changed. I won't really go into
  436. 13:47this. I think this deserves its own
  437. 13:48video, but it will be linked down below
  438. 13:50if you do want to read it. Now in public
  439. 13:52do kind of have something like this
  440. 13:53inside of their API called context
  441. 13:55editing. So I think they're kind of
  442. 13:57interested in this idea as well. But of
  443. 13:58course they do mention that it breaks
  444. 14:00the cache and they kind of want to
  445. 14:01evaluate the cost benefit of removing
  446. 14:03something from the context window if it
  447. 14:05is breaking the cache for the next time.
  448. 14:07So maybe in 2027 they will allow the
  449. 14:09Repl to treat the prompts that you put
  450. 14:11in Claude Code as a variable and also
  451. 14:13the conversation history. Now if they
  452. 14:15were to add and I don't think it'd get
  453. 14:17fully there, Alex Zheng also makes a
  454. 14:18point that RLMs only really begin to
  455. 14:20work once a model is post-trained around
  456. 14:23them. So if Anthropic were to train Opus
  457. 14:256 or Opus 7 inside of its new version of
  458. 14:28Claude Code where it can manage
  459. 14:30sub-agents from a REPL and also the
  460. 14:32context window and prompts, then this
  461. 14:33whole code mode thing would be even more
  462. 14:35powerful and it would mean that Claude
  463. 14:36can do even more ambitious work for
  464. 14:38cheaper. So it may be the case that over
  465. 14:40time Claude becomes some kind of RLM.
  466. 14:43Now if you do like this kind of stuff,
  467. 14:44then you may want to join my email
  468. 14:45newsletter because there are a bunch of
  469. 14:47ideas that I share inside of here that
  470. 14:49don't quite make it onto YouTube but are
  471. 14:50still very helpful. There will also be a
  472. 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.