he-yufeng/CoreCoder
Minimal AI coding agent (~1,000 lines of Python) inspired by Claude Code. Works with any LLM. Think NanoGPT for coding agents. Formerly NanoCoder.
What it solves
Coding agents like Claude Code or Cursor are often treated as black boxes. CoreCoder strips away the complexity and shows that the core of such an agent is just a simple loop that calls a large language model, executes the tools it requests, and repeats until it has an answer. It solves the problem of understanding how coding agents actually work, giving you a minimal, readable reference that you can run, debug, and modify. Instead of reading thousands of lines of opaque production code, you can read the whole engine in an afternoon and then fork it to build your own.
How it works
The engine is built around a while loop in agent.py (240 lines). You send the user's request to a model, the model may ask for tool calls (like reading a file, editing code, running a shell command), you execute those tools in parallel, feed the results back into the conversation, and repeat until the model decides it's done. The loop is bounded by a max-round limit to prevent runaway.
To make this work reliably in the real world, the project handles streaming responses, retries, cost tracking, context management, and safety. Key pieces:
llm.pymanages API calls, retries, and cost accounting.context.pycompacts conversation context in three tiers as it gets full (trim long tool outputs, then summarize older turns, then compress everything).- Eight tools are provided:
bash,read_file,write_file,edit_file,glob,grep,todo_write, andagent(for sub-agents). Each tool is a small Python file, and you can add your own. - The
agenttool can spawn sub-agents with isolated contexts, running up to 4 in parallel, and you can set dependencies between them. - Safety: mutating tools (like writing files or running shell commands) ask for your consent via a permissions system.
- It uses an OpenAI-compatible API by default, but you can switch providers with two environment variables, or use an optional LiteLLM backend for many more.
- It also supports plan mode, hooks (Pre/PostToolUse), and checkpoints (undo snapshots).
Everything is written in plain, readable Python, with a clear code map in the README so you can jump straight to any component.
Who it's for
CoreCoder is for developers who want to truly understand how AI coding agents work, and who want to build their own. It's a learning and forking foundation, not a production daily driver. The README explicitly compares it to nanoGPT (a minimal GPT for teaching): it's meant to be read end-to-end, debugged, and modified. If you've ever felt intimidated by the internals of tools like Claude Code, this is your entry point. It's also useful for anyone who wants to create a custom coding assistant tailored to their own workflow, with the ability to swap models, add tools, and rewrite the system prompt easily.
Highlights
- Readable end to end: the whole engine (~1,483 lines of core code, 3,276 total) can be read in an afternoon, with no hidden magic.
- Hackable: set breakpoints anywhere, change code, and rerun locally. The project really works — it reads and writes files, runs commands, and completes tasks.
- Eight built-in tools cover typical agent actions, and adding a new tool is a small Python file (base class is 32 lines).
- Three-tier context compaction manages long conversations without losing early decisions.
- Multi-agent support: the
agenttool spawns up to 4 parallel sub-agents with isolated contexts, dependencies, and shared cost tracking. - Safety by design: mutating operations require consent, and there's a regex-based guard against dangerous shell commands.
- Provider-agnostic: works with OpenAI-compatible APIs, plus an optional LiteLLM backend for 100+ models; thinking models like DeepSeek-reasoner are supported with reasoning displayed.
- Includes an 8-part bilingual source-reading series that traces every line and explains the "why" behind each design choice.
Related
- Project
- Project
- Project
- Project
- Project