Nanocode: The best Claude Code that $200 can buy in pure JAX on TPUs
TL;DR Highlight
Trained a 1.3B coding-agent model from scratch in about 9 hours on TPUs for $200
Who Should Read
An agent developer who wants to understand how an LLM learns tool calling, starting from the training process
Core Mechanics
- You run everything from pretraining to DPO
- nanocode is a library for walking through pretraining, SFT, and DPO-based RLHF end to end.
- It follows the simplest version of Constitutional AI, the approach Anthropic uses.
- It is written in JAX and optimized for TPU training.
- $200 for d24, $34 for d20
- On a TPU v6e-8, nanocode-d24 (1.3B) takes about 9 hours and costs $200.
- nanocode-d20 (477M) takes about 1.5 hours and costs $34.
- In the table, d12 (135M) takes 9 minutes and costs $3.
- Mixing in code changed the tokenizer
- The Stack-V2 was mixed in at 1:5 for both pretraining and tokenizer training.
- On a code sample, tokens dropped from 492 (nanochat) to 326, a 50.9% efficiency gain.
- Korean dropped 27.6% and some general text lost efficiency.
- Tool calls are wrapped in special tokens
- Tool output is treated as its own turn with tool_result_start/end tokens.
- Only four tools are defined: Read, Edit, Grep, Bash.
- Bash alone would force learning shell syntax from examples, so frequent actions like grep get dedicated tools.
- SOUL.md aligns the voice
- The SOUL asks for lowercase, friendly, non-sycophantic replies.
- A generator answers, a critic scores it against the SOUL, and failures get revised.
- Passing answers become Chosen and first failures become Rejected for SFT and preference learning.
- CORE is lower, by design
- d24 scores 0.227 CORE versus 0.261 when trained on FineWeb-EDU alone.
- GPT-2 XL (1.6B) scores 0.257.
- Context length is 4096, double nanochat d24's 2048.
Community Reactions
- A commenter questioned the example code
- The "remove falsey values without creating a new list" example was answered with a list comprehension that makes a new list.
- They also noted that with *args the original list can't be modified.
- A terminology objection
- One commenter said Claude Code is a harness that can't be trained.
- Precisely, the project trains a Claude Code-style model.
- Why spend $200?
- One commenter asked why anyone would pay $200 to train a coding model when free ones exist.
- Praise from a non-ML reader
- A commenter with no ML experience found it interesting and easy to follow.
- Name confusion warning
- A commenter pointed out a different agentic coding harness called nanocoder.
How to Apply
- Shrink your tool schema to Read/Edit/Grep/Bash
- Open your agent's tool list today and split frequent shell commands into dedicated tools.
- Test the article's idea that fixed-argument tools are more reliable than one Bash tool for small models.
- Pin the agent's voice with a one-page SOUL.md
- Write tone and prohibitions briefly in the system prompt and score outputs with a critique prompt.
- Keep only rules and drop philosophical text.
- Save failed and revised answers as pairs
- Log low-scored answers as Rejected and the passing revisions as Chosen.
- Reuse them later for DPO or evals.
- Validate the tool-call template before fine-tuning
- Confirm with your real CLI parser that the template works before spending training money.
Try It
# Paste into Claude or ChatGPT (simplified version of the paper's method: Constitutional critique-revise loop)
Evaluate and fix the answer below against this SOUL.
[SOUL]
- Use lowercase only (proper nouns and code are exceptions).
- Be warm and friendly, never sycophantic or verbose.
- Do exactly what was asked.
[User request]
{{질문}}
[Initial answer]
{{답변}}
Steps:
1. Score it 1-10 against the SOUL and write a specific critique of what violates it.
2. If below 7, rewrite the answer to address the critique.
3. Repeat until it scores 7 or higher, then output only the final answer.Terminology
Related Papers
Quadrillion-parameter transformers and how to train them
On fixed data, much bigger models with scaled weight decay and ensembling keep loss falling as compute grows.
Astra can read and write weights to improve Qwen
An LLM edited Qwen3.5-0.8B's weights directly, lifting MATH-500 from 7.9% to 48.1%.
Show HN: Qwen3-4B with the AI writing tics trained out
Distilling Qwen3-4B with LoRA cut its AI-writing slop score from 121 to 12.5 per 1000 words
Dust: Pretraining Transformers Without Backpropagation
Adding per-token noise to activations lets transformers pretrain without backpropagation, rivaling backprop.
Show HN: TurboGPT: train 22KiB transformer in 13s
A CUDA C++ project trains a tiny byte-level GPT in under a minute.
I had Gemini train its own replacement for $9
Fine-tuning GLiNER on $9 of Gemini labels reached 0.83 F1 locally.
Learning to solve hard problems in RL for LLMs by never giving up
Cutting compute on easy problems and retrying hard ones in RL raised accuracy on the hardest problems
Training a 3.8B LLM to 0.384 CORE for $998
A 3.8B LLM trained on 8 B200s in 43 hours for $998 scored 0.384 on CORE.