AnyCoder

May 12, 2026 · View on GitHub

AI coding agent in your terminal. Works with any LLM.

PyPI Python License: MIT Tests

中文文档 | Installation | Quick Start | Supported Models

DeepSeek, Qwen, GPT-5, Claude, Gemini, Kimi, GLM, Ollama local models - pick your favorite and start coding.


$ anycoder -m deepseek

> read main.py and fix the broken import

  Reading main.py
  ╭──────────────────────────────────────╮
  │ [6 lines total]                      │
  │      1  from utils import halper     │
  │      ...                             │
  ╰──────────────────────────────────────╯

  Editing main.py
  ╭──────────────────────────────────────╮
  │ Edited main.py                       │
  │ --- a/main.py                        │
  │ +++ b/main.py                        │
  │ @@ -1 +1 @@                          │
  │ -from utils import halper             │
  │ +from utils import helper             │
  ╰──────────────────────────────────────╯

Fixed: halper → helper.

  deepseek-chat | tokens: 1,247 | cost: \$0.0004

Why AnyCoder?

Claude Code is the best AI coding tool out there, but it only works with Anthropic's API. Want to use DeepSeek (cheap and fast)? Qwen (great for Chinese devs)? A local model via Ollama? You're out of luck.

AnyCoder gives you the same experience - file editing, shell commands, codebase search, context management - with whatever LLM you want.

What it does:

  • 100+ LLM providers via litellm - one CLI, any model
  • Agent loop with tool use - reads files, writes code, runs commands, searches codebases
  • Streaming output - see responses as they generate, token by token
  • Context compression - auto-compresses when conversations get long (snip tool outputs first, then summarize)
  • Search & replace editing - precise modifications with uniqueness checking and diff output
  • Dangerous command blocking - catches rm -rf /, fork bombs, curl | bash, etc.
  • Parallel tool execution - runs multiple independent tool calls concurrently
  • Session persistence - save and resume conversations with /save and --resume
  • .env support - drop a .env in your project root and go
  • ~1,450 lines of Python - small enough to read, hack, and extend

Installation

pip install anycoder

Quick Start

# Set your API key (pick one)
export DEEPSEEK_API_KEY=sk-...    # DeepSeek (default)
export OPENAI_API_KEY=sk-...      # OpenAI
export ANTHROPIC_API_KEY=sk-...   # Claude
export GEMINI_API_KEY=...         # Gemini

# Use DeepSeek (default, cheap and fast)
anycoder

# Use Kimi K2.5
anycoder -m kimi

# Use Claude Sonnet 4.6
anycoder -m claude

# Use GPT-5.4
anycoder -m gpt5

# Use Qwen
anycoder -m qwen

# Use local Ollama, data never leaves your machine
anycoder -m ollama/qwen3:32b

# One-shot mode
anycoder "add error handling to the login function in auth.py"
anycoder -p "find all TODO comments and list them"

# Resume a saved session
anycoder --resume session_1712345678

Or use a .env file in your project root:

# .env
DEEPSEEK_API_KEY=sk-...
ANYCODER_MODEL=deepseek

Supported Models

Use short aliases or full litellm model names:

AliasModelProvider
deepseekDeepSeek Chat (V3)DeepSeek
deepseek-r1DeepSeek Reasoner (R1)DeepSeek
gpt5 / gpt-5GPT-5.4OpenAI
gpt4oGPT-4oOpenAI
o4-minio4-miniOpenAI
claudeClaude Sonnet 4.6Anthropic
claude-opusClaude Opus 4.6Anthropic
claude-haikuClaude Haiku 4.5Anthropic
geminiGemini 2.5 FlashGoogle
gemini-proGemini 2.5 ProGoogle
qwenQwen PlusAlibaba
qwen-maxQwen MaxAlibaba
kimiKimi K2.5Moonshot AI
glmGLM-4 PlusZhipu AI

Local Models (Ollama)

ollama serve
anycoder -m ollama/llama3.1
anycoder -m ollama/codestral
anycoder -m ollama/qwen3:32b

Custom OpenAI-Compatible APIs

export ANYCODER_API_BASE=https://your-api.com/v1
export ANYCODER_API_KEY=your-key
anycoder -m your-model-name

Tools

AnyCoder has 6 built-in tools that the LLM calls automatically:

ToolWhat it does
bashRun shell commands with dangerous command blocking and cd tracking
read_fileRead files with line numbers, offset/limit for large files
write_fileCreate new files or overwrite existing ones
edit_fileSearch-and-replace edits with uniqueness checking and diff output
globFind files by pattern (**/*.py, src/**/*.ts)
grepSearch file contents with regex

You describe what you want in natural language. The agent decides which tools to use.

Commands

CommandDescription
/modelShow current model
/model <name>Switch model mid-conversation
/modelsList all model aliases
/tokensToken usage and estimated cost
/diffFiles modified this session
/compactManually compress context
/save [name]Save session to disk (names are sanitized before they become filenames)
/sessionsList saved sessions
/clearClear conversation history
/helpShow all commands
/quitExit

Input: Enter to send, Esc+Enter for newline (multiline input), Ctrl+C to cancel, Ctrl+D to exit.

Architecture

~1,450 lines total. Here's how it's organized:

anycoder/
├── cli.py            REPL + slash commands          258 lines
├── llm.py            litellm streaming wrapper      184 lines
├── agent.py          Agent loop + parallel tools    179 lines
├── context.py        Two-phase compression           92 lines
├── config.py         Env + .env + model aliases      86 lines
├── session.py        Save/resume sessions            60 lines
├── prompts/system.py System prompt generation        50 lines
└── tools/
    ├── bash.py       Shell + safety + cd tracking   114 lines
    ├── edit_file.py  Search-replace + diff output    98 lines
    ├── grep_tool.py  Regex search + skip binary     111 lines
    ├── read_file.py  File reading + binary detect    70 lines
    ├── glob_tool.py  File pattern search             48 lines
    └── write_file.py File writing + tracking         39 lines

How the agent loop works:

  1. User message gets added to conversation history
  2. History + tool schemas are sent to the LLM (streaming)
  3. If the LLM returns text, it's printed to the terminal
  4. If the LLM returns tool calls, each tool is executed and results are appended
  5. Go to step 2 until the LLM responds with text only (no more tool calls)
  6. Context manager auto-compresses when approaching the token limit

Two-phase compression (inspired by Claude Code):

  • Phase 1: Snip long tool outputs (keeps conversation structure intact)
  • Phase 2: Summarize old conversation turns if still over threshold

Configuration

Environment variables or .env file:

VariableDescriptionDefault
ANYCODER_MODELDefault modeldeepseek/deepseek-chat
ANYCODER_API_BASECustom API base URL-
ANYCODER_API_KEYAPI key-
DEEPSEEK_API_KEYDeepSeek API key-
OPENAI_API_KEYOpenAI API key-
ANTHROPIC_API_KEYAnthropic API key-
GEMINI_API_KEYGoogle AI API key-

Use as a Library

from anycoder import Agent, Config

config = Config(model="deepseek/deepseek-chat", api_key="sk-...")
agent = Agent(config)
agent.run("find all TODO comments in this project")

Comparison

FeatureClaude CodeClineAiderAnyCoder
LLM supportClaude onlyMultiMulti100+ via litellm
LanguageTypeScript (closed)TypeScriptPythonPython (MIT)
InstallnpmVS Code extpippip
File editingSearch & replaceDiffDiffSearch & replace
Context compressionYesNoYesYes (two-phase)
StreamingYesYesYesYes
Session persistenceYesNoYesYes
Code size512K lines100K+50K+~1,450 lines
Best forUsing itUsing itUsing itUsing it AND reading the source

Development

git clone https://github.com/he-yufeng/AnyCoder.git
cd AnyCoder
pip install -e ".[dev]"
pytest tests/ -v
  • CoreCoder — my other project: Claude Code's 512K-line source distilled into ~1,400 lines of Python, with 7 architecture deep-dive articles. AnyCoder builds on the same ideas but focuses on being a practical tool (litellm, session persistence, .env support) rather than a teaching codebase.
  • CodeJoust — can't decide between Claude Code, aider, Codex, and Gemini for your bug? CodeJoust races all four in parallel git worktrees, auto-scores by tests / cost / diff / time, hands you the winner's patch. One pip install codejoust away.
  • LiteBench — one-command LLM / agent benchmark (HumanEval, GSM8K, MMLU, MATH-500, YAML-defined custom tasks). Use it to pick which model your AnyCoder setup should default to.
  • RepoWikipip install repowiki → one command turns any local or GitHub repo into a wiki with dependency graph + architecture diagram + module pages.

License

MIT. Use it, fork it, build something better.


Built by Yufeng He · Agentic AI Researcher @ Moonshot AI (Kimi)