# micro-claude-code **Repository Path**: luohelios/micro-claude-code ## Basic Information - **Project Name**: micro-claude-code - **Description**: Micro Claude Code 是一个用 Java 21 打造的开源 AI 编程助手,支持终端 TUI / Web 远程 / 多智能体协作三种模式,接入 Claude、GPT 及兼容 API,通过 MCP 协议扩展工具生态,让 AI 直接在终端中读写代码、执行命令、协同完成复杂工程任务。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-04 - **Last Updated**: 2026-10-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: ClaudeCode, AIAgent, Java, AICode ## README # Micro Claude Code [![Java](https://img.shields.io/badge/Java-21-orange?style=flat-square&logo=openjdk)](https://openjdk.org/) [![Gradle](https://img.shields.io/badge/Gradle-8.3-blue?style=flat-square&logo=gradle)](https://gradle.org/) [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](LICENSE) [![Build](https://img.shields.io/badge/Build-Passing-brightgreen?style=flat-square)](#building) > A powerful Java-based AI coding assistant with TUI, Web UI, and multi-agent orchestration capabilities. [Features](#features) • [Installation](#installation) • [Configuration](#configuration) • [Usage](#usage) • [Architecture](#architecture) • [Tools](#built-in-tools) • [Teams](#multi-agent-teams) • [MCP](#mcp-integration) --- ## Features **Multiple Operating Modes** - **TUI Mode**: Interactive terminal interface with Markdown rendering and streaming output - **Web Mode**: Remote access via HTTP/WebSocket server (default: `localhost:18888`) - **Print Mode**: Non-interactive single-shot execution for scripts and CI/CD pipelines **LLM Support** - Anthropic Claude (native SDK with Extended Thinking support) - OpenAI GPT-4o and compatible models - DeepSeek and other OpenAI-compatible APIs - Model Context Protocol (MCP) integration for tool discovery **Built-in Development Tools** - File operations: `ReadFile`, `WriteFile`, `EditFile` - Search: `Glob` (filename patterns), `Grep` (regex content search) - Execution: `BashTool` (sandboxed shell commands) - Git Worktree management for parallel work - Dynamic tool discovery via `ToolSearch` **Multi-Agent Orchestration** - Coordinator mode for task decomposition and worker management - Team-based collaboration with shared task boards - Mailbox-based asynchronous communication between agents - Sub-agent spawning with customizable tool filters - Background task execution with progress tracking **Intelligent Context Management** - Automatic context compaction with recovery state preservation - Tool result budgeting (large outputs spilled to disk) - Long-term memory system with cross-session persistence - File history tracking with snapshot support - Session persistence and resumption **Extensibility** - Skill system with SOP-driven workflows - Hook engine for pre/post tool execution logic - MCP server integration for external tools - Custom sub-agent definitions --- ## Installation ### Prerequisites - **Java 21+** (JDK with Java 21 toolchain support) - **Gradle 8.3+** (or use the included Gradle wrapper) ### Build from Source ```bash # Clone the repository git clone https://github.com/your-org/micro-claude-code.git cd micro-claude-code # Build the project ./gradlew build # Run tests ./gradlew test # Create executable JAR ./gradlew shadowJar # Output: build/libs/micro-claude-code.jar ``` ### Quick Start ```bash # TUI mode (default) ./gradlew run # Web mode ./gradlew run --args="--remote" # Web mode with custom address ./gradlew run --args="--remote=:9000" # Print mode (non-interactive) ./gradlew run --args="-p 'Explain this codebase'" # With custom config file ./gradlew run --args="path/to/config.yaml" ``` --- ## Configuration ### Configuration File Micro Claude Code looks for configuration in the following order: 1. Path specified via CLI argument 2. `MICRO_CLAUDE_CODE_CONFIG` environment variable 3. `config.yaml` in project root ### Example Configuration ```yaml # Provider configuration providers: - name: anthropic-official protocol: anthropic base_url: https://api.anthropic.com api_key: "${ANTHROPIC_API_KEY}" model: claude-sonnet-4-20250514 thinking: true - name: openai-official protocol: openai base_url: https://api.openai.com/v1 api_key: "${OPENAI_API_KEY}" model: gpt-4o - name: deepseek protocol: openai-compat base_url: https://api.deepseek.com api_key: "${DEEPSEEK_API_KEY}" model: deepseek-chat # Permission mode: default | plan | auto permission_mode: default # MCP servers mcp_servers: - name: context7 command: npx args: ["-y", "@upstash/context7-mcp"] - name: custom-http-mcp url: https://example.com/mcp transport: http # or "sse" headers: Authorization: "Bearer ${MY_TOKEN}" # Multi-agent coordination mode enable_coordinator_mode: false ``` ### Environment Variables | Variable | Description | |----------|-------------| | `ANTHROPIC_API_KEY` | Anthropic API key | | `OPENAI_API_KEY` | OpenAI API key | | `DEEPSEEK_API_KEY` | DeepSeek API key | | `MICRO_CLAUDE_CODE_CONFIG` | Path to custom config file | --- ## Usage ### TUI Mode Launch the interactive terminal interface: ```bash ./gradlew run # or java -jar build/libs/micro-claude-code.jar ``` **Key Features:** - Markdown rendering in terminal - Streaming response display - Slash commands (`/clear`, `/help`, `/quit`, etc.) - Session resumption with `/resume` - Provider selection at startup (if multiple configured) ### Web Mode Start the HTTP/WebSocket server: ```bash ./gradlew run --args="--remote" # Server listens on http://localhost:18888 ``` Access the web interface at `http://localhost:18888` for remote collaboration. ### Print Mode Non-interactive execution for automation: ```bash # Text output ./gradlew run --args="-p 'Analyze the code quality'" # JSON streaming output ./gradlew run --args="-p 'List all TODO comments' --output-format stream-json" ``` ### CLI Arguments ``` Usage: micro-claude-code [options] [config-path] Options: -p Non-interactive mode with given prompt --output-format Output format: text | stream-json (default: text) --remote Enable web server mode --remote= Web server with custom address (default: :18888) --teammate Run as team worker process (internal use) --team-name Team name for teammate mode --agent-name Agent name for teammate mode Arguments: config-path Path to configuration file (optional) ``` --- ## Architecture ``` ┌─────────────────────────────────────────────────────────────┐ │ Entry Point │ │ (MicroClaudeCode.main) │ └─────────────────────────────────────────────────────────────┘ │ ┌─────────────────────┼─────────────────────┐ │ │ │ ▼ ▼ ▼ ┌───────────────┐ ┌─────────────────┐ ┌──────────────┐ │ TUI Mode │ │ Web Mode │ │ Print Mode │ │ (JLine + │ │ (Javalin │ │ (stdout) │ │ Mordant) │ │ HTTP/WS) │ │ │ └───────┬───────┘ └────────┬────────┘ └──────┬───────┘ │ │ │ └────────────────────┼────────────────────┘ │ ┌────────▼────────┐ │ Agent Core │ │ (Agent.java) │ └────────┬────────┘ │ ┌────────────────────┼────────────────────┐ │ │ │ ▼ ▼ ▼ ┌───────────────┐ ┌─────────────────┐ ┌──────────────┐ │ Tool Registry │ │ LLM Clients │ │ Context │ │ & Built-in │ │ (Anthropic, │ │ Manager │ │ Tools │ │ OpenAI, etc.) │ │ │ └───────────────┘ └─────────────────┘ └──────────────┘ ``` ### Core Components | Component | Description | |-----------|-------------| | `MicroClaudeCode` | Main entry point, CLI argument parsing, mode selection | | `Agent` | Core agent loop, streaming execution, tool orchestration | | `ToolRegistry` | Tool registration, schema management, deferred loading | | `ConversationManager` | Message history, tool pairing, system reminders | | `LlmClient` | Abstract LLM interface (Anthropic, OpenAI, OpenAI-compat) | | `ContextCompactor` | Automatic context window management | | `MemoryManager` | Long-term memory persistence and recall | | `TeamManager` | Multi-agent team coordination | | `McpManager` | MCP server connections and tool integration | | `HookEngine` | Pre/post tool execution hooks | --- ## Built-in Tools ### File Operations | Tool | Description | |------|-------------| | `ReadFile` | Read file contents with optional line range | | `WriteFile` | Create or overwrite entire files | | `EditFile` | Search-and-replace based editing | | `Glob` | Find files matching glob patterns | | `Grep` | Search file contents with regex | ### Execution | Tool | Description | |------|-------------| | `BashTool` | Execute shell commands (sandboxed) | ### Git Integration | Tool | Description | |------|-------------| | `EnterWorktree` | Create/switch to Git worktree | | `ExitWorktree` | Leave current worktree | ### Dynamic Tools | Tool | Description | |------|-------------| | `ToolSearch` | Discover and load deferred/MCP tools | | `AskUserQuestion` | Prompt user for input | | `ExitPlanMode` | Exit plan mode and start execution | | `SyntheticOutput` | Return structured output | ### Sub-Agents | Tool | Description | |------|-------------| | `Agent` | Spawn sub-agent with customizable type and tools | Available sub-agent types: - `explore` — Read-only codebase exploration - `plan` — Architecture and planning - `general-purpose` — Full tool access ### Team Coordination | Tool | Description | |------|-------------| | `TeamCreate` | Create a new team | | `TeamDelete` | Disband a team | | `SendMessage` | Send message to team member | | `TaskStop` | Stop a running teammate | | `TaskCreate/Get/List/Update` | Shared task board operations | --- ## Multi-Agent Teams Micro Claude Code supports orchestrating multiple AI agents for complex tasks. ### Coordinator Mode Enable in `config.yaml`: ```yaml enable_coordinator_mode: true ``` In coordinator mode, the lead agent: - Cannot read/write files or run commands directly - Orchestrates worker agents via `Agent` and `SendMessage` - Synthesizes results from worker outputs - Manages team lifecycle with `TeamDelete` ### Team Workflow ``` ┌─────────────────┐ │ Lead Agent │ (Coordinator) │ (User-facing) │ └────────┬────────┘ │ Creates team, spawns workers ▼ ┌─────────────────┐ │ Team Manager │ (Shared state) │ - Mailbox │ │ - Task Board │ └────────┬────────┘ │ ┌────┴────┐ │ │ ▼ ▼ ┌────────┐ ┌────────┐ │Worker A│ │Worker B│ (Teammates) │(explore)│ │(implement)│ └────────┘ └────────┘ ``` ### Example: Team Creation ```java // Lead agent creates team and spawns workers TeamCreate({ "name": "feature-team" }) Agent({ "team_name": "feature-team", "name": "researcher", "description": "researcher", "prompt": "Analyze the codebase and identify all API endpoints..." }) Agent({ "team_name": "feature-team", "name": "implementer", "description": "implementer", "prompt": "Implement the new feature based on the research..." }) // Workers communicate via SendMessage // Lead receives results via team mailbox ``` ### Teammate Process Teammates run as separate processes (via tmux/iTerm or in-process): ```bash # Internal teammate invocation java -jar micro-claude-code.jar --teammate \ --team-name my-team \ --agent-name worker-1 ``` --- ## MCP Integration [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) enables integration with external tools and data sources. ### Configuration ```yaml mcp_servers: # stdio transport (local process) - name: filesystem command: npx args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"] # HTTP/SSE transport (remote server) - name: custom-api url: https://mcp.example.com transport: http # or "sse" headers: Authorization: "Bearer ${API_TOKEN}" ``` ### MCP Tool Naming MCP tools are namespaced: `mcp____` Example: `mcp__filesystem__read_file` ### Deferred Tool Loading MCP tools use deferred loading to reduce context size: 1. Tools start hidden from the initial tool list 2. Agent uses `ToolSearch` to discover tools by query 3. Discovered tools are loaded into the registry 4. Available in subsequent requests --- ## Skill System Skills are SOP-driven workflows loaded from `.micro-claude-code/skills/` or project directories. ### Skill Structure ``` .my-skill/ ├── skill.md # Skill definition and SOP └── resources/ # Optional supporting files ``` ### Loading Skills ```java // Via tool LoadSkill({ "name": "my-skill" }) // Or install new skill InstallSkill({ "url": "https://example.com/skill.zip" }) ``` Skills inject their SOP into the conversation context, guiding the agent through complex workflows. --- ## Hook Engine Hooks execute custom logic before/after tool calls. ### Configuration ```yaml hooks: - id: log-edits event: tool_post condition: "tool == 'EditFile'" type: command command: "echo 'File edited: ${args.file_path}'" async: true ``` ### Hook Events | Event | Description | |-------|-------------| | `tool_pre` | Before tool execution | | `tool_post` | After tool execution | | `session_start` | Session initialization | | `session_end` | Session termination | ### Hook Actions | Type | Description | |------|-------------| | `command` | Execute shell command | | `prompt` | Inject system reminder | | `http` | HTTP webhook | | `agent` | Spawn sub-agent | --- ## Context Management ### Auto-Compaction When context approaches the window limit: 1. Old messages are summarized 2. Recent file reads are preserved 3. Active skill SOPs are retained 4. Summary injected as system message ### Tool Result Budgeting Large tool outputs are managed: 1. Outputs exceeding threshold are spilled to disk 2. Preview returned to conversation 3. Full content accessible via `ReadFile` 4. Exemption for readback operations ### Memory System Long-term memory persists across sessions: - **Instructions**: Project-specific guidance (`.micro-claude-code/instructions.md`) - **Memories**: Learned facts and preferences (`.micro-claude-code/memories/`) - **Recall**: Automatic context-aware memory selection --- ## Security ### Sandboxed Execution Shell commands run in OS-level sandboxes: **macOS (Seatbelt)** ```yaml sandbox: writable_paths: ["./", "/tmp"] deny_write: ["/etc", "/System"] allow_network: false ``` **Linux (Bubblewrap)** ```yaml sandbox: writable_paths: ["./", "/tmp"] deny_write: ["/etc", "/usr"] allow_network: false ``` ### Permission Modes | Mode | Description | |------|-------------| | `default` | Prompt user for dangerous operations | | `plan` | Read-only mode for planning | | `auto` | Auto-approve all operations | --- ## Building ### Development Build ```bash ./gradlew build ``` ### Run Tests ```bash ./gradlew test ``` ### Create Distribution ```bash # Executable JAR ./gradlew shadowJar # Output: build/libs/micro-claude-code.jar # Distribution packages ./gradlew distZip # build/distributions/micro-claude-code.zip ./gradlew distTar # build/distributions/micro-claude-code.tar ``` ### Run with Gradle ```bash ./gradlew run # TUI mode ./gradlew run --args="--remote" # Web mode ./gradlew run --args="-p 'prompt'" # Print mode ``` --- ## Project Structure ``` micro-claude-code/ ├── src/main/java/com/microclaudecode/ │ ├── agent/ # Agent core loop and events │ ├── command/ # Slash command system │ ├── compact/ # Context compaction │ ├── config/ # Configuration loading │ ├── conversation/ # Message management │ ├── filehistory/ # File change tracking │ ├── history/ # Command history │ ├── hook/ # Hook engine │ ├── llm/ # LLM client implementations │ ├── mcp/ # MCP integration │ ├── memory/ # Long-term memory │ ├── permission/ # Permission checking │ ├── plan/ # Plan mode support │ ├── print/ # Print mode │ ├── prompt/ # System prompt building │ ├── remote/ # Web server │ ├── sandbox/ # OS sandboxing │ ├── session/ # Session persistence │ ├── skill/ # Skill system │ ├── subagent/ # Sub-agent management │ ├── task/ # Task tracking │ ├── teams/ # Multi-agent teams │ ├── tool/ # Tool registry and implementations │ ├── toolresult/ # Tool result processing │ ├── tui/ # Terminal UI │ └── worktree/ # Git worktree management ├── src/test/java/ # Test suite ├── build.gradle.kts # Build configuration └── config.yaml # Example configuration ``` --- ## Contributing Contributions are welcome! Please: 1. Fork the repository 2. Create a feature branch (`git checkout -b feature/amazing-feature`) 3. Write tests for new functionality 4. Ensure all tests pass (`./gradlew test`) 5. Commit your changes (`git commit -m 'Add amazing feature'`) 6. Push to the branch (`git push origin feature/amazing-feature`) 7. Open a Pull Request --- ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. --- ## Acknowledgments - [Anthropic Claude](https://www.anthropic.com/) for the Claude API - [OpenAI](https://openai.com/) for the OpenAI API - [Model Context Protocol](https://modelcontextprotocol.io/) for the MCP specification - [JLine](https://github.com/jline/jline3) for terminal I/O - [Mordant](https://github.com/ajalt/mordant) for Markdown rendering - [Javalin](https://javalin.io/) for the web server --- **Built with Java 21** | **Designed for developers** | **Powered by AI**