FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

kkkhs/ClawdCode: ๐Ÿฆ€ An AI-Powered CLI Coding Agent - Your intelligent coding companion in the terminal ยท GitHub

Repository files navigation

ClawdCode

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


โœจ Features

๐Ÿค– Intelligent Agent

  • Agentic Loop: LLM + System Prompt + Context + Tools
  • Streaming output with real-time response
  • Thinking process with auto-collapse/expand
  • Tool call display with compact dim-styled logs
  • AbortController-based Ctrl+C interruption

๐Ÿ› ๏ธ Built-in Tools (7)

  • Read / Write / Edit โ€” file operations with diff preview
  • Glob / Grep โ€” fast code search and pattern matching
  • Bash โ€” shell execution with permission control
  • MCP โ€” external tool integration via Model Context Protocol

๐Ÿ”’ Security & Permissions

  • 4 permission modes: default / autoEdit / yolo / plan
  • 7-stage execution pipeline with safety checks
  • Inline permission prompt above input area
  • Sensitive file detection (.env, credentials, etc.)
  • Deny stops agent immediately โ€” no continued thinking

๐ŸŽจ Terminal UI

  • Ink (React for CLI) โ€” declarative interactive UI
  • Markdown rendering with 140+ language syntax highlighting
  • 5 built-in themes with auto dark/light detection
  • Theme persistence across sessions
  • Code block file paths and /copy clipboard support

๐Ÿงฉ Extensions

  • Slash Commands โ€” /help, /compact, /model, /theme, ...
  • Custom Commands โ€” Markdown files as commands, zero code
  • Skills โ€” pluggable agent capabilities via SKILL.md
  • Hooks โ€” 11 lifecycle events with pre/post shell scripts

๐Ÿ“ฆ State & Context

  • Zustand store with fine-grained subscriptions
  • Token counting and auto-compaction
  • Session persistence and resume (--continue)
  • Command history with arrow key navigation
  • MCP Registry for external tool servers

๐Ÿ“ฅ Installation

# npm
npm install -g clawdcode

# pnpm
pnpm add -g clawdcode

# bun (recommended)
bun add -g clawdcode

๐Ÿš€ Quick Start

1. Configure API Key

# 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

2. Start Coding

# Interactive mode
clawdcode

# With initial message
clawdcode "analyze this project structure"

# With specific model
clawdcode --model gpt-4o

# Resume previous session
clawdcode --continue

3. Slash Commands

/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

๐Ÿ—๏ธ Architecture

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                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Custom Commands

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 tests
Dynamic 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

โš™๏ธ Configuration

ClawdCode supports multiple configuration methods (in priority order):

  1. CLI arguments โ€” --api-key, --base-url, --model
  2. Environment variables โ€” OPENAI_API_KEY, OPENAI_BASE_URL
  3. Project config โ€” ./.clawdcode/config.json
  4. 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:*) โ†’ matches npm 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.

๐Ÿ’ป CLI Options

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

๐Ÿ”ง Tech Stack

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

๐Ÿ“– Documentation

๐Ÿ“š 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

๐Ÿ’ก Examples

# 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"

๐Ÿ›  Development

# 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 typecheck

๐Ÿค Contributing

Contributions welcome. Please submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feat/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

MIT ยฉ 2024-present


Built with โค๏ธ by kkkhs

About

๐Ÿฆ€ An AI-Powered CLI Coding Agent - Your intelligent coding companion in the terminal

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages


Back | FazBrowse Home | New Git URL