Code Factory + Ralph: Autonomous Coding Loop
· 3 min read
Source: Ryan Carson's articles | compound-product repo | Ralph guide Authors: Ryan Carson (@ryancarson), Geoffrey Huntley (Ralph pattern), Kieran Klaassen (Compound Engineering) Tweet: 3,751 likes
The Goal
One loop:
- The coding agent writes code
- The repo enforces risk-aware checks before merge
- A code review agent validates the PR
- Evidence (tests + browser + review) is machine-verifiable
Ralph: The Autonomous Loop
Ralph is a bash loop that ships features while you sleep:
- Pipes a prompt into your AI agent
- Agent picks the next story from
prd.json - Implements it
- Runs typecheck and tests
- Commits if passing
- Marks the story done
- Logs learnings to
progress.txt - Repeats until done
File Architecture
| File | Purpose |
|---|---|
ralph.sh | The executable loop script |
prompt.md | Iteration-specific instructions |
prd.json | Task inventory (branchName, priority, passes) |
progress.txt | Learnings across iterations (agent appends after each story) |
AGENTS.md | Preserved patterns and conventions |
Compound-Product System
4 phases:
- Phase 0: Generate daily reports
- Phase 1: Analyze reports using LLM API
- Phase 2: Planning with AI agents -> create
prd.jsonexecutable tasks - Phase 3: Execution loop (
loop.sh) -- runs up to N iterations
./scripts/compound/auto-compound.sh # full run
./scripts/compound/auto-compound.sh --dry-run # dry run
./scripts/compound/loop.sh 10 # just the loop
5 Critical Success Factors
- Small Stories -- tasks must fit within single context windows
- Fast Feedback -- typecheck and tests must execute quickly
- Explicit Criteria -- clear completion definitions
- Pattern Accumulation -- by iteration 10, agent understands patterns from previous stories
- Documentation Updates -- AGENTS.md preserves reusable patterns
The Contract
Define a contract specifying:
- Risk tiers by path -- what scrutiny different codebase parts get
- Required checks by tier -- what must pass per risk level
- Docs drift rules for control-plane changes
- Evidence requirements for UI/critical flows -- browser recordings, screenshots
Code Factory Workflow
- Risk tiers: Low (automate fully), Medium (automate with gates), High (require human confirmation)
- Preflight gate must complete before CI fanout -- deterministic ordering
- Review state: valid only when matching current PR head commit SHA (non-negotiable)
- Deterministic rerun: one canonical workflow as rerun requester, dedupe by marker +
sha:<head> - Evidence capture: tests + browser recordings + review, all machine-verifiable
- Auto-resolve: only bot-only stale threads after clean rerun
- Browser automation:
agent-browserfor screenshots and video evidence attached to PRs - Remediation agent: fixes review issues in-branch, reruns deterministically
Review Agents (Pluggable)
The control-plane pattern is agent-agnostic. Options:
- Greptile
- CodeRabbit AI
- CodeQL + policy logic
- Custom LLM review
Installation
git clone https://github.com/snarktank/compound-product.git
cd compound-product
./install.sh /path/to/your/project
Config (compound.config.json):
{
"tool": "amp" or "claude",
"reportsDir": "reports/",
"qualityChecks": ["npm run typecheck", "npm test"],
"maxIterations": 10,
"branchPrefix": "compound/"
}
Not Suitable For
- Exploratory work
- Major refactors without clear criteria
- Security-sensitive code
- Anything requiring human review of nuance
Related Articles by Ryan Carson
- Code Factory setup (Feb 16, 2026)
- How to setup a team of agents in OpenClaw (Feb 9, 2026)
- How to setup your agent to do daily testing + file bugs (Feb 2, 2026)
- How to make your agent learn and ship while you sleep (Jan 28, 2026)
- Step-by-step guide to get Ralph working (Jan 6, 2026)
