Architecture
For contributors. TypeScript on Bun, compiled to a single binary.
src/
cli.ts arguments, then one of the four front ends
app.ts what every front end needs to start: settings, session, model, agent
commands.ts sub-commands without a conversation (keys, models, sessions, export, doctor)
core/ the agent, with no user interface (under 3,000 lines, enforced by a test)
agent.ts the loop: model call, tools, permissions, retries, compaction, sub-agents
events.ts everything the core tells a front end
session.ts JSONL tree files
compaction.ts when to summarize, where to cut, the summary prompt
permissions.ts modes and rules
workspace.ts MAXXING.md / CLAUDE.md / AGENTS.md, imports, skills, commands, agent types
prompt.ts the system prompt
checkpoints.ts file contents before a turn, for undo
config.ts paths, settings, keys
export.ts a session as Markdown
repair.ts tool calls a model wrote as text, read back as calls
providers/ types.ts is OUR provider interface; aisdk.ts adapts the AI SDK provider packages to it
catalog/ models.dev, reduced and embedded
tools/ one file per family; types.ts is the tool contract
mcp/ MCP client → ordinary tools
facades/ print.ts (-p and --json), acp.ts
tui/ the interactive terminal (pi-tui)
The rules of the house
- A small core, everything else around it.
src/coreholds the loop, sessions, compaction and permissions, and a test fails when it passes 3,000 lines. A feature that can live in a tool, a front end or a Markdown file does not go in the core. - One core, four front ends. The terminal,
-p,--jsonandacpare clients of the sameAgent. They receiveAgentEvents and implementHost(three questions the core may ask: a permission, a question to the user, the approval of a plan). The core never prints and never reads a key press. - Providers behind our own interface.
Provider.stream(request)yields six kinds of events (src/providers/types.ts). Today one adapter implements it on the low-level interface of the AI SDK provider packages; any protocol can be replaced by a client of our own without touching anything above. - Formats people already have. Instruction files, skills, commands, rules,
.mcp.json: read as they exist in projects, no conversion step. - Safe by default, nothing phones home.
- Written from ideas, not from other people's code. Dependencies must have a permissive license.
One turn
prompt(input)
append the user message
loop
append steering messages, if any
compact if the context is near the limit (or start preparing a summary)
call the model (stream → events), retrying passing errors; overflow → compact, retry
append the assistant message, with tokens and cost
no tool call? → take a queued message and continue, or stop
run the tool calls: neighbours marked `parallel` together, the others in order
each: validate arguments → permission (rule, mode, or ask the Host) → run → bounded result
append the tool results
interrupted or denied? → stop
Every append goes to the session file at once: a crash loses nothing that was done, and Agent.repair() closes a
call left without a result.
Adding things
- A tool: an object implementing
Tool(name,description,inputSchema,access(),run()), added intools/index.ts.access()declares what the call is about to do (read,edit,execute,network…) and on what; the permission engine does the rest. Setparallel: trueonly if it changes nothing. - A provider protocol: implement
Providerand select it inproviders/aisdk.ts. Errors must beProviderErrors that say whether they are retryable and whether they are a context overflow. - A front end: build an
AgentwithcreateAgent(options, host, { onEvent }).
Tests
bun test (no network, no key):
test/agent.test.ts: the loop against a scripted provider (tools, parallelism, permissions, plan mode, retries, interruption, steering, repair, compaction, sub-agents, costs).test/e2e.test.ts: through the real provider adapters against local servers speaking the OpenAI, Anthropic and Gemini wire formats.test/acp.test.ts: the ACP front end driven by the official SDK client.test/permissions.test.ts,tools.test.ts,workspace.test.ts,mcp.test.ts.
bun run typecheck, bun run build. test/mock-server.ts is a scripted OpenAI-compatible server, handy to try
the terminal without a key: declare it as a custom provider and run maxxing-code.
Bench
bun bench/run.ts --model <provider/model> runs a set of small coding tasks (bench/tasks/*: a starting folder, a
prompt, a script that checks the result) and writes the results to bench/results/. --agent opencode runs the
same tasks with OpenCode, for comparison with the same model. Run it before and after a change to the loop, the
prompt or a tool.
Releasing
bun run build:all produces the four binaries, each also compressed (.gz), dist/checksums.txt and the npm
packages under dist/npm/. A release is a tag vX.Y.Z with the compressed binaries and the checksums attached
(the install script and maxxing-code update read them from there; the checksums are those of the binaries once
unpacked),
then npm publish of each platform package and of maxxing-code (not published yet). The version and the
repository address are written once, in package.json (the install script and the docs name the repository too):
bump version there and add a section to CHANGELOG.md.
Maxxing Code