A tiny, readable CLI coding agent. Give it a goal in plain English and it runs an agent loop against Claude, editing files in your current folder until the goal is done.
cd miniagent
npm install
ANTHROPIC_API_KEY=sk-... npx tsx src/cli.ts "rename a.txt to b.txt and add a header comment"
# add --verbose to print the raw model output each turnFiles touched by the agent are sandboxed to the folder you run it from (../ and
absolute paths outside it are blocked). No framework, no LangChain — just a loop
you can read.
An agent is three things wired together. Here is exactly which code is which:
- The model —
src/agent.ts, theclient.messages.create({ ... })call. That single request (system prompt + history + tool list in, a decision out) is the LLM. - The harness — everything else in
src/agent.ts: theforloop, reading the model'stool_useblocks, andexecuteTool()'s switch insrc/tools.tsthat turns a requested tool into a real filesystem action. - The context — the
historyarray insrc/agent.ts. It starts as your goal and grows every turn (assistant replies, tool calls, tool results); we resend the whole thing each call because the API itself is stateless. That array is the memory.