OpenSpec + Ralph Loop integration for iterative development with opencode.
Version: spec-and-loop 2.0.0 + OpenSpec 1.2.0
Quick Start Guide - Get up and running in 5 minutes!
OpenSpec provides excellent structure for planning (proposal → specs → design → tasks) but leaves execution manual. This package provides an iterative development loop — execute → commit → repeat — driven by an internal mini Ralph implementation that works with OpenCode and eliminates the need for any external Ralph runtime.
The runtime prompt is self-contained: it does not depend on Cursor-only slash commands or editor-local skills.
Version Requirements: This documentation applies to OpenSpec 1.2.0 and spec-and-loop 2.0.0.
npm install -g spec-and-loop@2.0.0Prerequisites: You need OpenSpec and the OpenCode AI agent installed:
npm install -g @fission-ai/openspec@1.2.0 opencode-aiAlternative OpenCode install methods:
# Install script (general use)
curl -fsSL https://opencode.ai/install | bash
# Homebrew (macOS / Linux)
brew install anomalyco/tap/opencode# 1. Initialize OpenSpec in your project
openspec init
# 2. Create a new change
openspec new change add-user-auth
# 3. Review and complete the OpenSpec artifacts
# (openspec/changes/add-user-auth/proposal.md)
# (openspec/changes/add-user-auth/design.md)
# (openspec/changes/add-user-auth/specs/*/spec.md)
# (openspec/changes/add-user-auth/tasks.md)
# 4. Run the ralph loop (executes tasks with opencode)
ralph-run --change add-user-authFor detailed step-by-step instructions, see QUICKSTART.md.
Testing suite for spec-and-loop 2.0.0
Spec-and-loop includes a comprehensive test suite to ensure reliability and cross-platform compatibility.
Testing Guide - Detailed instructions for running tests
# Run all tests
npm test
# Run unit tests only
npm run test:unit
# Run integration tests only
npm run test:integration
# Run tests with coverage
npm run test:coverage
# Run shellcheck linting
npm run lint- Linux: Tests run on Ubuntu (latest)
- macOS: Tests run on macOS (latest)
- Node.js: Tested on Node.js 24
All tests are run automatically via GitHub Actions on every push and pull request.
Required for spec-and-loop 2.0.0 with OpenSpec 1.2.0
Before using spec-and-loop, ensure you have:
-
Node.js - For package installation (requires >=24.0.0)
node --version # Should be >=24.0.0 -
openspec - OpenSpec CLI for specification workflow (requires 1.2.0)
npm install -g @fission-ai/openspec@1.2.0
-
opencode - Agentic coding assistant
npm install -g opencode-ai
-
jq - Command-line JSON processor
# Ubuntu/Debian sudo apt install jq # macOS brew install jq
-
git - Version control (for commits per task)
git init
For complete installation instructions, see QUICKSTART.md.
Documentation applies to OpenSpec 1.2.0 and spec-and-loop 2.0.0
openspec init- Initialize OpenSpec in current directoryopenspec new change <name>- Create a new change with artifact templatesopenspec --help- View all available commands and their syntax
ralph-run [OPTIONS]
OPTIONS:
--change <name> Specify the OpenSpec change to execute (default: auto-detect)
--max-iterations <n> Maximum iterations for Ralph loop (default: 50)
--no-commit Suppress automatic git commits during the loop
--verbose, -v Enable verbose mode for debugging
--help, -h Show this help message
OBSERVABILITY AND CONTROL:
--status Print the current loop status dashboard and exit
--add-context <text> Add pending context to inject into the next iteration and exit
--clear-context Clear any pending context and exit
Workflow for OpenSpec 1.2.0 + spec-and-loop 2.0.0
openspec new change my-featureThis creates:
- proposal.md: Why you're making this change
- specs//spec.md: Detailed requirements for each capability
- design.md: Technical decisions and architecture
- tasks.md: Implementation tasks as checkboxes
After creating the change, manually complete the OpenSpec artifacts by filling in proposal.md, design.md, specs/*/spec.md, and tasks.md.
Example tasks.md:
## Implementation
- [ ] Create database schema
- [ ] Implement API endpoints
- [ ] Write unit tests
- [ ] Add documentationralph-run --change my-featureWhat happens:
- Validation: Checks for required OpenSpec artifacts and git repository
- PRD Generation: Converts proposal + specs + design → PRD format for internal use
- Setup: Creates .ralph directory, syncs tasks symlink, and sets up output capture
- Task Execution: For each incomplete task:
- Generates context-rich prompt (full OpenSpec artifacts + a fresh task snapshot + recent loop signals)
- Runs
opencodewith the prompt via the internal mini Ralph engine - Captures output to temp directory for review and debugging
- Logs any errors to
.ralph/errors.mdwith timestamps - Creates git commit with task description (unless
--no-commit) - Marks task complete in tasks.md
- Cleanup: Automatically removes old output directories (older than 7 days)
- Completion: All tasks done
# Check loop status
ralph-run --status
# Check remaining tasks
grep "^- \[ \]" openspec/changes/my-feature/tasks.md
# View git commits
git log --oneline
# Inject context into next iteration
ralph-run --add-context "Prefer async/await over callbacks"Example workflow for OpenSpec 1.2.0 and spec-and-loop 2.0.0
# 1. Initialize OpenSpec in your project
cd my-web-app
git init
openspec init
# 2. Create a new change
openspec new change user-auth
# 3. Complete OpenSpec artifacts manually or use opencode skills
# (review and fill in proposal.md, design.md, specs/*/spec.md, tasks.md)
# 4. Execute with Ralph
ralph-run --change user-auth
# Output:
# [INFO] Found 15 tasks to execute
# [INFO] Executing task 1/15: Create User model with password field
# [INFO] Executing task 2/15: Implement password hashing
# ...
# 5. Verify implementation
git log --oneline # 15 commits, one per task
git diff HEAD~15 # See full implementation| Feature | Description |
|---|---|
| Structured Planning | OpenSpec workflow: proposal → specs → design → tasks |
| Agentic Execution | opencode executes tasks with full context |
| Iterative Loop | Each task builds on previous commits |
| Iteration Feedback | Recent failures and no-progress iterations inform the next pass |
| Granular History | One git commit per task |
| Auto-Resume | Interrupted? Run again — picks up where left off |
| Context Injection | --add-context injects guidance into the next iteration |
| Loop Status | --status shows active state, history, and struggle indicators |
| Error Tracking | Automatic error logging and archiving for debugging |
| Output Capture | Loop output captured to temp directories for review |
| Cross-Platform | Full support for Linux and macOS with portable operations |
| No External Ralph | Self-contained mini Ralph engine — no external ralph CLI needed |
Features available in spec-and-loop 2.0.0 with OpenSpec 1.2.0
spec-and-loop includes a first-party mini Ralph implementation (lib/mini-ralph/) that
provides the core iterative loop without any external Ralph dependency:
- Iterative execution: Each task builds on previous commits with full context
- State and history: Loop state, iteration history, and struggle indicators stored in each change's
.ralph/ - Prompt templates: Context-aware prompts generated from OpenSpec artifacts
- Completion promises: Loop exits when a completion signal is detected
- Task progression: Synchronized with
tasks.mdcheckboxes as the source of truth
The supported subset intentionally excludes upstream features that are out of scope for this repository's OpenSpec-first workflow (multi-agent rotation, plugin toggles, etc.).
| OpenSpec | opencode | Together |
|---|---|---|
| Structured planning | Agentic execution | Plan → Execute loop |
| Human-readable specs | AI-understandable context | Full context propagation |
| Task breakdown | Task implementation | Automatable workflow |
- Auto-resume: Interrupted? Run again — picks up where left off
- Context injection:
--add-context/--clear-contextvia each change's.ralph/ralph-context.md - Error recovery: Recent loop signals help guide subsequent tasks
- Error tracking: Automatic error logging to
.ralph/errors.mdwith timestamps and archiving - Task synchronization:
tasks.mdand the per-change.ralph/ralph-tasks.mdsymlink stay in sync - Output capture: Loop output captured to temp directories for review and debugging
- Cross-platform: Portable operations for Linux and macOS (stat, md5sum, realpath)
- Cleanup: Automatic cleanup of old output directories (older than 7 days)
- Idempotent: Run multiple times safely
Advanced features for spec-and-loop 2.0.0
Inject custom instructions into the next iteration:
ralph-run --add-context "Use Redis instead of Memcached"
# Check current pending context
ralph-run --status
# Clear pending context
ralph-run --clear-contextralph-run --statusShows: active loop state, current task, prompt summary, pending context, iteration history, and struggle indicators if the loop appears stuck.
Run without automatic git commits (useful for reviewing changes before committing):
ralph-run --change my-feature --no-commitFor debugging:
ralph-run --verbose --change my-featurecat openspec/changes/my-feature/.ralph/PRD.md# Find the latest output directory path
cat openspec/changes/my-feature/.ralph/.output_dir
# View stdout and stderr logs
cat openspec/changes/my-feature/.ralph/.output_dir/ralph-stdout.log
cat openspec/changes/my-feature/.ralph/.output_dir/ralph-stderr.logOutput is captured to temporary directories for debugging. Old output directories are automatically cleaned up after 7 days.
# View recent errors
cat openspec/changes/my-feature/.ralph/errors.md
# Archived errors are saved with timestamps
ls openspec/changes/my-feature/.ralph/errors_*.mdArchitecture for spec-and-loop 2.0.0 with OpenSpec 1.2.0
This package integrates:
- OpenSpec: Structured specification workflow
- opencode: Agentic coding assistant for task execution
- Mini Ralph (
lib/mini-ralph/): Internal iterative loop engine
Each task execution includes:
- OpenSpec artifacts: Proposal, design, and spec content from the generated PRD
- Fresh task snapshot: Raw
tasks.mdcontent plus the current task and completed-task summary rendered each iteration - Recent loop signals: Compact reminders about prior failed or no-progress iterations
- Pending context: Any
--add-contextinjection
Synchronized tracking:
- tasks.md: Human-readable checkboxes
[ ]→[x](source of truth) - .ralph/ralph-tasks.md: Symlink to
tasks.mdfor the loop engine - Atomic updates: Checkboxes updated after each completed task
openspec/changes/<name>/
├── proposal.md # Your "why"
├── design.md # Your "how"
├── tasks.md # Your "what" (checkboxes, source of truth)
├── specs/ # Your requirements
│ ├── auth/
│ │ └── spec.md
│ └── api/
│ └── spec.md
└── .ralph/ # Internal loop state (auto-generated, per change)
├── PRD.md # Generated product requirements document
├── prompt-template.md # Template used for generating prompts
├── ralph-history.json # Iteration history and state
├── ralph-loop.state.json # Current loop state and iteration count
├── ralph-tasks.md # Symlink to ../tasks.md (syncs task state)
├── .output_dir # Path to latest output capture directory
├── ralph-context.md # (Optional) Pending context for next iteration
├── errors.md # (Optional) Error logs with timestamps
├── errors_*.md # (Optional) Archived error logs
└── *.md # (Optional) Research artifacts created during task execution
Note: Files marked as (Optional) are created only when needed:
ralph-context.md: Created when you use--add-contexterrors.mdanderrors_*.md: Created when errors occur during loop execution- Additional
*.mdfiles: Research artifacts created by opencode during task execution (e.g., verification outputs, analysis documents)
Cross-platform support verified for spec-and-loop 2.0.0
spec-and-loop is designed to work seamlessly on both Linux and macOS. The script includes portable implementations for:
- File modification times: Uses
stat -f %mon macOS andstat -c %Yon Linux - MD5 hashing: Supports both
md5sum(Linux) andmd5 -q(macOS) - Path resolution: Falls back from
realpathtoreadlink -fto manual path construction - Temp directories: Uses
TMPDIRenvironment variable or/tmpas fallback - Cleanup: Portable
findandrmoperations for old output directories
All features work identically on both platforms without requiring platform-specific configuration.
Troubleshooting guide for spec-and-loop 2.0.0 with OpenSpec 1.2.0
For common issues and solutions, see QUICKSTART.md#troubleshooting.
Quick fixes:
# opencode not found?
npm install -g opencode-ai
# jq not found?
sudo apt install jq # or: brew install jq
# Not a git repository?
git init
# command not found: ralph-run?
export PATH="$PATH:$(npm root -g)/.bin"GPL-3.0