This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Nexus v2 is an AI event production agent system with a Next.js frontend and Python backend. The backend implements a modular architecture with subagent routing, tool management, and context management for streaming AI responses via OpenRouter.
npm install # Install dependencies
npm run dev # Start development server
npm run build # Production build
npm run lint # Run ESLintpython -m venv venv # Create virtual environment
venv\Scripts\activate # Activate venv (Windows)
source venv/bin/activate # Activate venv (Unix)
pip install -r requirements.txt # Install dependencies
python src/tests/test_agents.py # Run agent tests (accepts optional prompt arg)
python src/main.py # Run backend (server not yet implemented)Agents (src/agents/): Event-driven agent system with async streaming
BaseAgent: Main agent class that processes messages and yieldsAgentEventobjectsAgentEventType: START, END, ERROR, TEXT_DELTA, TEXT_COMPLETEsubagents/: Registry system for specialized agent plugins (extensible)
LLM Client (src/llm/): OpenRouter API integration
- Async streaming with retry logic and exponential backoff
StreamEventandTokenUsageresponse schemas- Tool call streaming:
ToolCall,ToolCallDelta, event types for START/DELTA/COMPLETE
Context Management (src/context/): Message history handling
ContextManager: Manages conversation history and system promptsMessageItem: Individual messages with token counting via tiktoken
Tools (src/tools/): Tool abstraction layer
Tool: Abstract base class for all toolsToolRegistry: Manages tool registration, schema generation, and invocationcreate_default_registry(): Factory that returns registry with all builtin toolsToolKind: READ, WRITE, NETWORK, MEMORY, MCPToolInvocation,ToolResult,ToolConfirmation: Execution typesToolResult.success_result(),ToolResult.error_result(): Factory methods- Pydantic validation and OpenAI-compatible schema generation
general/: Builtin general-purpose toolsDateTimeTool: now, format, parse, diff, add operations (default tz: PST)
Prompts (src/prompts/): System prompt generation with subagent definitions
- User input →
BaseAgent.run() - Message added to
ContextManager LLMClientstreams response via OpenRouter API (with tool schemas)- Events yielded to caller (TEXT_DELTA, TEXT_COMPLETE, TOOL_CALL_*, ERROR)
- Next.js App Router with React 19 and TypeScript
- Tailwind CSS 4 for styling
- API client in
src/lib/api.ts
- Configuration: Always use
config.pyfor environment variables. Never useos.getenvelsewhere. Key settings:DEFAULT_TIMEZONE(default: America/Vancouver). - Module Exports: Update
__init__.pywhen adding new modules/classes. - Paths: Use absolute paths for file operations.
- Async-first: Backend uses async patterns throughout.
- Type Safety: Pydantic models for validation, TypeScript interfaces for frontend.
- Minimal Docstrings: No long descriptions in docstrings; use comments only for complex logic.
- Frontend: Next.js 16, React 19, TypeScript 5, Tailwind CSS 4
- Backend: Python 3.11+, OpenAI SDK (OpenRouter), Pydantic 2, httpx, tiktoken
- Database: MongoDB (planned, not yet implemented)