Skip to content
ย 
ย 

Latest commit

ย 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

miniclaw

Your tiny coding claw
Learn to build an AI coding agent in ~1500 lines of Python

PyPI Python MIT License

English | ไธญๆ–‡


What is miniclaw?

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.

Features

  • 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.md into .miniclaw/skills/<name>/ and the agent learns new tricks. Skills are injected into the system prompt automatically; the Skill tool loads full instructions on demand.
  • Memory -- Durable facts live in ~/.miniclaw/memory/MEMORY.md and 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 Agent tool spawns an isolated sub-agent (explore / general) so research or side tasks don't pollute the main context. Enable with subagent.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.

Quick Start

Install:

pip install miniclaw

Run:

export LLM_API_KEY=your_api_key
cd ~/my-project
miniclaw

That'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 miniclaw

From source (for hacking):

git clone https://github.com/sundl123/miniclaw.git
cd miniclaw
pip install -e .

Tip: If you get command not found: miniclaw after installing, your Python scripts directory isn't in PATH. Run pipx ensurepath (pipx) or add ~/.local/bin to your PATH (pip).

How It Works

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
Loading

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/

Commands

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.

Configuration

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)

Skills

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.

File Layout

~/.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

Project Structure

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

Changelog

See CHANGELOG.md for release history.

Design Documents

Document Description
ๆžถๆž„ๅˆ†ๆž ไปŽ Agent Loopใ€Skill ๆœบๅˆถใ€Tool ่ฎพ่ฎกใ€Prompt Cacheใ€Plan Mode ไบ”ไธช็ปดๅบฆๆทฑๅ…ฅๅˆ†ๆž้กน็›ฎๆžถๆž„
Sub-agent Sub-agent๏ผˆAgent tool๏ผ‰่ฎพ่ฎกไธŽๅฎž็Žฐ่ฏดๆ˜Ž

Running Tests

python3 -m pytest tests/ -v

Contributing

miniclaw is meant to stay small and readable. PRs that keep things simple are welcome.

License

MIT

About

๐Ÿฆž๐Ÿฆ€ Your tiny coding claw. Learn to build an AI coding agent from scratchโ€”small, simple, powerful.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages