What it is
A coding agent CLI that I wrote to understand how tools like Codex and Claude Code work underneath. I kept the agent loop in plain code instead of hiding it behind an agent SDK:
- the provider proposes tool calls;
- the runtime validates the arguments and asks for approval;
- the tool runs;
- the result goes back to the model.
The loop repeats until the model answers with text only or runs out of budget. If a tool fails, the error goes back to the model as a result so it can recover.
The recording above is a real run of the free ERNIE model on OpenRouter, rendered from its trace by a script. Nothing in it is hand-written.
How it works
- Providers. Separate adapters for the OpenAI Responses API, Gemini and OpenRouter, plus a mock and a scripted provider for tests. The core only sees a provider-neutral conversation.
- Safety. Every tool declares a risk level: read, write, execute or destructive. Reads are allowed. Writes and commands are denied unless approved. Edits are atomic patches bound to the file’s hash, and deletes go to a recoverable trash folder.
- Command isolation. Commands run without a shell, at one of three levels.
safeis an allowlist plus approval.sandboxuses a macOSsandbox-execprofile that limits writes to the workspace and denies network and reads in$HOME.containerruns Docker or Podman with a read-only root, no capabilities and no network. The last two fail closed when they aren’t available. - Delegation. Six agent profiles share one runtime. A lead agent hands work to child agents with their own context. Writable children run in parallel in separate Git worktrees and merge through a queue. Conflicts are kept as patches I can review and re-apply.
- Budgets. Turn, tool, agent, token, time and dollar limits are shared by the whole run.
--max-costfails closed when spending can’t be measured. - Traces. Runs are recorded as JSONL with secrets redacted, and can be inspected or replayed later.

Live eval
The eval runs ten small tasks in fresh workspaces: bug fixes, a feature from a spec, a multi-file rename, a failing test file, a security review, codebase exploration and a refusal to escape the workspace. Hidden grader files are copied over each workspace before checking, so an agent can’t pass by editing the visible test. An offline self-test proves every grader fails the untouched code and passes a reference solution.
Free models on OpenRouter, one run each, in containers:
| Model | Passed | Stopped by the provider |
|---|---|---|
inclusionai/ling-3.2-flash:free | 9/10 | 1 |
baidu/ernie-5.5-flash-preview:free | 9/10 | 0 |
nvidia/nemotron-3-ultra-550b-a55b:free | 9/10 | 0 |
cohere/north-mini-code:free | 6/10 | 4 |
Single runs on free endpoints rank runs, not models. ERNIE also scored 10/10 in two earlier runs the same day.
On Gemini gemini-3.5-flash-lite the eval drove the fixes. It went from 5/10 to 8/10:
- An underspecified tool schema cost three tasks.
apply_patchdeclared its changes as a bare object, so the model guessed field names and twice fell back to rewriting the whole file. The schema now spells outoldTextandnewText. That took it to 7/10. - Policy is not a sandbox. Asked to copy
../secret.txt, the model was blocked fromcat,python3andnode -e. Then it wrotecopy_secret.jsand ran it withnode, which the policy allows. That is why thesandboxandcontainerlevels exist. - Models waste their last turn. Several runs finished the work and ran out of turns before answering. The runtime now asks for an answer before the final turn.
- Free providers fail often. Rate limits looked like agent failures. OpenRouter calls now back off for up to a minute, and reports mark attempts the provider ended as blocked.
Testing
314 offline tests cover the loop, every adapter’s wire contract, the safety boundaries, delegation, worktree merging, traces, the TUI and the CLI. CI runs them on Node 20 and 22. OpenAI is only tested against recorded wire formats, and the eval is ten synthetic tasks, not a general benchmark.