Ghost Mode
Rust library that lets AI agents run model-written Python scripts in-process to chain tool calls without sending intermediate results back to the model.
At a Glance
Ghost Mode Rust library released under the MIT license; free to use, copy, modify, and distribute.
Engagement
Available On
Listed Dec 2026
About Ghost Mode
Ghost Mode is an MIT-licensed Rust library by legend-of-alan that brings Code Mode to agents. Instead of returning every tool result to the model before the next call, the model writes a short Python script that chains the calls inside the host process. The latest listed release is v0.1.1.
What It Is
Ghost Mode is an agent-tooling library for Rust. A developer gives a Sandbox their own tools, or points it at an MCP server, and hands the model only two function definitions: execute and poll. The model sends a script through execute, the sandbox runs it, and the model receives a Status JSON containing only the script's final result. If a run is still going, the model calls poll with a run_id.
How It Works
The Monty backend runs scripts inside the host process, so no container or extra service is needed. Scripts can reach the outside world only through the tools the host provides. Each tool call goes through Host::call, and the answer returns to the script rather than to the model. The README's example chains pull request, check run and log lookups and returns only the last 500 characters of each failed log.
Deployment and Safety Options
- Tool definitions can be exported in MCP shape or as OpenAI functions.
- The
rmcpfeature addsmcp::Server, so an MCP server can be used without writing a custom host. - Monty is not crash-isolated. For untrusted scripts, the
monty-poolfeature runs each session in its own worker process. Limitscap how much any one result can add, 40,000 characters by default.Sandbox::dumpsaves an idle session as bytes andBuilder::restorereloads it. SettingBuilder::signing_keymakes restore refuse unsigned bytes.
Token Savings Claims
The README cites figures from other teams' Code Mode work, including Anthropic, Cloudflare, a cost benchmark and the CodeAct paper, and notes that savings vary by model. Weaker models sometimes retried failed scripts until costs exceeded plain tool calls.
Setup Path
Install with cargo add ghostmode. Building from source uses rustup and the pinned toolchain with cargo build --locked. The monty-pool feature's dependencies need a C compiler.
Collections
Popular collections
- Harness Setup
Collection by @joemseifi
- Code Knowledge Graphs
Collection by @evtuff
- Obsidian Agentic & AI plugins
Collection by @samofcode
- Codebase Context Generators
Collection by @joemseifi
Add Ghost Mode to one of your collections.
Community Discussions
Be the first to start a conversation about Ghost Mode
Share your experience with Ghost Mode, ask questions, or help others learn from your insights.
Pricing
Open Source (MIT)
Ghost Mode Rust library released under the MIT license; free to use, copy, modify, and distribute.
- MIT-licensed Rust library
- Sandbox with execute and poll tools
- Monty backend runs scripts in-process
- Optional monty-pool feature for process isolation
- Optional rmcp feature for MCP server support
Capabilities
Key Features
- Model-written Python scripts chain tool calls in the host process
- Only two model-facing tools: execute and poll
- Intermediate results never return to the model
- In-process Monty backend with no container or extra service
- Optional MontyPool backend with per-session worker processes
- MCP server support via the rmcp feature
- Tool definitions in MCP or OpenAI function format
- Configurable Limits capping result size (40,000 characters by default)
- Session dump and restore with optional signing key
