Introducing TanStack AI Code Mode

Jack Herrington| 00:07:40|Apr 9, 2026
Chapters11
Introduces the problem: LLMs are inefficient with conventional tool calling and need a better approach to leverage tools.

TanStack AI Code Mode slashes tool-calling cost by shifting logic into TypeScript code, cutting rounds trips from four to two and dramatically reducing context size.

Summary

Jack Herrington introduces TanStack AI Code Mode as a smarter alternative to traditional tool calling. He starts by outlining why LLMs struggle with tool calls and how N+1 patterns waste time and context. The demo contrasts regular tooling with code mode: regular tooling requires multiple round trips and accumulates about 9.8 KB of context, while code mode generates and executes TypeScript code inside an isolate, reducing trips to two and cutting context to roughly 1.7 KB. Herrington demonstrates calculating the average shoe price, showing code mode not only runs faster (8s vs 27s) but also yields a correct result (137.75) rather than an incorrect 134.50. The TanStack AI Monorepo’s ts-code-mode-web directory hosts the setup, including the getCodeModeTools function that wires an isolate driver (QuickJS, Node, or Cloudflare Worker) and injected tools. He also introduces code mode skills, which persist generated code as reusable tools like get_average_product_price, and shows how this enables faster repeated queries. Beyond tools, TanStack pushes code-mode demos into databases and dynamic UI generation, with the Dynamic Reports example building UI via code instead of JSON. Herrington encourages viewers to clone the repo and experiment with their own data, promising more insights in future updates and inviting comments and questions.

Key Takeaways

  • Code mode replaces direct tool calls with generated TypeScript that runs in an isolated environment, dramatically reducing round trips.
  • In the shoe price demo, regular tooling required four LLM calls and about 9.8 KB of back-and-forth context, while code mode used two calls and ~1.7 KB.
  • Code mode delivered a correct average price of 137.75 instead of an incorrect 134.50 from the regular tooling approach.
  • Code mode skills can persist generated code as reusable tools (e.g., get_average_product_price) with input/output schemas and descriptions.
  • The TanStack monorepo includes ts-code-mode-web; tools are wired via createCodeMode with an isolate driver (QuickJS, Node, or Cloudflare), plus a system prompt detailing TypeScript typings and execute_typescript usage.
  • Code mode demonstrations extend to database queries and dynamic UI generation, showing code-crafted UI for Dynamic Reports and real-time tool usage analytics in MPM GitHub Chat.

Who Is This For?

Essential viewing for frontend/backend developers and AI engineers exploring TanStack AI and code-driven tool orchestration. If you’re building LLM-powered apps that rely on tooling, this video shows practical patterns to cut latency and improve accuracy.

Notable Quotes

"Now that we've worked at LLMs for a while, we know that there are things that they're very efficient at and other things that they're not so efficient at."
Opening framing for why code mode matters.
"Let's take a look at this exact same scenario, but with code mode. I'm gonna click on the code mode button here."
Demonstrating the switch from regular tools to code mode.
"It literally wrote the code to do that. And we can see a huge performance win."
Code mode generates and runs TypeScript to optimize the task.
"The actual average price is 137 and 75 cents."
Code mode yields a precise calculation vs. heuristic in regular tooling.
"Code mode skills... allows the LLM to actually store TypeScript that thinks is valuable."
Introduction of reusable code-mode skills for persistence.

Questions This Video Answers

  • How does TanStack AI Code Mode reduce tool-calling overhead?
  • What is an isolate driver and how is it used in code mode?
  • Can code mode be used with databases and dynamic UI generation?
  • What are code mode skills and how do they improve performance?
  • How do I try TanStack AI code mode in my own project?
TanStack AICode Modeexecute_typescriptisolate driverQuickJSNodeCloudflare WorkergetProductListPagegetProductByIdN+1 API pattern
Full Transcript
Now that we've worked at LLMs for a while, we know that there are things that they're very efficient at and other things that they're not so efficient at. And one of the things that they're not so efficient at is tool calling, which is a bummer because in order to actually make your agent do anything cool, it needs to have tools. So how do we fix and optimize how we call our LMS to use their advantages and get away from their disadvantages? Well, at TanStack, we've been building out this thing called code mode and I want to show you the difference between regular tooling and code mode so you can understand why we're so excited about this. Lemme show you just how inefficient tool calling is and how code mode fixes it. This is an example page. We've got a shoe product list here. So you've got two tools. getProductListPage, which gives the list of IDs as well as the page count, and then getProductById. It roughly maps to REST N+1 API. And a lot of folks do this kind of thing with their LLMs, and it's horribly inefficient. Let's ask the question. Let's say, what's the average cost of a shoe? Now we're gonna run that with regular tools, and we can see over here that it's making a bunch of tool calls. Now what happens with those tool calls is that the LLM responds to us with a request to run a tool, and then we run that tool and then we start a whole new request with all of the messages that we had before and all of the tool calls and all the results, and we send that back to the server for processing. And in this case, just to answer that simple question and get back the average price of the shoes, we've had to make four round trips between us and the server to service all of those tool calls, even though a lot of these tool calls were done in parallel. So this is about the most efficient that you're gonna get with this N+1 pattern when it comes to normal tool use. And we can see that the context that we've sent back and forth to the server has really compounded. We've got 9.8 k worth of use of context going back and forth to the server. So even the simple question is actually pretty inefficient. Now to fix this, we lean on something where we know that the LLM is really good and that's in writing TypeScript. So let's take a look at this exact same scenario, but with code mode. I'm gonna click on the code mode button here. And we can see that instead of running those tools directly and instead generated some TypeScript code that it then sent to execute_typescript and that Typescript code was executed inside of an isolate. That isolate had access to getProductListPage and getProductById. And so it could just go and do things like Promise.all, map, reduce all that stuff to go and figure out what's the average cost of a shoe. So it literally wrote the code to do that. And we can see a huge performance win instead of four LLM calls. Now we've got two instead of 9.8 kilobytes of context, we've got 1.7. And it's even faster to do it. All the tool calls were 27 seconds, and the duration of code mode was eight seconds. And the next thing we know about LLMs is that they're not particularly good at math. Check out the average price. All of the shoes coming out of the regular tools versions. A hundred thirty, four fifty, is that right? Well, actually, no, it's not. The code mode version gets you the actual price because it's just using TypeScript to do the calculation and the actual average price is 137 and 75 cents. So now let's go over to the app and see how this is actually working. Now this is the TanStack AI Monorepo, and I'm over in the examples ts-code-mode-web directory. That's the application that we were just looking at. And in there there is the routes for home. That's the homepage that And inside that is the API for product code mode. So this is what the code mode side of the chat calls to get anything done. And the really interesting thing here is this async function get code mode tools. So code mode is actually modeled as just a tool. You just call createCodeMode. You give it a driver, that's the isolate driver that's actually gonna be used to run the TypeScript. And you can use QuickJS, node or a CloudFlare worker currently. You create that isolate driver, you give that driver over to code mode, and then you give it the tools that are injected into that isolate. And what we get back is a standard TanStack AI tool that we just give off the chat and a system prompt. And the system prompt has all of the TypeScript typings for the injected tools as well as all the information that the LLM will need to know about how to call execute_typescript. And then we just add that system prompt onto our existing system prompt. And that's it. That's all it takes to do code mode. But if you're thinking that's pretty cool, well, I agree with you, but it actually gets better. So check this out. We also have code mode skills, and that's an additional library that you can layer on top of code mode and it allows the LLM to actually store TypeScript that thinks is valuable. I mean, if you think about it for a second. This generated code over here is basically a tool. So the next time we ask for an average, it could just reuse this code, right? Let's try that. Let's turn on with skills and then run it again. And now, in addition to giving us the output, it's also registering a skill. That skill is get_average_product_price. And it's got the input schema. The output schema, as well as the code, a description, and we can take a look at it over here and actually see it. Now this is persisted currently in this demo on disc, but you could put it anywhere you want. You could put it in a database, you could put it anywhere. Now let's refresh the page. Click on with skills again, go for average cost and see how much faster is that? Well, it just used the skill that had just created. And look how fast and efficient it is. Two calls the LLM, half a K of context, a duration of three seconds. It's astounding. But that's not all. We've actually been working on code mode for a little while, and so we've kind of gone a little hog wild on it. We've got a cool database demo over here where you can see that we've just connected code mode straight to a database, and it's gonna build the TypeScript as well as all the SQL to go and do database work for you. This you can just use right outta the box on your database, get some cool reports. It's very exciting. Just go and put it onto your database. You're gonna love it. We've got a much more in depth example called MPM GitHub Chat. It shows that you can have regular tools as well as code mode tools all together in the same system. It actually allows you to go and select between the different isolates and it shows you how often various tools are used in real time. It even shows you how to use custom messages to go and put up UI like this NPM data over here. But if you think that's cool, well hang onto your hats. If you go over here to Dynamic Reports, this is where it really gets exciting. Let's take a look at hot state libraries. This is exactly the same set of tools as we had before, but we've added on some UI tools and now code mode can actually go and build out a UI dynamically for this report. It is so cool. All I asked it for was this report. It figured everything out for me. Now this is using code to build out the UI and I've seen a lot of JSON specified UI stuff out there for LLMs, but why not just use code? This works really, really well. I could go on and on about code mode, but I really encourage you to check it out. Go clone the TanStack AI monorepo, run ts-code-mode-web. Try it out for yourself, try it out on your own data. Can't wait to hear what you're experiencing. Of course, leave that in the comments right down below, and if you have any questions, I'll try to answer them down there. In the meantime, if you like this video, hit that like button. If you really like the video, hit the subscribe button and click on that bell and you'll be notified. The next time I new Blue Collar Coder comes out.

Get daily recaps from
Jack Herrington

AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.