# CoreCoder

> A deliberately tiny, readable Python coding agent you run once, read in an afternoon and fork into your own

- Category: AI Coding / Autonomous Coding Agents
- Language: Python
- Licence: MIT
- Repository: https://github.com/he-yufeng/CoreCoder
- Canonical page: https://ai-tldr.dev/tools/corecoder/
- Updated: 2026-09-24

## In short

CoreCoder is a minimal AI coding agent written in pure Python, built to be read and forked rather than to compete with production assistants. It sits in the Autonomous Coding Agents category of the AI Coding tools and is open-source, written in Python and licensed MIT. To get started: clone and install in editable mode.

## Overview

CoreCoder is a minimal AI coding agent written in pure Python, built to be read and forked rather than to compete with production assistants. Its README pitches it as "the nanoGPT of coding agents": the engine — agent loop, model interface, context handling, tools and sessions — is 1,309 lines once blank lines and comments are dropped, and the whole package is 25 files and 2,658 physical lines. The author, Yufeng He, describes it as the hands-on counterpart to his earlier source analysis of Claude Code. The project was formerly named NanoCoder and was renamed to avoid confusion with the unrelated Nano-Collective/nanocoder.

Despite its size it is a working agent. It reads, writes and edits files, runs shell commands, spawns sub-agents, keeps a to-do checklist and compacts its context in three tiers (trimming long tool output at 50% full, summarising older turns at 70%, and an emergency squeeze at 90%). It reports the tokens and estimated dollars a session has used, saves and resumes sessions, and asks for consent before any tool that would change the disk or run a command.

It speaks the OpenAI-compatible API by default, so switching to DeepSeek, a local Ollama model or another provider is usually two environment variables, with an optional LiteLLM backend for providers that lack an OpenAI-compatible endpoint. The README is paired with a bilingual (Chinese and English) series of source-reading essays that walk through the loop, tools, cost accounting, context compaction, sub-agents, the CLI and how to fork it.

## What it does

- Eight built-in tools — `bash`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`, `todo_write` and `agent` (sub-agent spawning) — with edits done as search-and-replace on a unique match rather than by line number, returning a diff.
- Consent gate for mutating tools: in the REPL each call can be allowed once, always allowed for the session, or denied; in one-shot `-p` mode mutating calls are refused unless you pass `--yes`.
- Plan mode (`/plan`) that refuses every mutating call until the agent has presented a numbered plan and you type `approve`.
- Claude Code-style extensibility: `~/.corecoder/hooks.json` runs your shell commands before and after tool calls (a pre hook can veto with exit code 2), and `~/.corecoder/mcp.json` adds tools from MCP servers over stdio as `mcp__<server>__<tool>`.
- Three-tier context compaction, parallel tool execution, streaming with backoff-and-retry, and per-session token and cost reporting via `/tokens`.
- Importable as a library: the package exports `Agent`, `LLM` and `Config` for embedding the loop in your own program.

## Getting started

CoreCoder needs Python 3.10 or newer. The README recommends cloning it and installing in editable mode so you can read and change the code as you go; `pip install corecoder` also works if you only want to run it.

1. Clone and install in editable mode

```bash
git clone https://github.com/he-yufeng/CoreCoder
cd CoreCoder
pip install -e .
```

2. Point it at a model

   It uses the OpenAI-compatible API, with `gpt-5.5` as the default OpenAI model. Other providers are two variables away — this is the README's DeepSeek example; a local Ollama model uses `OPENAI_BASE_URL=http://localhost:11434/v1`. The key can also go in a `.env` file at the project root, which is loaded on startup.

```bash
export OPENAI_API_KEY=sk-...
export OPENAI_BASE_URL=https://api.deepseek.com
export CORECODER_MODEL=deepseek-chat
```

3. Run the REPL or a one-shot task

   Inside the REPL, `/help` lists the slash commands, including `/model`, `/compact`, `/tokens`, `/diff`, `/undo`, `/plan`, `/save` and `/sessions`. One-shot `-p` mode refuses mutating tools unless you add `--yes`.

```bash
corecoder                                             # interactive REPL
corecoder -p "add error handling to parse_config()"   # one-shot mode, exits when done
```

4. Optional: route through LiteLLM

   For providers without an OpenAI-compatible endpoint, install the LiteLLM extra.

```bash
pip install "corecoder[litellm]"
```

5. Embed it as a library

```python
from corecoder import Agent, LLM

llm = LLM(model="deepseek-chat", api_key="sk-...", base_url="https://api.deepseek.com")
print(Agent(llm=llm).chat("find every TODO comment in this project and list them"))
```

## When to use it

- Learning how terminal coding agents like Claude Code work by stepping through a small, fully runnable implementation with a debugger.
- Using a compact, MIT-licensed codebase as the starting point for your own coding agent — adding tools, rewriting the system prompt or swapping in a fallback model chain.
- Running a lightweight coding agent against DeepSeek, Qwen, Kimi or a local Ollama model through one OpenAI-compatible endpoint.
- Scripting one-shot code changes in CI with `corecoder -p ... --yes`, guarded by pre-tool hooks that veto edits to protected paths.

## Version history

- 2026-09-24 v0.7.0: v0.7.0 streams the reasoning of thinking models such as deepseek-reasoner while keeping it out of the history, retries streams that die mid-response, and routes shell commands through Git Bash on Windows.
