This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Ralph is a CLI tool for long-running PRD-driven development with AI coding agents (Cursor, Claude Code, or Codex). It orchestrates AI agent sessions that work through tasks defined in a PRD (Product Requirements Document) file, with features like automatic retries, task decomposition, verification, and session memory.
# Development
bun run dev # Run the CLI directly
bun run src/index.tsx # Alternative: run entry point
# Quality checks (run after changes)
bun run check # Format + lint + fix (oxfmt + oxlint + eslint)
bun run typecheck # TypeScript type checking
# Testing
bun test # Run all tests
bun test src/__tests__/lib/config.test.ts # Run single test file
bun test --watch # Watch mode
# Build
bun run build # Production build via scripts/build.tsThese commands manage PRD tasks and progress:
ralph task list # List all tasks with completion status
ralph task current # Show the next pending task
ralph task done <n> # Mark task as complete (by number or title)
ralph task undone <n> # Mark task as not done
ralph progress add "<text>" # Add a progress note
ralph progress show # Display progress notessrc/index.tsx- Main entry, parses args, routes to commands or renders Ink componentssrc/cli/parser.ts- Argument parsing for all CLI commandssrc/cli/commands/- Individual command handlers (status, config, guardrails, etc.)
The orchestrator is now a service composed of several specialized managers:
src/lib/services/orchestrator/- Composition root that coordinates all orchestration servicessrc/lib/services/session-manager/- Manages session lifecycle (start, resume, fatal errors)src/lib/services/iteration-coordinator/- Sets up iteration callbacks, manages retry contextssrc/lib/services/handler-coordinator/- Coordinates handlers for verification, decomposition, learningsrc/lib/services/parallel-execution-manager/- Manages parallel task executionsrc/lib/services/branch-mode-manager/- Manages branch-per-task workflow
src/stores/agentStore.ts- Agent execution state, spawnsAgentRunnersrc/stores/appStore.ts- Application state (PRD, session, current view)src/stores/iterationStore.ts- Tracks iteration progress and timingsrc/stores/agentStatusStore.ts- Agent status display state
src/lib/agent.ts-AgentRunnerclass handles spawning the agent process (Cursor CLI), streaming output, timeout/stuck detection, retry logic with context injectionsrc/lib/agent-stream.ts- Parses JSON streaming output from Cursor CLIsrc/lib/services/AgentProcessManager.ts- Singleton managing the active agent subprocess
Services are bootstrapped at startup via src/lib/services/bootstrap.ts and accessed through src/lib/services/container.ts:
ProjectRegistryService- Multi-project support, path resolution, stores data in~/.ralph/projects/ConfigService- Layered config (global + project-level)PrdService- PRD file loading/parsingGuardrailsService- Prompt guardrails managementSessionService- Session persistenceSessionMemoryService- Cross-session learning/memoryUsageStatisticsService- Usage tracking and statisticsGitBranchService- Git branch operationsGitProviderService- GitHub integration
src/lib/events.ts- Minimal event bus with onlyagent:completeandagent:errorevents- HandlerCoordinator subscribes to these events for verification, decomposition, learning
- Most communication uses direct callback patterns rather than events
src/components/RunApp.tsx- Main runtime UIsrc/components/ViewRouter.tsx- Routes between different viewssrc/components/views/- Individual view components
import { something } from "@/lib/something.ts"; // src/lib/something.ts
import { Component } from "@/components/index.ts";import { getConfigService, getPrdService, getOrchestrator } from "@/lib/services/index.ts";
const config = getConfigService().get();
const orchestrator = getOrchestrator();import { bootstrapTestServices, teardownTestServices } from "@/lib/services/bootstrap.ts";
beforeEach(() => bootstrapTestServices({ config: { get: () => mockConfig } }));
afterEach(() => teardownTestServices());~/.ralph/ # Global Ralph directory
├── config.json # Global config
├── registry.json # Project registry
├── usage-statistics.json # Global usage statistics
└── projects/ # Per-project storage
└── <project-folder>/ # Named by git remote or path
├── config.json # Project-specific config
├── prd.json # PRD file (JSON format)
├── session.json # Active session state
├── session-memory.json
├── guardrails.json
├── instructions.md # Custom agent instructions
└── logs/ # Iteration logs
- Types are exported from
src/types.ts(re-exports fromsrc/types/) - Service types defined alongside implementations in
src/lib/services/*/types.ts