Build Your Own Claude Code
A command-line coding agent in TypeScript on Bun. It runs an agent loop against an LLM, gives the model Read, Write and Bash tools, and loads skills from .claude/skills, including ones that run as subagents.
- Period
- Context
- My role
The problem
The quickest way to understand how a coding agent works is to build the loop yourself. The challenge goes from a single model call to an agent with tools, skills and subagents, and every stage is checked by CodeCrafters' test runner before the next one opens.
How it was built
The agent loop
Each turn sends the conversation and the tool definitions to the model. If it asks for tools, each call is run, its result is appended as a tool message, and the loop goes again until the model answers in plain text. A tool that fails returns its error to the model as text instead of crashing the run, so the model can see what went wrong and try something else.
Skills, loaded only when needed
At startup only each skill's name and description, parsed from YAML frontmatter, go into the system prompt. The full instructions are loaded when the model calls the Skill tool or the user types /skill-name. Slash commands can be stacked, and $ARGUMENTS, $ARGUMENTS[n] and $n are substituted into the instructions.
Subagents for forked skills
A skill marked context: fork runs in a fresh conversation of its own. Only its final answer comes back to the parent, so the main context never fills up with the subagent's intermediate tool calls.
Where it landed
- Every stage of the challenge completed
- Clone the repo, run bun install, set OPENROUTER_API_KEY and it runs on your machine
Specification
- Runtime
- Model
- Tools
- Skills
- Run locally