Your tiny coding claw
Learn to build an AI coding agent in ~1500 lines of Python
English | ไธญๆ
Ever wondered how tools like Claude Code or OpenClaw actually work under the hood? miniclaw is the answer -- a minimal, hackable AI coding agent you can read through in an afternoon.
The name says it all: mini + claw (from OpenClaw). No sprawling architecture, no thousand-file monorepo. Just the essential loop that powers every AI coding assistant:
You type a request
-> LLM thinks
-> LLM calls tools (read / write / edit / grep / glob / bash)
-> Tools execute in your workspace
-> LLM sees the result
-> Repeat until done
If you want to learn, teach, or hack on an AI agent, start here.
- 10 Tools --
read,write,edit,glob,grep,bash,Skill,memory,session_search,Agent. Workspace file ops plus on-demand skills, persistent memory, past-session recall, and sub-agents. - Plan Mode -- The agent can enter a read-only planning phase: explore code, produce a structured plan, then execute only after you approve. Write operations are blocked until you say go.
- Skills System -- Drop a
SKILL.mdinto.miniclaw/skills/<name>/and the agent learns new tricks. Skills are injected into the system prompt automatically; theSkilltool loads full instructions on demand. - Memory -- Durable facts live in
~/.miniclaw/memory/MEMORY.mdand are auto-injected each session. The agent can read/write topic files for longer notes. - Session Search -- Conversations are recorded locally; the agent can browse, full-text search, or scroll through past sessions.
- Sub-agents -- Optional
Agenttool spawns an isolated sub-agent (explore/general) so research or side tasks don't pollute the main context. Enable withsubagent.enabled. - Context Management -- Micro-compaction and auto-summarize keep long conversations within the context window.
- Any OpenAI-compatible LLM -- Swap models by changing one environment variable. Default: MiniMax-M2.7.
- Workspace Isolation -- All file operations are sandboxed to your workspace directory. No
..path escapes.
Install:
pip install miniclawRun:
export LLM_API_KEY=your_api_key
cd ~/my-project
miniclawThat's it. You're talking to an AI agent that can read, write, and run code in your project.
Other install methods
pipx (recommended for isolation):
pip install pipx
pipx ensurepath
pipx install miniclawFrom source (for hacking):
git clone https://github.com/sundl123/miniclaw.git
cd miniclaw
pip install -e .Tip: If you get
command not found: miniclawafter installing, your Python scripts directory isn't in PATH. Runpipx ensurepath(pipx) or add~/.local/binto your PATH (pip).
The entire agent fits in a handful of Python modules. Here's the core loop:
flowchart LR
User([You]) -->|message| REPL[cli.py<br>REPL]
REPL -->|messages + tools| LLM[api.py<br>LLM API]
LLM -->|tool_call| Tools[tools/<br>10 Tools]
Tools -->|result| LLM
LLM -->|final reply| REPL
REPL -->|display| User
Each module has a single responsibility -- read through them in this order:
| Module | What it does |
|---|---|
cli.py |
Command-line REPL, parses input, handles /plan, /clear, etc. |
api.py |
Sends messages to the LLM, runs the tool-call loop until the model stops calling tools |
tools/ |
Workspace tools + dispatch for Skill, memory, session_search, Agent |
context/ |
Micro-compaction, auto-summarize, context window management |
memory/ |
Persistent memory store and memory tool |
sessions/ |
Session DB, event records, and session_search tool |
subagent/ |
Sub-agent runner and Agent tool |
plan_mode.py |
Permission guard for plan mode: allows read-only ops, blocks writes |
skills.py |
Scans .miniclaw/skills/ and injects skill metadata into the system prompt |
settings.py |
Loads and merges config from global + workspace JSON files |
dirs.py |
Resolves user-level (~/.miniclaw/) and workspace-level paths |
config.py |
Path safety checks and API constants |
ui.py |
Terminal UI: startup banner, colored output (powered by rich) |
dev_logging.py |
Developer logging to ~/.miniclaw/logs/ |
| Command | Description |
|---|---|
/plan |
Enter plan mode (read-only exploration) |
/plan <description> |
Enter plan mode with a task description |
/clear |
Clear conversation history |
/model |
Show current model |
/quit /exit /q |
Exit |
Keyboard shortcuts: Ctrl+J newline, Up/Down history, Ctrl+C cancel, Ctrl+D exit.
Config is JSON, with two layers: global (~/.miniclaw/config.json) and workspace ({workspace}/.miniclaw/config.json). Workspace config wins.
Run miniclaw init to create the default config. Use miniclaw init --force to reset.
{
"llm": {
"api_key": "your_api_key",
"model": "MiniMax-M2.7",
"base_url": "https://api.minimaxi.com/v1",
"timeout": 300
},
"plan_mode": {
"allowed_bash_patterns": ["^curl\\s+-s"]
},
"memory": {
"enabled": true
},
"sessions": {
"enabled": true
},
"subagent": {
"enabled": false,
"max_turns": 300
}
}All llm fields can be overridden by environment variables (env vars take priority):
| Variable | Description |
|---|---|
LLM_API_KEY |
LLM API key |
LLM_MODEL |
Model name (default: MiniMax-M2.7) |
LLM_BASE_URL |
OpenAI-compatible API base URL |
LLM_HTTP_TIMEOUT |
HTTP timeout in seconds (default: 300) |
MINICLAW_WORKSPACE |
Workspace directory (also -w flag; CLI flag wins) |
Create .miniclaw/skills/<skill-name>/SKILL.md with YAML frontmatter (name, description) and instructions in the body. The agent sees the skill list at startup and reads the full SKILL.md on demand.
~/.miniclaw/ # User-level (shared across workspaces)
โโโ logs/ # Runtime logs
โโโ memory/ # Persistent memory (MEMORY.md + topic files)
โโโ sessions/ # Session DB (SQLite + FTS)
โโโ config.json # Global config (optional)
{workspace}/.miniclaw/ # Workspace-level (per project)
โโโ config.json # Workspace config (higher priority)
โโโ plans/ # Plan files
โโโ skills/ # Skills directory
miniclaw/
โโโ chat.py # Dev entry point (same as `miniclaw` command)
โโโ pyproject.toml # Package config
โโโ CHANGELOG.md # Release history
โโโ miniclaw/ # The Python package
โ โโโ cli.py # REPL
โ โโโ api.py # LLM API + tool loop
โ โโโ tools/ # Tool implementations + dispatch
โ โโโ context/ # Context compaction + summarization
โ โโโ memory/ # Persistent memory tool
โ โโโ sessions/ # Session records + search
โ โโโ subagent/ # Sub-agent runner + Agent tool
โ โโโ plan_mode.py # Plan mode permissions
โ โโโ config.py # Path safety + constants
โ โโโ dirs.py # Directory resolution
โ โโโ settings.py # Config loading + merge
โ โโโ skills.py # Skill scanning
โ โโโ ui.py # Terminal UI (rich)
โ โโโ dev_logging.py # Dev logging
โโโ tests/ # Unit tests
โโโ docs/design/ # Design docs
See CHANGELOG.md for release history.
| Document | Description |
|---|---|
| ๆถๆๅๆ | ไป Agent LoopใSkill ๆบๅถใTool ่ฎพ่ฎกใPrompt CacheใPlan Mode ไบไธช็ปดๅบฆๆทฑๅ ฅๅๆ้กน็ฎๆถๆ |
| Sub-agent | Sub-agent๏ผAgent tool๏ผ่ฎพ่ฎกไธๅฎ็ฐ่ฏดๆ |
python3 -m pytest tests/ -vminiclaw is meant to stay small and readable. PRs that keep things simple are welcome.
