A simplified MVP that shows how Claude Code works under the hood — agentic loop, tool use, streaming, all in ~300 lines of TypeScript.
pnpm tsx src/cli.ts
claude-sonnet-4-6
5 tools
The agentic loop — a simple while loop that calls Claude, executes tools, and repeats.
The minimum set needed for an agentic coding assistant.
Read file contents with line numbers. Truncates at 50KB to stay within context budget.
Create or overwrite files. Auto-creates parent directories if they don't exist.
Precise string replacement. Finds an exact match and replaces it — fails if not unique.
Glob-based file discovery. Ignores node_modules and .git. Returns up to 200 matches.
Execute shell commands with 30s timeout. Returns stdout, stderr, and exit code.
Each agentic turn = 1 API call. Complexity determines how many turns a task needs.
| Session Type | API Calls | Input Tokens | Output Tokens | Est. Cost |
|---|---|---|---|---|
| Simple Q&A | 1 | 200 – 500 | 300 – 1.5K | $0.001 – $0.005 |
| Read & Explain File | 2 – 3 | 2K – 8K | 1K – 4K | $0.01 – $0.05 |
| Single File Edit | 3 – 5 | 5K – 15K | 2K – 8K | $0.03 – $0.10 |
| Multi-File Refactor | 10 – 30 | 20K – 80K | 10K – 40K | $0.15 – $0.60 |
| Build New Feature | 15 – 50+ | 50K – 200K | 20K – 100K | $0.50 – $3.00 |
Context grows with each turn because the full message history is sent every time. By turn 20, input tokens can be 5–10x the initial prompt.
Streaming makes the experience feel responsive even when total generation time is several seconds.
| Tool | Typical Latency | Notes |
|---|---|---|
read_file |
5 – 50ms | Filesystem read, limited to 50KB |
write_file |
5 – 50ms | Filesystem write + mkdir |
edit_file |
5 – 100ms | Read + string replace + write |
list_files |
10 – 200ms | Glob traversal, varies with directory size |
run_command |
50ms – 30s | Depends on command; timeout at 30s |
Simulated sessions showing TinyCode in action. Watch the agentic loop unfold step by step.
~300 lines of TypeScript, 6 files, zero abstractions.
| File | Purpose | Key Function |
|---|---|---|
src/cli.ts |
REPL entry point | readline loop, command dispatch |
src/agent.ts |
Agentic loop engine | runAgentTurn() — stream + tool dispatch |
src/render.ts |
Terminal output | ANSI colors, streaming text, tool call display |
src/tools/index.ts |
Tool registry | Definitions + executeTool() dispatch |
src/tools/*.ts |
Tool implementations | 5 files, one per tool |