A mini AI agent CLI, similar to Claude Code and Gemini CLI
A mini AI agent CLI, similar to Claude Code and Gemini CLI
This is a minimal coding assistant with the same behavior as Claude Code. Minimal: just 280 loc for the agent, 400 loc for tools, 1200 lop for prompts. Intuitively it "runs an interactive coding agent":
…The behavior of an AI agent is completely characterized by only five things, the things that are sent to the LLM "completion" method:
This agent behaves the same as Claude in the mechanical aspects (how its loop behaves, what tools it has, what behavior they have, when it chooses to send system-reminders).
However when it comes to Claude's "secret sauce", i.e. the content of Claude's tool-descriptions, system-prompt and system-reminders, this agent has none of Claude's magic: it only has its own simple versions. (If Claude's version of these things were plugged into this agent, then it would give byte-for-byte identical output to Claude).
This agent also prints system-reminders in the UI, so you can understand what's being sent and when.
This implementation has none of the UI niceties of Claude Code, and none of the permissions/safety. What it does have, however:
/plan {true|false}, and all the other
tools that Claude has -- Read, Edit, MultiEdit, Grep, Glob, LS, Bash,
WebFetch, WebSearch--mcp command line argument.You can choose a model. It uses the litellm naming conventions, e.g.
--model gpt-4.1 # uses OPENAI_API_KEY
--model gemini/gemini-2.5-pro # uses GEMINI_API_KEY
--model anthropic/claude-sonnet-4-20250514 # uses ANTHROPIC_API_KEYThe WebSearch tool uses a 'simple' model to digest web-pages before feeding
them to the main model. The simple model is usually automatically inferred,
but you can specify e.g. --digest-model o4-mini. Mini_agent uses the model's
prompt caching (which is CRUCIAL!) and displays cache hit numbers.
Mini_agent also exposes single-step and non-interactive uses. This is powerful for headless operation e.g. when you want to run the agent remotely but then migrate it's current state over to the user's machine when it needs help. It's also handy for integration tests. Let's explain these features via the command-line args:
./mini_agent.py --resume transcript.jsonl --{no-}interactive --{no-}execute-tools -p "What files are in the current directory?"Precisely put, the behavior of mini_agent is two loops.
--no-execute-tools flag will make it exit with code 2
and print tool-use to the command-line, rather than proceeding.--no-interactive
flag will make it exit with code 0 rather than asking the user.Every user message and every assistant message get written to a transcript.jsonl
file, in the same format as Claude Code uses (hence you can start a conversation
in Claude Code and migrate over to mini_agent, or vice versa).
If you supply --resume flag then it will resume from that existing
transcript, otherwise it will start a fresh transcript. If you supply
a -p prompt (text, or json content-block list) then it will append
this user-message to the transcript before starting its loops.
The key architectural observations:
What this means is that Claude Code can be accurately expressed through
(1) a small universal interaction+agentic loop (280 loc) which supports hooks
and subagents, (2) all its "behavior" (system-prompt, system-reminders,
tool-descriptions, tool-results) can be put into an MCP server.
I put my own behavior into --mcp ./core_tools.py. We could do the same
and put Claude Code's behavior into an MCP, or Gemini CLI's.
Claude Code's entire behavior is just 420 loc plus 1200 lines of prompts!
Claude Code (and Gemini) will both reveal full descriptions+schema of the tools available to them upon request. "Please write a list of every tool you have at your disposal. Give its name, description and json-schema. Write them into a file called tools.md." Moreover, Claude Code was good at examining each tool's schema, and brainstorming how to exercise all possible edge cases; also at finding the exact output of Claude Code's built-in tools for all these cases and turning them into test suites.
During development I used an "inproc" MCP server.
Normal --mcp ./core_tools.py communciates over RPC via stdio.
But I also wrote --mcp builtin, which links statically
to core_tools.py and calls the tools "inproc". This let me set
breakpoints in the tool implementation and get a good callstack
all the way from agent to tool. I did this by creating a
statically-linked class which looks like mcp.ClientSession
but dispatches statically.
No open issues yet, or sync has not completed.