Context: I'm writing an AI RPG engine called Spookery, and I immediately wanted to try this technique for myself when I heard of it. Agent deployment is currently dominated by token costs, especially during tool calling (single prompt generating tens or hundreds of tool calls). Unfortunately, it looks like the only ones who are doing this seriously are big agentic products like Claude Code and Codex. So, I thought it'd be fun to try it myself and bring it to you all!
The idea of Code Mode is simple but powerful. Instead of passing back tool call results back to the LLM one at a time, let the LLM batch calls by letting it write a short script using your tools. Basically taking 30 trips to the grocery store for 30 items and turning it into one trip to the store with a list in-hand.
There's a few near-ish open-source options, but they used TypeScript backends, we're a little boilerplate heavy, and I wanted to have something a little faster and Rust friendly for my game engine. Pydantic's Monty seemed a good candidate--their self-reports are around 5x faster on execution and 100x faster on startup (3). I wouldn't take the numbers to the bank, but it's written on a Rust framework and the python backend is entirely built from Rust too.
Anyway, I had a couple of days off unexpectedly. So, I went temporarily insane and built a Rust tool to bring code mode to the greater community for free. In enough days to fit on one hand (and just as many hours of sleep), I came up with the implementation linked. I call it Ghost Mode. It's MIT licensed. It's a drop-in for your agent that already makes traditional tool calls. With ~20 lines of setup, you can convert your existing agent to a Code Mode agent.
I hope you get something out of this, and maybe I can save you some money. Considering how limiting token economics are right now, I think this could be a game changer for the industry. If there's interest, I can imagine we can build also add some great new features, language compatibility, and other great things. Thanks for reading :)
Sources: (1) https://www.marktechpost.com/2026/11/17/anthropic-claude-cod... (2) https://arxiv.org/abs/2611.19123 (3) https://pydantic.dev/docs/monty/get-started/