An AI-Powered CLI Coding Agent
Inspired by Claude Code β read, write, and execute code directly in your terminal.
Features β’ Installation β’ Quick Start β’ Architecture β’ Documentation
|
|
|
|
|
|
# npm
npm install -g clawdcode
# pnpm
pnpm add -g clawdcode
# bun (recommended)
bun add -g clawdcode# Interactive setup
clawdcode --init
# Or set environment variable
export OPENAI_API_KEY=sk-your-api-key
# Or use other OpenAI-compatible providers
export OPENAI_BASE_URL=https://api.deepseek.com
export OPENAI_API_KEY=sk-your-deepseek-key# Interactive mode
clawdcode
# With initial message
clawdcode "analyze this project structure"
# With specific model
clawdcode --model gpt-4o
# Resume previous session
clawdcode --continue/help Show all commands
/clear Clear conversation
/compact Compress context (save tokens)
/model Switch model interactively
/theme Switch theme (dark/light/ocean/forest/sunset)
/status Show session info
/copy Copy code block to clipboard (/copy list)
/thinking Toggle thinking block expand/collapse
/mcp MCP server status
/hooks List active hooks
/skills List loaded skills
Coding Agent = LLM + System Prompt + Context + Tools
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLI Entry (yargs) β
β β β
β Agent Loop ββββββββββββββββββββββββββββββββ β
β ββ Build Context (messages + tools) β β
β ββ Call LLM (streaming) β β
β ββ Parse Response β β
β β ββ text β render to UI β β
β β ββ tool_calls β Execution Pipeline β β
β β ββ 1. Discovery β β
β β ββ 2. Permission β β
β β ββ 3. Pre-Hooks β β
β β ββ 4. Confirmation (UI) β β
β β ββ 5. Execute β β
β β ββ 6. Post-Hooks β β
β β ββ 7. Format β β
β ββ Inject Results βββββββββββββββββββββββ β
β β
β Store (Zustand) β β UI (Ink/React) β β Theme Manager β
β Context Manager β β Token Counter β β Compaction β
β MCP Registry β β External Tool Servers β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Create project-specific commands in .clawdcode/commands/ (shareable via Git):
.clawdcode/commands/review.md
---
description: Code review for current changes
---
Review the current Git changes.
## Changes
!`git diff --stat HEAD~1`
## Requirements
1. Summarize what changed
2. Point out potential issues
3. Suggest improvements.clawdcode/commands/test.md
---
description: Run tests and analyze failures
argument-hint: [test file or pattern]
allowed-tools:
- Bash(npm:*)
- Read
---
Run tests: $ARGUMENTS
If any test fails, analyze the cause and suggest fixes.Then use them:
/review # Code review
/test src/utils # Run specific testsDynamic Content Syntax
| Syntax | Description | Example |
|---|---|---|
$ARGUMENTS |
All arguments | /cmd foo bar β foo bar |
$1, $2 |
Positional args | /greet Alice β $1=Alice |
!`cmd` |
Bash embed | !`git branch` |
@path |
File reference | @package.json |
ClawdCode supports multiple configuration methods (in priority order):
- CLI arguments β
--api-key,--base-url,--model - Environment variables β
OPENAI_API_KEY,OPENAI_BASE_URL - Project config β
./.clawdcode/config.json - User config β
~/.clawdcode/config.json
Config File Example
{
"default": {
"apiKey": "sk-your-api-key",
"baseURL": "https://api.openai.com/v1",
"model": "gpt-4o"
},
"ui": {
"theme": "dark"
},
"permissions": {
"allow": ["Bash(npm:*)", "Bash(git:*)"],
"deny": ["Bash(rm -rf:*)"]
},
"mcpServers": {
"filesystem": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
}
}
}Permission Modes
| Mode | Read | Write | Execute | Description |
|---|---|---|---|---|
default |
β | β | β | Ask for write/execute |
autoEdit |
β | β | β | Auto-approve writes |
yolo |
β | β | β | Full auto mode |
plan |
β | β | β | Read-only analysis |
clawdcode --permission yolo "fix all lint errors automatically"Permission Rules
{
"permissions": {
"allow": [
"Read(**/*.ts)",
"Bash(npm:*)",
"Bash(git:*)"
],
"deny": [
"Bash(rm -rf:*)",
"Write(/etc/*)"
]
}
}Rule format: ToolName(pattern)
- Exact:
Bash(npm test) - Prefix:
Bash(npm:*)β matchesnpm install,npm test, etc. - Glob:
Read(**/*.ts)β matches all TypeScript files
Hooks
Add lifecycle hooks in .clawdcode/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": ["echo 'About to run shell command: $TOOL_INPUT'"]
}
],
"PostToolUse": [
{
"matcher": "Write",
"hooks": ["npx prettier --write $FILE_PATH"]
}
],
"Notification": [
{
"matcher": "",
"hooks": ["terminal-notifier -message '$NOTIFICATION_MESSAGE'"]
}
]
}
}11 hook events: PreToolUse, PostToolUse, Stop, UserPromptSubmit, Notification, etc.
Usage: clawdcode [options] [message]
Options:
--api-key, -k OpenAI API key
--base-url, -b OpenAI API base URL
--model, -m Model to use (default: gpt-4o)
--permission, -p Permission mode (default/autoEdit/yolo/plan)
--theme, -t Color theme (dark/light/ocean/forest/sunset)
--continue, -c Resume previous session
--debug, -d Enable debug mode
--init Create default config file
--help, -h Show help
--version, -v Show version
| Technology | Role |
|---|---|
| TypeScript | Type safety, strict mode |
| Bun | Build & runtime |
| Ink | React for CLI β declarative terminal UI |
| Zustand | Lightweight state management |
| OpenAI SDK | Compatible with OpenAI / DeepSeek / local models |
| Zod | Runtime parameter validation |
| MCP | Model Context Protocol for external tools |
| lowlight | 140+ language syntax highlighting |
π Complete Tutorial β 17 Chapters β Build an AI CLI Coding Agent from scratch
| Part | Chapters | Topics |
|---|---|---|
| Getting Started | 01 - 03 | Coding Agent overview, project setup, CLI entry |
| Core Architecture | 04 - 07 | Agent core, system prompt, tool system, execution pipeline |
| System Integration | 08 - 12 | Context management, UI system, MCP protocol, state management, command history |
| Extensions | 13 - 17 | Slash commands, interactive commands, streaming & themes, skills, hooks |
# Analyze project structure
clawdcode "analyze this project's architecture"
# Fix TypeScript errors
clawdcode "fix all TypeScript type errors"
# Code review (read-only mode)
clawdcode --permission plan "review the recent code changes"
# Full auto mode
clawdcode --permission yolo "format all files with prettier"
# Use DeepSeek
clawdcode --base-url https://api.deepseek.com --model deepseek-chat "refactor this function"# Clone
git clone https://github.com/kkkhs/ClawdCode.git
cd ClawdCode
# Install
bun install
# Dev
bun run dev
# Build
bun run build
# Type check
bun run typecheckContributions welcome. Please submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feat/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feat/amazing-feature) - Open a Pull Request
MIT Β© 2024-present
Built with β€οΈ by kkkhs