frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Show HN: Open-Sourced Code Mode to Cut ~60% of My Rust Agent's Token Burn

https://github.com/legend-of-alan/ghostmode
2•legend-of-alan•2h ago
For those who are tracking, Anthropic released an announcement last week about their experimental code mode for Claude Code, claiming some bonkers token savings when it comes to tool calls (95% on some workloads(1)). I haven't benchmarked it myself, but independent studies come in somewhere closer to 60~70% savings (2), but I digress. TLDR; I built an open-source version for the community.

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/

Comments

antoineMoPa•53m ago
> by having the agent write code against its tools instead of loading every tool definition up front

what does "write code against its tools" mean in practice?

legend-of-alan•29m ago
Sure thing! I like the shopping analogy here. Vanillla tool calls work like one trip to the grocery store every time you want to buy an item. Code Mode is more like going to the store once with a shopping list and buying all the items at once.

Especially for dependent calls.

So in code, this is roughly the difference between:

```

// old:

loop x4:

    next_tool = ask_llm()

    result = call_tool(next_tool)

    send_to_llm(result)
// do something with the result

```

And

```

// new (no loop!)

script_to_run = ask_llm(my_tools_list)

result = run_sandbox(script_to_run)

// do something with the result

```

In the new version we’ve mostly eliminated the need for the loop, and you’ll notice we only needed to call ask_llm() once! The LLM is batching multiple dependent tool calls into a little script that you run in a secure sandbox so you don’t have to go to the oracle of Delphi every time you need to call a tool.

In practice it allows the LLM to “think” in workflows instead of in terms of individual function calls. Not only does it save LLM calls, but it saves context because the LLM doesn’t often need to know every intermediate result.

Another example is from the README. In code mode, the LLM generates this script. It’s one call to the LLM and never leaves your pc. In contrast, normal tool calling would turn each of these calls into a call to the LLM.

```

pr = get_pull_request(number=42)

runs = list_check_runs(commit=pr["head_sha"])

failed = [run for run in runs if run["conclusion"] == "failure"]

[{"check": run["name"], "log": get_log(run_id=run["id"])[-500:]} for run in failed]

```

Show HN: I wrote an entire Vim manual over 4 years

http://themouseless.dev/vim/
233•thanato0s•23h ago•73 comments

Show HN: Open-Sourced Code Mode to Cut ~60% of My Rust Agent's Token Burn

https://github.com/legend-of-alan/ghostmode
2•legend-of-alan•2h ago•2 comments

Show HN: Olumino, a Markdown notes and spaced repetition app

https://olumino.app
120•Wiyseful•1d ago•50 comments

Show HN: Gerber 3D – view, compare and fab-check PCB files in the browser

https://wespeakenglish.github.io/VisualGerber/
2•pinelab•3h ago•0 comments

Show HN: Three Linux VMs in a browser tab, each running a different browser

https://michidk.github.io/sidebyside/
148•michidk•23h ago•33 comments

Show HN: Hacker News Movies

https://hackerfilms.pages.dev
3•nullandvoid•3h ago•2 comments

Show HN: SimDrop – Running iOS simulators in the macOS Finder sidebar

https://github.com/rxliuli/sim-drop
49•rxliuli•21h ago•10 comments

Show HN: Synth Patch Hero

https://swarkentin.github.io/synth-patch-hero/
144•kaidon•3d ago•28 comments

Show HN: An agent skill that optimizes code with falsifiable hypotheses

https://chszlab.github.io/AgenticAlgorithmEngineering/
134•0x23•4d ago•13 comments

Show HN: Old Nvidia and ATI tech demos, running again in the browser

https://gpu-demo-gallery.pages.dev/
355•arkits•2d ago•80 comments

Show HN: Turned a $5 AliExpress clock into a desk Clawd pet(+usage)

https://github.com/click6067-ship-it/token-tv
57•click6067•2d ago•7 comments

Show HN: Rchive – Every drive I've owned since the 90s, searchable in one window

https://www.rchive.computer/
54•kevinsync•3d ago•26 comments

Show HN: Silent dictation for Claude Code via on-device lip reading

https://github.com/batanus/lip-dictation
17•dima7711•23h ago•2 comments

Show HN: GravityFinder – Explore Exoplanets and More

https://gravityfinder.com
4•Trommsdorff•12h ago•0 comments

Show HN: Faster Mac Use – Background Chrome/macOS MCP and 5-lane routing skill

https://github.com/lifan-builds/faster-mac-use
3•lifan-builds•12h ago•0 comments

Show HN: Grind, my OpenDocument native office suite built in Rust

https://github.com/fwilhe2/grind
3•fwilhe•19h ago•1 comments

Show HN: Mason – A lightweight Postgres read-replica, built on columnar storage

https://masondata.ai/
109•tagspace•2d ago•21 comments

Show HN: PQCrypta Proxy: Rust proxy with HTTP/3, QUIC, hybrid post-quantum TLS

https://github.com/PQCrypta/pqcrypta-proxy
47•pqpdf•5d ago•25 comments

Show HN: Dart-TS Bridge

https://github.com/AdityaJandu/rpc-dart
2•rearview•16h ago•0 comments

Show HN: Single Calendar – Sync multiple Google calendars

https://singlecalendar.com
5•tsergiu•17h ago•2 comments

Show HN: Décor does HTML widgets for the Mac (you know, like in the old days)

https://stgm.github.io/decor/
4•omsta•17h ago•5 comments

Show HN: Explore the 17M-line Lean proof of the Riemann Hypothesis

https://maic.me/alpoge/
5•Maicon•17h ago•1 comments

Show HN: Play with VST/CLAP instruments and effects in the browser

https://vst.run/
3•mrmufungo•17h ago•1 comments

Show HN: Footprint – Visual electronics learning, encyclopedia, and part search

https://usefootprint.app/
2•mr-footprint•17h ago•0 comments

Show HN: Ribbon Architect – Endless ways to tie a gift ribbon

https://ribbonarchitect.com
26•permute•3d ago•1 comments

Show HN: Pocket Garden – 150 plus web games in a virtual console

https://triptych.github.io/web-games-andrew/console/
5•triptych•18h ago•0 comments

Show HN: Sliding-panes React UI library (inspired by WebOS Enyo)

https://vcarl.com/sashay/
39•vcarl•2d ago•8 comments

Show HN: Fuck_data_brokers.py

https://github.com/gary23w/f-ck_data_brokers
240•gary23w•19h ago•52 comments

Show HN: Carry – Save every AI conversations as Markdown, in a folder you Own

https://carry.md/
31•iankit17•2d ago•30 comments

Show HN: Type-C – variants, options, generics and pattern matching for C

https://github.com/stass/type-c
52•stass•4d ago•22 comments