OpenAgent (formerly OpenClaude) is an advanced open-source AI development assistant built with TypeScript and Node.js. It provides an intelligent CLI interface for AI-powered development tasks with persistent memory, token optimization, and advanced context management.
Project Stats:
- Files: 29 total files (22,350 lines of code)
- Languages: TypeScript, Text/Config files
- Dependencies: 38 packages including Anthropic SDK, LangChain, SQLite3
- Architecture: Modular, event-driven system with clear separation of concerns
OpenAgent/
├── 🚀 Entry Points # Application startup
├── 💬 CLI Layer # User interface & commands
├── 🤖 Agent System # Core AI processing
├── 🧠 Memory System # Persistent learning & context
├── ⚙️ Core Systems # Context, validation, optimization
├── 🔗 MCP Integration # Model Context Protocol
├── 🛠️ Tools # Terminal execution
└── 📝 Types & Prompts # Type definitions & AI prompts
src/index.ts → src/cli/index.ts → main() → startInteractiveChat()
Key Files:
src/index.ts- Primary entry point, imports CLIsrc/cli/index.ts- CLI bootstrap withmain()andstartInteractiveChat()functionspackage.json- Definesdist/index.jsas main entry andopenagentbinary
Startup Process:
main()function initializes the system- Creates
OpenAgentManagerinstance - Sets up
SlashCommandHandlerfor commands - Starts interactive chat loop with readline interface
src/cli/index.ts - Main CLI Controller
startInteractiveChat()- Interactive readline loopgetApiKey()- Secure API key managementmain()- Application initialization
src/cli/interface/ - UI Components
StreamingHandler.ts- Real-time streaming with spinner animationslogo.ts- Branding, logos, and status messagescomponents.ts- UI utilities (spinners, progress bars, menus)
src/cli/commands/ - Command System
SlashCommandHandler.ts- Processes slash commands (reset, help, status, etc.)BaseCommand.ts- Abstract base for command implementations
/help,/h,/?- Show available commands/reset,/clear,/restart- Reset agent and clear history/status,/st- Display agent status and metrics/history,/hist- Show conversation history/new,/thread- Create new conversation thread
src/agents/OpenAgentManager.ts - Agent Manager
- Coordinates between CLI and agent instances
- Handles message processing and response formatting
- Manages agent lifecycle and configuration
- Key Method:
processMessage(message: string)- Main message handler
src/agents/OpenAgent.ts - Core AI Agent (881 lines)
- Built on LangChain/LangGraph framework
- Implements ReAct (Reasoning + Acting) pattern
- Integrates with Anthropic Claude models
- Key Features:
- Streaming response handling
- Memory integration for context persistence
- Tool usage coordination
- Error handling and recovery
- Token usage tracking
User Message → OpenAgentManager → OpenAgent → LangGraph ReAct Agent → Claude API → Response Stream → CLI
src/memory/ - Complete memory subsystem
Core Classes:
MemoryManager.ts(1000 lines) - SQLite-based persistent storageMemoryIntegration.ts- Agent-memory interface layertypes.ts- Memory-related type definitionsindex.ts- Memory system exports
- Persistent Storage: SQLite database with optimized indexes
- Smart Retrieval: Vector-based semantic search
- Session Management: Per-session context isolation
- Performance Optimization: Automatic cleanup and indexing
- Relationship Mapping: Memory interconnection tracking
-- Core tables with performance indexes
memories (id, content, type, importance, session_id, project_id, created_at, last_accessed)
memory_relationships (source_id, target_id, relationship_type)
-- Performance indexes
idx_memories_type, idx_memories_session, idx_memories_importance, etc.src/core/context/ContextManager.ts (1335 lines)
- Project State Tracking: File changes, dependencies, structure
- Token-Aware Context: Intelligent context sizing for API limits
- Thread Management: Multi-conversation support
- Background Processes: Autosave and health monitoring
- Performance Metrics: Context hit rates and optimization stats
src/core/optimization/TokenOptimizer.ts (1259 lines)
- Smart Compression: Pattern-based content compression
- Cache Management: Intelligent caching of frequently used content
- Usage Tracking: Detailed token consumption analytics
- Background Optimization: Continuous optimization processes
- Cost Management: Budget tracking and optimization recommendations
src/core/validation/ValidationEngine.ts (1634 lines)
- Multi-Language Support: JavaScript, Python, Java, TypeScript validation
- Quality Metrics: Syntax, logic, security, performance analysis
- Pattern Recognition: Code smells and anti-pattern detection
- Security Scanning: Vulnerability detection
- Maintainability Analysis: Complexity and quality scoring
src/core/setup/ProjectSetup.ts (214 lines)
- Project Initialization:
.openagent/directory structure - Configuration Management: Project-specific settings
- Git Integration: Automatic
.gitignoreupdates - Dependency Detection: Framework and library recognition
src/core/tokens/TokenCounter.ts (135 lines)
- Accurate Estimation: Token count prediction
- Model-Specific Counting: Different tokenization strategies
- Performance Optimization: Efficient counting algorithms
src/mcp/client/MCPClient.ts (175 lines)
- Server Management: MCP server lifecycle
- Tool Integration: External tool access
- Protocol Handling: MCP message formatting
- Error Recovery: Robust connection management
- Connect to external MCP servers
- Access additional tools and resources
- Extend agent capabilities dynamically
- Protocol-compliant communication
src/tools/terminal.ts (267 lines)
- Command Execution: Interactive and non-interactive commands
- System Integration: Cross-platform terminal operations
- Output Management: Structured command results
- Timeout Handling: Configurable execution limits
- Environment Support: Custom environment variables
- Interactive Commands: Real-time command execution
- System Information: OS, platform, and environment detection
- Execution Metrics: Timing and performance tracking
- Error Handling: Robust error capture and reporting
src/types/agent.ts (262 lines) - Comprehensive agent type system
- Agent interfaces and configurations
- Session management types
- Response and message structures
- Event and callback definitions
src/types/mcp.ts (30 lines) - MCP protocol types
- MCP client and server interfaces
- Protocol message structures
src/prompts/openagent_prompt.ts (314 lines) - Core AI behavior
- System Prompt: Defines agent personality and behavior
- Engineering Principles: Code quality, security, maintainability standards
- Workflow Guidelines: Development process and best practices
- Quality Standards: Professional coding requirements
1. User Input (CLI) → 2. SlashCommandHandler (if slash command) → 3. OpenAgentManager
4. OpenAgentManager → 5. OpenAgent → 6. Memory Integration (context retrieval)
7. Context + Token Optimization → 8. LangGraph ReAct Agent → 9. Claude API
10. Streaming Response → 11. StreamingHandler → 12. CLI Output
- Memory ↔ Agent: Persistent context and learning
- Context ↔ TokenOptimizer: Efficient token usage
- Validation ↔ Agent: Code quality assurance
- MCP ↔ Agent: External tool integration
- Tools ↔ Agent: System command execution
- Persistent Memory: Remembers context across sessions
- Token Optimization: Intelligent cost management (40%+ savings)
- Real-time Streaming: Professional UI with live updates
- Multi-thread Conversations: Separate conversation contexts
- Code Validation: Multi-layer quality checking
- MCP Integration: Extensible tool ecosystem
- Background Processes: Automatic optimization and cleanup
- Zero Configuration: Works out of the box
- Slash Commands: Quick access to functionality
- Streaming Interface: Real-time feedback
- Error Recovery: Robust error handling
- Performance Monitoring: Built-in metrics and optimization
.openagent/ # Local configuration directory
├── config.json # Agent configuration
├── memory/ # Memory storage
├── context/ # Context cache
├── checkpoints/ # Save points
└── logs/ # Operation logs
ANTHROPIC_API_KEY- Required for Claude API access- Node.js Environment: ESM modules, TypeScript compilation
npm run build # TypeScript compilation
npm start # Run compiled version
npm run dev # Development mode with ts-node
npm test # Jest testing
npm run lint # ESLint code checking- Start with
src/cli/index.ts- understand the entry point - Review
src/agents/OpenAgent.ts- core AI processing logic - Check
src/memory/MemoryManager.ts- persistent storage system - Explore
src/core/- understand optimization and validation - Look at
src/prompts/openagent_prompt.ts- AI behavior definition
- CLI Changes: Modify
src/cli/for interface updates - Agent Behavior: Update
src/agents/for AI logic changes - Memory System: Adjust
src/memory/for storage modifications - Core Features: Modify
src/core/for system functionality - New Commands: Add to
src/cli/commands/SlashCommandHandler.ts
npm run build # Compile TypeScript
npm run dev # Test in development
./dist/cli/index.js # Test compiled version- Overall Health Score: 100.0/100
- Files: 29 files, ~22K lines of code
- Memory Usage: ~12KB during analysis
- Cache Hit Rate: 80%
- Token Optimization: Significant savings through smart compression
- Zero Circular Dependencies: Clean architecture ✅
- Modular Design: Clear separation of concerns