A minimal implementation of Claude Code for learning and understanding how AI programming assistants work.
MiniCC (Minimal Claude Code) is an educational AI code assistant, similar to what Minix is to Linux. It provides a clean framework to help developers understand how to build intelligent programming assistants and is designed as an easily extensible agent skeleton.
- 🛠️ Tool System: Extensible tool architecture supporting file operations, command execution, code search
- 🤖 LLM Integration: Supports OpenAI API compatible large language models
- 📝 Session Management: Maintains context for multi-turn conversations
- 🔄 Recursive Execution: AI autonomously completes multi-step tasks
- 🎯 Customizable System Prompt: Easily modify AI behavior via
.minicc/system_prompt.md - 📚 Learning Friendly: Clean code with clear architecture, perfect for learning
minicc/
├── packages/
│ ├── core/ # Core functionality
│ │ ├── llm/ # LLM client
│ │ ├── tools/ # Tool implementations
│ │ └── services/ # Business services
│ ├── sdk/ # Software Development Kit
│ │ └── src/ # SDK API for building agents
│ └── cli/ # Command line interface
│ └── commands/ # CLI commands
├── .minicc/ # Configuration
│ └── system_prompt.md # Customizable system prompt
└── .history/ # Session history storage
The core innovation is the recursive tool execution that allows AI to complete multi-step tasks autonomously:
flowchart TD
Start([User Input]) --> AddMsg[Add User Message to Session]
AddMsg --> Process[processConversation]
Process --> BuildPrompt[Build Messages Array<br/>System + History + User]
BuildPrompt --> CallAPI[Call LLM API<br/>with Tools Definitions]
CallAPI --> CheckTools{AI Response<br/>Has Tool Calls?}
CheckTools -->|Yes| SaveTools[Save AI Tool Request<br/>to Session]
SaveTools --> ExecuteTools[Execute Each Tool]
ExecuteTools --> SaveResults[Save Tool Results<br/>to Session]
SaveResults --> Recurse[Recursively Call<br/>processConversation]
Recurse --> Process
CheckTools -->|No| SaveResponse[Save AI Text Response<br/>to Session]
SaveResponse --> Return([Return Final Answer])
style Start fill:#e1f5e1
style Return fill:#e1f5e1
style Recurse fill:#ffe1e1
style Process fill:#fff4e1
- Single Entry Point: All interactions go through
processConversation() - AI-Driven Flow: The AI decides when to use tools and when to stop
- Natural Termination: When AI returns text without tools, the recursion ends
- Stateful Sessions: All messages (user, assistant, tool results) are preserved
git clone https://github.com/yinwm/minicc.git
cd miniccpnpm installSet environment variables:
# Temporary (current session)
export OPENAI_API_KEY=your-api-key-here
export OPENAI_BASE_URL=https://api.openai.com/v1 # Or other compatible API
export MODEL=gpt-4 # Or other model
# Or run directly
OPENAI_API_KEY=your-api-key-here OPENAI_BASE_URL=https://api.openai.com/v1 pnpm chat
# Permanent (add to ~/.bashrc or ~/.zshrc)
echo 'export OPENAI_API_KEY=your-api-key-here' >> ~/.bashrc
echo 'export OPENAI_BASE_URL=https://api.openai.com/v1' >> ~/.bashrcpnpm build# Interactive chat mode
pnpm chat
# Single query
pnpm minicc -p "List all files in current directory"
# With session management
pnpm sessions --listfile_read: Read file contentsfile_write: Write entire filefile_list: List directory files
file_edit: Find and replace contentfile_insert: Insert at specific linefile_delete_lines: Delete line ranges
shell_execute: Execute system commandscode_search: Search patterns in code
Customize AI behavior by editing .minicc/system_prompt.md:
vim .minicc/system_prompt.mdThe file uses Markdown format for easy editing and version control. Changes are applied on next run.
- Create a tool class extending
BaseTool:
import { BaseTool, ToolExecutionResult } from './base.tool';
export class MyTool extends BaseTool {
name = 'my_tool';
description = 'My custom tool';
parameters = {
type: 'object',
properties: {
input: { type: 'string' }
},
required: ['input']
};
async execute(args: any): Promise<ToolExecutionResult> {
// Implement your logic
return { success: true, data: 'result' };
}
}- Register in tool registry
$ pnpm chat
╭───────────────────────────────────────╮
│ MiniCC - AI Programming Assistant │
│ Type "exit" or "quit" to leave │
╰───────────────────────────────────────╯
✓ Loaded system prompt from .minicc/system_prompt.md
Your question: Read README.md and summarize it# File operations
pnpm minicc -p "Read package.json"
pnpm minicc -p "List all TypeScript files"
pnpm minicc -p "Search for TODO comments"
# Code modifications
pnpm minicc -p "Add a comment to main function"
pnpm minicc -p "Fix the import statements"
# Shell operations
pnpm minicc -p "Run npm test"
pnpm minicc -p "Check git status"pnpm build # Build all packages
pnpm minicc # Start interactive mode
pnpm minicc -p # Execute single query
pnpm sessions # Manage sessions
pnpm clean # Clean build artifactsInstall globally and use as a command-line tool:
# Install CLI
npm install -g @minicc/cli
# Use commands
minicc chat
minicc query "List all files"
minicc sessions --listInstall SDK and integrate into your applications:
# Install SDK
npm install @minicc/sdkimport { createAgent, BaseTool } from '@minicc/sdk';
class SqlQueryTool extends BaseTool {
name = 'sql_query';
description = 'Execute SQL queries';
parameters = {
type: 'object',
properties: { query: { type: 'string' } },
required: ['query']
};
async execute(args: any) {
// Your business logic
return { success: true, data: 'Results...' };
}
}
const agent = createAgent({
model: 'gpt-4',
systemPrompt: 'You are a helpful assistant',
tools: [new SqlQueryTool()],
openaiConfig: {
apiKey: process.env.OPENAI_API_KEY
}
});
const response = await agent.chat('session-1', 'Query all users');- Tool System: See
packages/core/src/tools/for tool implementations - LLM Integration: Check
packages/core/src/llm/for API integration - Session Management: Review
packages/core/src/services/session.service.ts - CLI Structure: Explore
packages/cli/src/commands/for CLI implementation - SDK Usage: Check
packages/sdk/README.mdfor SDK documentation
Q: How to use other LLMs?
A: Set OPENAI_BASE_URL to any OpenAI-compatible API endpoint (e.g., Ollama, LM Studio, SiliconFlow)
Q: Where are sessions stored?
A: In .history/ directory, automatically created on first run
Q: How to reset the system prompt?
A: Edit .minicc/system_prompt.md or delete it to use defaults
Q: Can I use this in production?
A: MiniCC is designed for learning. For production, use official Claude Code or mature alternatives
Contributions welcome! Focus on:
- Clear, educational code
- Tool extensions
- Documentation improvements
- Bug fixes
MIT
💡 Note: MiniCC is an educational project for understanding AI assistants. For production use, consider official solutions.