Replace a headless Claude Code script with Maki to cut token spend

2026-11-05来源 dev.to RustEnglish

Headless Claude Code scripts are handy: pipe a prompt in, get structured output out, wire it into CI or a cron job. They are also where token spend quietly piles up, because every run re-reads files in full and drags bash output into the context window.

tontinton/maki is an open source coding agent built around one goal: use as few context tokens as possible. Its README says it can run UI-less with output compatible with Claude Code's stream-json format, which makes it a candidate drop-in for existing scripts. This post covers what it does differently, how to install it, and how to point a headless script at it.

Why it uses fewer tokens

Per the README, maki attacks the biggest token sinks directly:

  • An index tool uses tree-sitter to produce a skeleton of a file with the exact start and end lines of each item, so the agent can read only the function it needs. The author reports it adds about 59 tokens per turn but saves about 224 on reads, a net of roughly 165 tokens per turn.
  • A code_execution tool runs a sandboxed interpreter where all other tools are async functions, so data can be filtered or summarized without ever entering the context window.
  • A task tool lets the agent delegate to a weak, medium or strong model from the same provider, think Haiku, Sonnet, Opus.
  • rtk integration. If you have rtk installed, maki uses it to shrink bash output. The author notes bash is only about 12% of total token use and reads are about 65%, which is why the index tool matters more.

Other details from the README: a Rust terminal UI with fast startup, Lua plugins, plan mode, skills and MCP support, a memory tool, and a permission system that parses bash commands with tree-sitter, so git diff && rm -rf / is evaluated as git * plus rm * rather than waved through as one git command.

Install

On Linux or macOS, the README recommends reading the script before running it:

curl -fsSL https://maki.sh/install.sh -o install.sh cat install.sh chmod +x install.sh && sh install.sh 

The one-liner is curl -fsSL https://maki.sh/install.sh | sh. It installs to ~/.local/bin, and you can override that with MAKI_INSTALL_DIR. Other routes from the README:

brew install maki nix run github:tontinton/maki cargo install --locked --git https://github.com/tontinton/maki.git maki 

Windows has a PowerShell installer (irm https://maki.sh/install.ps1 | iex).

Pick a provider

Maki supports many providers through environment variables. A few from the README:

  • Anthropic: ANTHROPIC_API_KEY only. The README states that using OAuth is against Anthropic's terms, so use an API key.
  • OpenAI: OPENAI_API_KEY, or OAuth with maki auth login openai.
  • Google: GEMINI_API_KEY. DeepSeek: DEEPSEEK_API_KEY. OpenRouter: OPENROUTER_API_KEY.
  • Local: OLLAMA_HOST (for example http://localhost:11434) or LLAMA_CPP_HOST (for example http://localhost:8080).

Export the key for the provider you want before the first run.

Swap it into a headless script

If your script currently calls Claude Code in print mode, the README's headless flags are the ones to try:

maki --print --output-format stream-json 

The README says the output is compatible with Claude Code, so a parser that reads Claude Code's stream-json should keep working. Test it on a low-stakes job first, compare the output side by side, and check your token bill after a week. Note that --yolo disables the permission system, so keep it out of anything that touches a real machine unless the job is sandboxed.

Use it from your editor

Maki also speaks ACP. In Zed's settings.json:

"agent_servers": { "Maki": { "default_config_options": { "model": "deepseek/deepseek-flash" }, "type": "custom", "command": "maki", "args": ["acp"], "env": {} } } 

Caveats

  • The benchmark and token numbers are the author's own, from his usage. We have not reproduced them.
  • The author discloses that over 90% of maki's code was written by maki, guided by humans.
  • This walkthrough follows the README and we have not run it end to end.

The step-by-step version lives on our use-case page: replace a headless Claude Code script with Maki. If token spend is your main worry, also see cut token spend in Claude Code with Headroom.

Want the setup commands for 50 AI repos people actually ship with? Get the free AI Repos That Actually Ship pack: https://dedupedai.com/ship-pack/?utm_source=devto&utm_medium=article&utm_campaign=shippack

原文:https://www.a8q9.cn/en/article/replace-a-headless-claude-code-script-with-maki-to-cut-token-spend-37e07c.html

相关文章