r/rust_gamedev • u/legend-of-alan • 13h ago
Code Mode: I built a Rust tool to cut >60% of your Agent API Costs?
Hey all, I'm trying to share this across a few places and hopefully my free tool saves you some money if you're building a Rust agent for your game!
TLDR; Code Mode is a feature that Anthropic announced a few days ago that can save >60% of token costs for agent tool calls. Since token cost dominates agentic software for people like me building Spookery, my AI RPG game engine, I built a Rust tool called Ghost Mode to open source this technique (and also because it's fun to build stuff!). You can find it at the link above! It's a drop-in for your existing MCP servers/clients with only a little boilerplate.
Details;
So I don’t know if you saw the news from Anthropic, but they released this feature called ‘Code Mode’ for Claude Code. Basically it ‘batches’ LLM tool calls into scripts instead of constantly asking the LLM for the next tool. They claim 95% token savings (Haven't benchmarked it myself yet, but independent research claim more like a 60% savings, depending on workload). Up to now, this is mostly used by established coding agent products like Claude Code and Codex.
I immediately became obsessed, because I wanted it for Spookery to run AI-powered RPG games & private servers. So I took a look around, and there’s not much in Rust. There’s a few libraries like with TypeScript and other backends, but they’re like 5x slower (execution) to 100x slower (startup) compared to claims of modern options like Pydantic’s Monty (Python backend written on Rust).
So I went temporarily insane, didn’t sleep, and built/released my own in the days I had off… I call it Ghost Mode. It’s MIT-licensed, because I wanted to share it with others. To use it, just run:
cargo add ghostmodeGive it a try if you’re looking to save tokens in your new Rust agents for your games (or if you just want to flatter me by testing it). If anybody tries it and likes it, I think we can build a really powerful Code Mode implementation together (extend it for other languages, add new features, etc.).
I hope you get something useful out of it.
And if you get nothing out of this, just keep an eye for code mode in your code harnesses soon. I think Anthropic’s is still in the experimental features… But I think it’ll change the game if it’s as powerful as the research says.