Code Expert - An AI coding assistant CLI built with LangGraph and OpenAI, adapted from Claude Code.
Copert is a command-line coding assistant that helps you with software engineering tasks including writing code, debugging, refactoring, searching codebases, and more. Built on LangGraph for multi-agent orchestration and powered by OpenAI's GPT models.
- Interactive REPL: Continuous conversation with context preservation
- File Operations: Read, write, and edit files
- Code Search: Search for patterns using ripgrep and glob
- Command Execution: Run bash commands and scripts
- ReAct Pattern: Reasoning + Acting agent loop for complex tasks
- Tool Calling: Native OpenAI function calling with LangChain tools
- Command History: Navigate previous commands with arrow keys
Copert requires ripgrep for code search functionality:
# macOS
brew install ripgrep
# Linux
apt install ripgrep # Debian/Ubuntu
yum install ripgrep # RedHat/CentOS
# Windows
choco install ripgrepInstall Copert CLI globally to use from any directory:
# Clone the repository
git clone git@github.com:danielfang001/copert-cli.git
cd copert-cli
# Install globally with uv tool
uv tool install --editable .
# Update shell PATH (one-time setup)
uv tool update-shell
# Restart your shell or run:
export PATH="$HOME/.local/bin:$PATH"Now you can use copert from anywhere!
# Clone the repository
git clone git@github.com:danielfang001/copert-cli.git
cd copert-cli
# Install dependencies with uv
uv syncCreate a .env.copert file in your project directory (or working directory where you invoke copert):
OPENAI_API_KEY=your_key_here
LANGSMITH_API_KEY=your_langsmith_key
EXA_API_KEY=your_exa_key
OPENAI_MODEL=gpt-4.1 # recommend using gpt-5 if you have are verified for api streaming
OPENAI_TEMPERATURE=0.1
OPENAI_MAX_TOKENS=4096
MAX_ITERATIONS=25Note: Copert uses .env.copert instead of .env to avoid conflicts with your project's environment variables.
Copert supports project-specific context files similar to Claude Code's CLAUDE.md feature. When you have a COPERT.md file in your project directory, Copert automatically loads it into the session context to provide better, project-aware assistance.
Use the /init command to automatically generate a COPERT.md file:
$ copert
You: /initThe init command spawns a specialized sub-agent that:
- Reads your README.md and dependency files (pyproject.toml, package.json, etc.)
- Analyzes your project architecture
- Creates a comprehensive COPERT.md file with:
- Common development commands (build, test, lint)
- High-level architecture and patterns
- Important implementation details
- Automatic Loading: COPERT.md is automatically loaded when you start a Copert session
- Context Efficiency: Offloads token-heavy project context from conversation history
- Better Assistance: Copert uses this context to provide more accurate, project-specific help
- First time setting up Copert in a new project
- After major architectural changes
- To help Copert understand your project's conventions and patterns
Start an interactive session by running without arguments:
$ copert
Welcome to Copert CLI v0.1.0
Type /help for commands, /exit to quit
You: Can you help me write a prime number function?
π§ Using tool: write_file
file_path: prime.py
β Tool completed
Copert: I've created a prime number function for you in prime.py...
You: Now add unit tests
π§ Using tool: write_file
file_path: test_prime.py
β Tool completed
Copert: I've added unit tests in test_prime.py...
You: /exit
Goodbye!Session Commands:
/help- Show help message/init- Initialize project with COPERT.md guide file/clear- Clear conversation history/history- Show conversation history/exitor/quit- Exit sessionCtrl+D- Exit sessionCtrl+C- Cancel current inputβ/β- Navigate command history
Use specific commands for scripting:
# One-time chat
copert chat "Read the README file"
# Display version
copert version
# Show configuration
copert configIf running from source without global installation:
# Interactive mode
uv run python main.py
# One-shot commands
uv run python main.py versionUser Message
β
Agent (LLM with tools)
β
Has tool calls?
ββ Yes β Tools β Agent (summarizes) β End
ββ No β End
- LangGraph StateGraph: Manages agent workflow and state
- LangChain Tools: File ops, search, execution tools
- ChatOpenAI: OpenAI LLM with function calling
- Prompt Toolkit: Interactive REPL with history and auto-completion
- Typer CLI: Command-line interface for one-shot commands
- Rich: Terminal formatting and markdown rendering
copert-cli/
βββ copert/
β βββ agents/ # LangGraph agent and graph
β βββ cli/ # Typer CLI interface
β βββ config/ # Settings and schemas
β βββ llm/ # LangChain ChatOpenAI wrapper
β βββ state/ # State management
β βββ tools/ # All tools
β β βββ file_ops/ # Read, Write, Edit
β β βββ search/ # Grep, Glob
β β βββ execution/ # Bash
β βββ utils/ # Utilities
βββ main.py # Entry point
βββ pyproject.toml # Dependencies
- read_file: Read files with line numbers
- write_file: Write content to files
- edit_file: Exact string replacement in files
- ls: List directory contents
- multiedit: Make multiple edits to a single file
- grep: Ripgrep-based code search
- glob: File pattern matching
- bash: Execute shell commands
- todowrite: Create and manage task lists
- webfetch: Fetch and process web content
- websearch: Search the web using Exa API
- task: Delegate complex tasks to specialized sub-agents
Copert implements a multi-agent architecture where the main agent can delegate complex, multi-step tasks to specialized sub-agents. This keeps the main conversation focused while allowing thorough, autonomous research in isolated contexts.
# Main agent recognizes complex task and delegates:
task(
description="Search API endpoints",
prompt="""
Search the entire codebase for all API endpoint definitions.
Look for FastAPI, Flask, and Django patterns.
Return a structured report organized by file.
""",
subagent_type="general-purpose"
)Flow:
- Main agent identifies a complex, multi-step task
- Spawns a specialized sub-agent with fresh context
- Sub-agent autonomously completes the task with read-only tools
- Sub-agent returns comprehensive final report
- Main agent processes report and continues
Research and analysis specialist for:
- Complex codebase searches (multiple grep/glob operations)
- Multi-file pattern analysis
- Documentation research (webfetch/websearch)
- Exhaustive file exploration
Tools: read_file, ls, grep, glob, webfetch, websearch (read-only)
Code implementation specialist for:
- Implementing features across multiple files
- Bulk refactoring operations
- Applying fixes/patterns to many files
- Code generation with specific requirements
Tools: read_file, write_file, edit_file, multiedit, ls, grep, glob (write access, no execution)
- Context Efficiency: Complex operations don't pollute main conversation context
- Specialization: Each sub-agent has optimized prompts and tool access for their domain
- Safety:
- general-purpose: Read-only, cannot make changes
- code-writer: Can write but cannot execute (no bash), preventing destructive commands
- Separation of Concerns: Research and implementation are isolated processes
- Parallel Execution: Can delegate to multiple sub-agents simultaneously
- Focus: Main agent stays focused on high-level planning and orchestration
- Scalability: Easy to add more specialized sub-agent types
The main agent automatically delegates to sub-agents when:
To general-purpose:
- Task requires multiple search/grep rounds across many files
- Extensive file exploration without knowing exact locations
- Pattern analysis across the entire codebase
- Research requiring multiple web searches and documentation fetches
To code-writer:
- Implementing features that span multiple files
- Bulk refactoring operations (e.g., "refactor all error handling to use ErrorService")
- Applying fixes or patterns to many files
- Code generation with specific structural requirements
Main Agent (12 tools)
ββ Full access: read, write, edit, ls, multiedit, grep, glob, bash, todowrite, webfetch, websearch, task
β
ββ Delegates research via 'task' tool
β β
β general-purpose Sub-Agent (6 read-only tools)
β ββ read_file, ls, grep, glob, webfetch, websearch
β ββ Returns: Research report
β
ββ Delegates implementation via 'task' tool
β β
β code-writer Sub-Agent (7 write tools, no execution)
β ββ read_file, write_file, edit_file, multiedit, ls, grep, glob
β ββ Returns: Implementation report
β
ββ Processes reports and responds to user
User: "Refactor all database queries to use async/await"
Main Agent:
1. π€ Delegates to general-purpose:
"Search for all sync database query patterns"
β Report: 15 files with sync queries found
2. π€ Delegates to code-writer:
"Refactor these 15 files to async/await,
following the pattern in examples/async-query.ts"
β Report: 15 files updated with changes listed
3. π Main agent summarizes to user and suggests running tests
# Run tests
uv run pytest
# Format code
uv run ruff format .
# Type check
uv run mypy copert/Learned a lot from the context engineering talk from langchain and manus.
None