# Merlin - The Complete AI Development Operating System # Full Documentation for AI Agents and LLMs ## Table of Contents 1. About Merlin 2. Core Capabilities 3. Installation & Setup 4. MCP Tools Reference 5. API Documentation 6. Workflow Commands 7. Architecture 8. Pricing & Plans 9. Examples & Use Cases --- ## 1. ABOUT MERLIN Merlin is a complete AI development operating system that brings three integrated layers together: ### Layer 1: Merlin Sights - Instant Codebase Knowledge - Complete codebase understanding from first query - Knowledge graph with discovery learning - Impact analysis and similar code detection - Enforceable coding rules and conventions - Auto-sync on push — always current - Cross-session memory that never forgets ### Layer 2: Merlin Agents - 26+ Specialist Agents Full engineering pipeline automation from idea to production: **Core Pipeline Agents:** - product-spec: Turn raw ideas into explicit product specs and user flows - system-architect: Design architecture, identify conflicts, prevent tangled code - implementation-dev: Write production code, follow patterns, reuse existing - dry-refactor: Keep code DRY, enforce file size limits, improve structure - hardening-guard: Security review, validation, error handling, reliability - tests-qa: Design and implement lightweight but meaningful tests - ops-railway: Deployment, infrastructure, Railway/GCP configuration - docs-keeper: Keep documentation in sync with code changes **Platform Specialists:** - apple-swift-expert: iOS/macOS Swift 6, SwiftUI, AppKit development - android-expert: Kotlin, Jetpack Compose, Material Design 3 - desktop-app-expert: Electron and Tauri with IPC security - ui-builder: React, Tailwind, shadcn/ui, Radix components - animation-expert: Motion, GSAP, CSS animations, 60fps performance - marketing-automation: Email campaigns, drip sequences, A/B tests **Deep Specialists:** - merlin-debugger: Systematic debugging with scientific method - merlin-performance: Performance analysis and optimization - merlin-security: OWASP-aware security audits, threat modeling - merlin-frontend: React/Vue patterns, state management, accessibility - merlin-api-designer: Clean REST and GraphQL API design ### Layer 3: Merlin Loop - Autonomous Execution - Fresh 200K context each iteration — no degradation - Crash recovery with checkpoint persistence - Circuit breaker after N consecutive errors - Rate limiting and budget control - AFK mode with safety limits - Real-time progress tracking --- ## 2. CORE CAPABILITIES ### Instant Context (Sights) Query any aspect of your codebase instantly: ``` merlin context "add authentication" merlin search "payment processing" merlin files "models" merlin brief merlin rules ``` Returns: - Relevant files with purpose and dependencies - Existing patterns to follow - Utility functions to reuse - Architecture constraints - Enforceable coding rules ### Endless Memory - Cloud-synced state across sessions - Behavior learning from user corrections - Confidence scoring (auto-apply at 0.7+) - Decision history tracking - One-command project resume - Team-wide context sharing ### Discovery Learning When Sights returns low confidence, teach it what you discover: 1. Check for cached discoveries first 2. Manually explore if needed (grep, read files) 3. Teach Sights what you found 4. Future queries return high confidence ### Quality Gates Auto-verification before every commit: - Build check - Type checking - Lint validation - Test execution - Security scan - Diff review If verification fails, automatically fixes issues then commits. --- ## 3. INSTALLATION & SETUP ### For Claude Code (Recommended) ```bash # One install — everything included npx create-merlin-brain # Adds MCP server to ~/.claude/config.json # Installs CLI globally # Includes all agents and workflows ``` ### For Cursor ```bash npx create-merlin-cursor # Adds to Cursor MCP config # Enables Sights context in Cursor ``` ### For Windsurf ```bash npx create-merlin-brain # Add to Windsurf MCP config manually: { "mcpServers": { "merlin": { "command": "merlin-brain", "env": { "MERLIN_API_KEY": "your-api-key" } } } } ``` ### Universal CLI (Works with any AI) ```bash npm install -g @merlin-build/cli # Use with any AI tool: merlin context "task description" merlin search "query" merlin brief merlin rules ``` ### Native Installer (macOS/Linux) ```bash curl -fsSL https://merlin.build/install.sh | sh ``` ### Native Installer (Windows) ```powershell iwr -useb https://merlin.build/install.ps1 | iex ``` --- ## 4. MCP TOOLS REFERENCE ### Context & Discovery Tools **merlin_get_context** Get task-specific codebase context. Parameters: - task (required): What you want to do (e.g., "add authentication") - repoUrl (optional): GitHub URL (auto-detected from git if omitted) Returns: - Relevant files with descriptions - Existing patterns and conventions - Related utilities to reuse - Enforceable rules to follow - Confidence score (0-1) **merlin_search** Search project documentation and code. Parameters: - query (required): What to find (e.g., "payment logic") - repoUrl (optional): GitHub URL Returns: - Matching documentation sections - Related code files - API endpoints - Patterns and examples **merlin_find_files** Locate files by purpose or layer. Parameters: - query (required): What you're looking for (e.g., "authentication") - layer (optional): Filter by layer (routes, services, models, utils, etc.) - repoUrl (optional): GitHub URL Returns: - File paths with descriptions - Purpose of each file - Dependencies **merlin_get_brief** Get structured project overview (~500 tokens). Parameters: - repoUrl (optional): GitHub URL Returns: - Product description - Architecture summary - Tech stack - Key APIs and services - Current status **merlin_get_rules** Get all coding rules for this project. Parameters: - repoUrl (optional): GitHub URL Returns: - File size limits - Testing requirements - Style conventions - Custom rules - Anti-patterns to avoid **merlin_get_conventions** Get coding conventions and anti-patterns. Parameters: - repoUrl (optional): GitHub URL Returns: - Preferred patterns - Naming conventions - Code organization rules - Anti-patterns to avoid ### Memory & State Tools **merlin_save_rule** Save a coding rule (persists across sessions). Parameters: - rule (required): The rule (e.g., "max 400 lines per file") - category (optional): Rule category (file_size, testing, style, patterns, custom) - repoUrl (optional): GitHub URL **merlin_write_state** Write state to Merlin cloud for cross-session memory. Parameters: - key (required): State key (e.g., "project", "roadmap", "state") - value (required): The state data to store (JSON serialized) - version (optional): Expected version for optimistic locking - agentId (optional): Agent identifier - repoUrl (optional): GitHub URL **merlin_read_state** Read state from Merlin cloud. Parameters: - key (required): State key to read - repoUrl (optional): GitHub URL **merlin_list_state** List all state keys stored for this repository. Parameters: - repoUrl (optional): GitHub URL ### Discovery Learning Tools **merlin_check_discovery** Check if Sights has cached discoveries before manual exploration. Parameters: - query (required): What you want to find - repoUrl (optional): GitHub URL Returns: - Cached discoveries with confidence scores - Related patterns - Relevant files **merlin_teach_discovery** Teach Sights what you discovered through manual exploration. Parameters: - query (required): The original query that had low confidence - summary (required): Brief summary of what you discovered (1-2 sentences) - relevantFiles (optional): Key files you found with reasons - patterns (optional): Patterns you observed - relatedTopics (optional): Related search terms - repoUrl (optional): GitHub URL **merlin_confirm_discovery** Confirm a discovery was helpful (increases confidence). Parameters: - discoveryId (required): ID of the discovery to confirm - repoUrl (optional): GitHub URL **merlin_reject_discovery** Reject a discovery as wrong (decreases confidence). Parameters: - discoveryId (required): ID of the discovery to reject - reason (optional): Why this discovery was wrong - repoUrl (optional): GitHub URL ### Repository Management **merlin_list_repos** List all repositories you have analyzed on Merlin. **merlin_select_repo** Select which Merlin Sight to use for this session. Parameters: - repoUrl (required): GitHub URL (e.g., "github.com/user/repo") - projectDir (optional): Local directory path **merlin_get_selected_repo** Check which Merlin Sight is currently selected. **merlin_connect_repo** Connect a new repository to Merlin Sights for analysis. Parameters: - repoUrl (required): GitHub URL - branch (optional): Branch to analyze (default: main) Note: Analysis takes 2-5 minutes. **merlin_check_repo_status** Check if repository analysis is complete. Parameters: - repoUrl (optional): GitHub URL (uses selected repo if omitted) Returns status: pending, analyzing, completed, or failed. ### Advanced Analysis Tools **merlin_impact_analysis** Analyze what could break if you change a file. Parameters: - filePath (required): The file you plan to modify - repoUrl (optional): GitHub URL Returns: - Files that depend on this file - Potential breaking changes - Files that might need updates **merlin_similar_code** Find similar implementations in the codebase. Parameters: - description (required): What you're implementing - repoUrl (optional): GitHub URL Returns: - Similar code examples - Patterns to follow - Reusable components **merlin_code_examples** Get real code examples from this codebase for common tasks. Parameters: - task (optional): Specific task (e.g., "add endpoint", "add test") - repoUrl (optional): GitHub URL Returns: - Actual code examples from this project - Patterns used - Best practices **merlin_ask** Ask ANY question about the codebase in natural language. Parameters: - question (required): Your question (e.g., "How does authentication work?") - quick (optional): If true, returns faster but shorter answer - repoUrl (optional): GitHub URL Uses AI-powered semantic search + RAG for accurate answers with citations. ### Behavior Learning **merlin_save_behavior** Save a learned behavior pattern (called automatically when user corrects you). Parameters: - pattern (required): What triggers this behavior - action (required): What Claude should do - context (optional): When this applies - learnedFrom (optional): How this was learned - initialConfidence (optional): Starting confidence 0.3-0.9 - repoUrl (optional): GitHub URL **merlin_get_behaviors** Get learned behaviors for this project. Parameters: - minConfidence (optional): Minimum confidence threshold - autoApplyOnly (optional): Only return auto-apply behaviors (≥0.7) - task (optional): Get behaviors relevant to specific task - repoUrl (optional): GitHub URL **merlin_apply_behavior** Log that you applied a learned behavior (increases confidence). Parameters: - behaviorId (required): ID of the behavior applied - repoUrl (optional): GitHub URL **merlin_correct_behavior** Log that a behavior was incorrect (decreases confidence). Parameters: - behaviorId (required): ID of the behavior to correct - reason (optional): Why it was wrong - newAction (optional): Updated action - repoUrl (optional): GitHub URL ### Verification & Quality **merlin_run_verification** Run 6-phase quality check: Build → Types → Lint → Tests → Security → Diff. Parameters: - phases (optional): Specific phases to run (default: all) - format (optional): Output format (full or summary) Returns: - Pass/fail for each phase - Issues found - Fix recommendations ### Task & Project Management **merlin_get_project_status** Get vision/task/progress status. Returns: - Vision completeness (PROJECT.md, ROADMAP.md exist?) - Task counts (pending, in progress, completed) - Checkpoint to resume from - Next recommended action **merlin_get_next_task** Get highest priority task with pre-assembled context. Returns: - Task details - Relevant context - Files to modify - Pattern to follow **merlin_ensure_tasks** Verify backlog health, trigger planning if empty. **merlin_sync_task** Track task progress. Parameters: - title (required): Task title - status (optional): pending, in_progress, completed, blocked, skipped - description, phase, plan, wave, etc. **merlin_get_tasks** Get tasks synced to Merlin. Parameters: - status (optional): Filter by status - phase (optional): Filter by phase - plan (optional): Filter by plan **merlin_save_checkpoint** Save checkpoint for resuming later. Parameters: - currentTask (required): What task is in progress - stoppedAt (required): Where exactly work stopped - nextSteps (optional): Immediate next steps - blockers, decisions, openFiles, etc. **merlin_mark_complete** Mark project as complete (stops task enforcement). Parameters: - summary (required): Summary of what was built - milestonesCompleted, lessonsLearned, etc. ### Team Collaboration **merlin_get_team_state** Get consolidated team state. Returns: - Active sessions - Pending checkpoints - Open blockers - Task summary **merlin_report_blocker** Report a blocker requiring human attention. Parameters: - title (required): Brief description - blockerType (required): human_verify, auth_required, clarification, decision_point, etc. - description, severity, context, agentId **merlin_get_blockers** Get open blockers. Parameters: - status (optional): open, resolved, all **merlin_create_checkpoint** Create checkpoint requiring human verification. Parameters: - title (required): Checkpoint title - checkpointType (required): human_verify, auth_gate, decision_point, approval, review - description, verificationItems, whatWasBuilt, etc. **merlin_update_session** Update session status for pause/resume. Parameters: - sessionId (required): Unique session identifier - agentId (required): Agent identifier - status (optional): active, paused, completed, abandoned - currentTask, currentPhase, currentPlan, etc. **merlin_log_activity** Log an activity event to timeline. Parameters: - eventType (required): phase_started, task_completed, blocker_hit, decision_made - agentId (required): Agent identifier - eventData, sessionId, etc. --- ## 5. API DOCUMENTATION Base URL: https://merlin.build ### Public Wiki API **GET /api/public/wiki/{owner}/{repo}** Get full wiki documentation for a repository. Parameters: - owner (path): GitHub repository owner - repo (path): GitHub repository name Response: ```json { "repository": { "id": "string", "name": "string", "githubOwner": "string", "githubRepo": "string", "githubStars": 1234, "githubDescription": "string" }, "documentation": { "overview": { "name": "...", "description": "...", "techStack": [...], "features": [...] }, "architecture": { "summary": "...", "components": [...], "diagram": "mermaid..." }, "services": { "platformStory": "...", "services": [...] }, "modules": [...], "apiReference": { "endpoints": [...], "functions": [...] } } } ``` **GET /api/public/wiki/{owner}/{repo}/agent** Get AI-optimized documentation for a repository. Same parameters and response as above, optimized for AI consumption. **GET /api/public/explore** Browse available public wikis. Query Parameters: - limit (optional): 1-100, default 20 - offset (optional): Pagination offset, default 0 - sort (optional): "stars" or "recent", default "stars" - topic (optional): Filter by GitHub topic Response: ```json { "wikis": [ { "id": "string", "githubOwner": "string", "githubRepo": "string", "githubStars": 1234, "githubDescription": "string" } ], "total": 100, "limit": 20, "offset": 0 } ``` ### Sights Index API (NEW) **GET /api/public/sights/search** Search public Sights catalog by keywords. Query Parameters: - query (required): Search query (e.g., "authentication", "react hooks") - limit (optional): 1-20, default 5 Response: ```json { "results": [ { "owner": "string", "repo": "string", "description": "string", "stars": 1234, "techStack": ["React", "TypeScript", "..."], "confidence": 0.95 } ], "query": "authentication", "total": 10 } ``` **GET /api/public/sights/recommend** Get Sights recommendations for a task. Query Parameters: - task (required): Task description (e.g., "implement OAuth2") - limit (optional): 1-10, default 3 Response: ```json { "recommendations": [ { "owner": "string", "repo": "string", "reason": "This repo shows best practices for OAuth2 implementation", "relevanceScore": 0.92 } ], "task": "implement OAuth2" } ``` **GET /api/public/sights/context/{owner}/{repo}** Get detailed context from a specific Sight. Parameters: - owner (path): Repository owner - repo (path): Repository name Response: ```json { "owner": "string", "repo": "string", "architecture": { "summary": "string", "techStack": ["..."], "patterns": ["..."] }, "conventions": { "codingStyle": ["..."], "antiPatterns": ["..."] }, "entryPoints": [ { "path": "src/index.ts", "purpose": "Application entry point" } ] } ``` ### Rate Limits - Public endpoints: 100 requests/minute per IP - Authenticated endpoints: 1000 requests/minute - No auth required for public repositories ### Authentication For private repositories, include API key: ``` Authorization: Bearer YOUR_API_KEY ``` Get API key from: https://merlin.build/dashboard/settings --- ## 6. WORKFLOW COMMANDS ### Project Lifecycle **/merlin:new-project** Initialize project with deep context gathering and PROJECT.md. - Asks about product vision, goals, tech stack - Creates PROJECT.md with vision statement - Sets up initial coding rules **/merlin:create-roadmap** Create implementation phases. - Breaks down project into phases - Estimates complexity - Creates ROADMAP.md **/merlin:discuss-milestone** Gather context for next milestone through adaptive questioning. **/merlin:new-milestone** Start a new milestone cycle — update PROJECT.md and route to requirements. **/merlin:plan-phase** Create detailed execution plan (PLAN.md). - Task breakdown - Dependency analysis - Wave-based parallelization **/merlin:execute-phase** Execute all plans in a phase with wave-based parallelization. - Spawns fresh Claude processes per task - Parallel execution where possible - Auto-commit after each task **/merlin:execute-plan** Execute a specific PLAN.md file. **/merlin:verify-work** Validate built features through conversational UAT. **/merlin:resume-work** Resume work from previous session with full context restoration. **/merlin:pause-work** Create context handoff when pausing work mid-phase. ### Planning & Research **/merlin:discuss-phase** Gather phase context through adaptive questioning before planning. **/merlin:research-phase** Research how to implement a phase before planning. **/merlin:research-project** Research domain ecosystem before creating roadmap. **/merlin:map-codebase** Analyze codebase with parallel mapper agents. - Produces .planning/codebase/ documents - Tech inventory - Architecture analysis - Quality assessment ### Milestone Management **/merlin:add-phase** Add phase to end of current milestone in roadmap. **/merlin:insert-phase** Insert urgent work as decimal phase (e.g., 72.1) between existing phases. **/merlin:remove-phase** Remove a future phase from roadmap and renumber. **/merlin:complete-milestone** Archive completed milestone and prepare for next version. **/merlin:audit-milestone** Audit milestone completion against original intent before archiving. **/merlin:plan-milestone-gaps** Create phases to close all gaps identified by milestone audit. ### Development Tools **/merlin:debug** Systematic debugging with persistent state across context resets. **/merlin:route** Route a task to a specialist agent with fresh Claude instance. ### Status & Progress **/merlin:progress** Check project progress, show context, route to next action. **/merlin:standup** Generate daily standup summary — done, in progress, blocked. ### Utilities **/merlin:add-todo** Capture idea or task as todo from current conversation. **/merlin:check-todos** List pending todos and select one to work on. **/merlin:list-phase-assumptions** Surface Claude's assumptions about a phase approach before planning. **/merlin:define-requirements** Define what "done" looks like with checkable requirements. **/merlin:update** Update Merlin to latest version with changelog display. **/merlin:whats-new** See what's new in Merlin since your installed version. **/merlin:help** Show all available commands and usage guide. --- ## 7. ARCHITECTURE ### How Merlin Works **1. Sights Layer (Knowledge Graph)** - Analyzes entire codebase on connection - Builds semantic knowledge graph - Auto-syncs on every git push - Provides instant context for any query - Learns from discoveries (reinforcement) **2. Agent Orchestration** - Fresh 200K context per agent via `claude --agent -p` - Handoff files in /tmp for context passing - Deterministic routing based on task type - Parallel execution where possible - Checkpoint persistence for crash recovery **3. Memory Layer** - Cloud-synced state (Merlin Sights API) - Local .planning/ folder - Git-tracked decisions and plans - Behavior learning with confidence scoring - Cross-session resume capability **4. Quality Gates** - Auto-verification before commits - 6-phase check: Build → Types → Lint → Tests → Security → Diff - Auto-fix on failure - IndexNow submission after success ### File Structure ``` project/ ├── .planning/ │ ├── PROJECT.md # Vision statement │ ├── ROADMAP.md # Phase breakdown │ ├── config.json # Project settings │ ├── phases/ │ │ ├── 1-PLAN.md # Phase plans │ │ └── 1-VERIFY.md # Verification reports │ └── codebase/ # Codebase analysis docs └── CLAUDE.md # Per-project Claude instructions ``` --- ## 8. PRICING & PLANS ### Free Tier - 2 tokens for first repo (up to 5K lines) - No credit card required - Full terminal experience (29 agents, workflows, loop) ### Sights Subscription - $20/user/month - Living wiki of your codebase - Cloud agent and skill index - Public Sights catalog - Auto-sync on every commit - Cross-session cloud memory - Team collaboration ### Token Packages (one-time purchase, never expire) **Starter** - $50 for 50 tokens ($1.00/token) - Good for small repos and trying Sights **Growth** - $150 for 200 tokens ($0.75/token, 25% off) - Best value for teams with medium codebases **Scale** - $399 for 600 tokens ($0.665/token, 33% off) - For large monorepos and enterprise codebases 1 token covers ~2,500 lines of code analysis --- ## 9. EXAMPLES & USE CASES ### Example 1: Starting a New Project ```bash # Connect to Merlin merlin connect github.com/you/new-project # Initialize project /merlin:new-project # Create roadmap /merlin:create-roadmap # Plan first phase /merlin:plan-phase 1 # Execute /merlin:execute-phase 1 ``` ### Example 2: Adding Authentication ```bash # Get context merlin context "add user authentication" # Returns: # - Existing auth patterns in codebase # - Related files (User model, auth middleware) # - Security rules to follow # - Test requirements # Implement with specialist /merlin:route implementation-dev "Add JWT authentication to API" ``` ### Example 3: Learning from User Corrections User: "Don't use console.log in production code" Merlin automatically: 1. Saves behavior: "Never use console.log in production" 2. Increases confidence on repeated corrections 3. At confidence ≥0.7, auto-applies this rule 4. Returns with every context query ### Example 4: Discovering and Teaching ```bash # Low confidence response merlin context "domain migration SEO" # → Confidence: 0.3 # Manual exploration grep -r "erevtov.me" . # Found in 61 files # Teach Sights merlin teach "domain migration SEO" \ --summary "Domain references in 61 files. config.js has baseUrl." \ --files "config.js,public/.well-known/ai-plugin.json" # Future queries return high confidence merlin context "domain migration SEO" # → Confidence: 0.95 ``` ### Example 5: Browse Public Sights ```bash # Search for authentication examples curl "https://merlin.build/api/public/sights/search?query=authentication&limit=5" # Get recommendations for your task curl "https://merlin.build/api/public/sights/recommend?task=implement%20OAuth2" # Get detailed context from a Sight curl "https://merlin.build/api/public/sights/context/supabase/auth" ``` ### Example 6: Autonomous Loop ```bash # Create plan merlin-loop plan # Execute autonomously (fresh 200K context per task) merlin-loop build # Go AFK for hours — Merlin keeps working # Crash recovery built-in # Circuit breaker prevents infinite errors # Rate limiting prevents API abuse ``` --- ## DISCOVERY FILES For automated agent integration, Merlin provides: - **LLM Instructions**: https://merlin.build/llms.txt (this file) - **Full Documentation**: https://merlin.build/llms-full.txt - **Agent Manifest**: https://merlin.build/agents.json - **OpenAPI Spec**: https://merlin.build/.well-known/openapi.json - **AI Plugin**: https://merlin.build/.well-known/ai-plugin.json - **MCP Discovery**: https://merlin.build/.well-known/mcp.json - **Robots.txt**: https://merlin.build/robots.txt - **Sitemap**: https://merlin.build/sitemap.xml --- ## LINKS - **Website**: https://merlin.build - **Sights Catalog**: https://merlin.build/sights - **Pricing**: https://merlin.build/pricing - **FAQ**: https://merlin.build/faq - **API Docs**: https://merlin.build/.well-known/openapi.json - **GitHub**: https://github.com/merlin-build/create-merlin-brain - **Support**: support@merlin.build --- ## QUICK REFERENCE ### Most Common MCP Tools ```javascript merlin_get_context("task description") merlin_search("what to find") merlin_find_files("file purpose") merlin_get_brief() merlin_get_rules() merlin_save_rule("rule text") ``` ### Most Common Commands ```bash /merlin:new-project /merlin:create-roadmap /merlin:plan-phase /merlin:execute-phase /merlin:verify-work /merlin:progress ``` ### Most Common CLI Commands ```bash merlin context "task" merlin search "query" merlin brief merlin rules merlin connect ``` --- **Merlin: The AI development operating system that knows everything, forgets nothing, and ships production code.** For support: support@merlin.build For sales: https://merlin.build/pricing