Minimal Rust coding agent. Single file: src/main.rs. ~185 LOC.
- No async — uses
reqwest::blocking. Keeps the code linear and readable. - No abstraction layers — one struct (
Msg), five functions (load_env,shell,read_file,write_file,dispatch,call_api,main). - OpenAI-compatible API — works with OpenRouter, or any
/chat/completionsendpoint. - Three tools —
shell,read_file,write_file. - Executor-mode system prompt — forces the model to act (write files, run commands) rather than describe.
MsgusesOption<Value>fields withskip_serializing_ifso tool/assistant messages serialize correctly without extra variants.- Tool results are pushed as individual
role: "tool"messages withtool_call_idmatching the request. .envis parsed manually (nodotenvcrate) — justsplit_once('=').- Full conversation history is sent every request — no summarization, no truncation.
systemfield sent on every API call alongsidemessages.
src/main.rs # entire implementation
Cargo.toml # 3 dependencies
.env # runtime config (not committed)
.env.example # template
OPENROUTER_API_KEY— requiredINFERENCE_BASE_URL— API base (default:https://openrouter.ai/api/v1)MODEL_NAME— model string (default:anthropic/claude-sonnet-4-6)
cargo build --release
./target/release/nano-codeTo add a tool: add an entry to the tools array in call_api(), add a match arm in dispatch(). That's it.