中文 | English
A lightweight CLI Agent implementation, perfect for learning Agent development as an educational project.
- 🤖 Intelligent Conversation - LLM-based dialogue capabilities (supports multiple models)
- 🔧 Tool Calling - Supports bash command execution and file reading
- 📺 Streaming Output - Real-time display of thinking process
- 🎨 Colorful Terminal - User-friendly interface design
- 📚 Education-Friendly - Clean code, clear structure, ~300 lines
Linux / macOS:
curl -fsSL https://raw.githubusercontent.com/fak111/minicode/main/install.sh | bashWindows (PowerShell):
irm https://raw.githubusercontent.com/fak111/minicode/main/install.ps1 | iexAfter installation:
Linux / macOS:
-
Set your API Key:
export OPENAI_API_KEY="your-api-key-here"
-
Add
~/.local/binto your PATH (if not already added):export PATH="$HOME/.local/bin:$PATH" # Add this line to ~/.bashrc or ~/.zshrc for persistence
-
Run MiniCode:
minicode
Windows:
- Add
%USERPROFILE%\AppData\Local\binto your system PATH environment variable - Set your API Key:
$env:OPENAI_API_KEY="your-api-key-here"
- Restart your terminal and run:
minicode
The installation script will:
- Check and install Bun if needed
- Clone the repository to
~/.minicode(Linux/macOS) or%USERPROFILE%\.minicode(Windows) - Install dependencies
- Create a global
minicodecommand
cd minicode
bun installcp .env.example .env
# Edit .env file and add your API KeyOr set environment variables directly:
export OPENAI_API_KEY="your_api_key_here"One-shot Mode (Single Execution):
bun run dev "read package.json"
bun run dev "List files and tell me about the project"REPL Mode (Interactive Conversation):
bun run devThen enter your questions:
➜ What does this project do?
minicode/
├── package.json # Project configuration
├── tsconfig.json # TypeScript configuration
├── .env.example # Environment variables example
├── README.md # This file
└── src/
├── config.ts # Configuration management
├── tools.ts # Tool definitions
├── session.ts # Session management + ReAct loop
└── cli.ts # CLI entry point
cli.ts → NanoSession.chat() → OpenAI API (streaming)
↓
Tool calls → runTool() → bash / read_file
↓
Results → Return to LLM for continued thinking
| File | Lines | Responsibility |
|---|---|---|
| config.ts | ~60 | Config loading, type definitions, System Prompt |
| tools.ts | ~70 | Tool definitions, tool execution, output truncation |
| session.ts | ~80 | ReAct loop, streaming output processing |
| cli.ts | ~55 | REPL loop, user interaction |
MiniCode uses the ReAct Pattern (Reasoning + Acting):
- Think: User input → LLM analysis
- Act: LLM decides to call tools → Execute tools
- Observe: Tool results → Return to LLM
- Repeat: LLM continues thinking or responds based on results
This project demonstrates:
- Environment Variable Configuration - Reading from
process.envinconfig.ts - Tool Definitions - JSON Schema definitions in
tools.ts - ReAct Loop -
whileloop insession.ts - Streaming Output -
for await...ofiteration insession.ts - REPL Implementation -
readline/promisesincli.ts
Steps to add new tools:
- Add definition to the
TOOLSarray intools.ts - Add execution logic to the
runTool()function - Document the new tool in
SYSTEM_PROMPTinconfig.ts
| Variable | Required | Default | Description |
|---|---|---|---|
OPENAI_API_KEY |
Yes | - | API Key |
OPENAI_BASE_URL |
No | https://api.deepseek.com |
API Base URL |
OPENAI_MODEL |
No | deepseek-chat |
Model name |
WORKDIR |
No | Current directory | Working directory |
MiniCode supports any OpenAI API-compatible models, such as:
deepseek-chat- DeepSeek chat model (default)deepseek-coder- DeepSeek code modelgpt-4-turbo- OpenAI GPT-4 Turbogpt-3.5-turbo- OpenAI GPT-3.5 Turboqwen-turbo- Qwen model- Other OpenAI API-compatible models
Usage Examples:
# Use GPT-4 Turbo
export OPENAI_MODEL="gpt-4-turbo"
export OPENAI_BASE_URL="https://api.openai.com/v1"
# Use DeepSeek Coder
export OPENAI_MODEL="deepseek-coder"
export OPENAI_BASE_URL="https://api.deepseek.com"
# Use Qwen
export OPENAI_MODEL="qwen-turbo"
export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"- Bun - Runtime
- OpenAI SDK - LLM interface
- picocolors - Colored output
This project is partially inspired by the open-source AI Coding Agent project OpenCode.
MIT