ralph
npx skills add https://github.com/akillness/skills-template --skill ralph
Agent 安装分布
Skill 文档
ralph – Self-Referential Completion Loop
When to use this skill
- Long-running implementation tasks that tend to stop early
- Tasks that need autonomous multi-turn iteration without manual intervention
- Workflows where the agent must self-correct and refine output across turns
- Sessions where exact completion signaling is required before stopping
Core Concept
The loop happens across agent turns, controlled by an AfterAgent hook.
- You run ONCE:
/ralph "Your task description" --completion-promise "DONE" - Agent works: Performs actions (modifies files, runs tests, writes code)
- Hook intercepts: When the agent finishes its turn, the
AfterAgenthook intercepts the exit - Loop continuation: Hook evaluates state (max iterations, promise) and starts a new turn with the original prompt, clearing the previous turn’s context
- Repeat: Continues autonomously until completion or user interruption
Why this works
- Stable Context & No Compaction: Prompt never changes between iterations; previous conversational context is cleared. The agent relies on current file state, not stale chat history.
- Persistent State: The agent’s work persists in files and git history across iterations.
- Autonomous Improvement: Each iteration sees the current codebase state and improves on past work.
- Ghost Protection: If you interrupt the loop and start a new task, the hook detects the prompt mismatch and silently cleans up.
1. Core Command Pattern
/ralph "<task description>" [--completion-promise=TEXT] [--max-iterations=N]
Defaults:
- Completion promise:
DONE - Max iterations:
100
2. How the Loop Behaves
- Starts with your task prompt.
- On each turn end, the
AfterAgenthook checks whether the assistant output contains:
<promise>DONE</promise>
- If not found, hook starts a new agent turn with the same original prompt (context cleared).
- Stops only when:
- Completion promise is detected in output, or
- Max iterations is reached, or
- You run
/ralph:cancel
3. Practical Usage
Standard run
/ralph "Build a Python CLI task manager with full test coverage"
With completion promise
/ralph "Build a REST API for todos. When all CRUD endpoints work and tests pass with >80% coverage, output TASK_COMPLETE" --completion-promise="TASK_COMPLETE"
Bounded iteration run
/ralph "Attempt to refactor the authentication module" --max-iterations=20
TDD workflow with self-correction
/ralph "Implement feature X by following TDD:
1. Write failing tests for the feature.
2. Implement the code to make the tests pass.
3. Run the test suite.
4. If any tests fail, analyze the errors and debug.
5. Refactor for clarity and efficiency.
6. Repeat until all tests are green.
7. When complete, output <promise>TESTS_PASSED</promise>" --completion-promise="TESTS_PASSED"
Cancel active loop
/ralph:cancel
View help
/ralph:help
4. Prompt Writing Best Practices
1. Clear Completion Criteria
Provide a verifiable definition of “done.” The --completion-promise is crucial.
Good:
/ralph "Build a REST API for todos. When all CRUD endpoints are working and all tests pass with >80% coverage, you're complete." --completion-promise="TASK_COMPLETE"
2. Use Safety Hatches
Always use --max-iterations as a safety net to prevent infinite loops.
/ralph "Attempt to refactor the authentication module" --max-iterations=20
3. Encourage Self-Correction
Structure the prompt to guide the agent through work â verify â debug cycles.
5. Launch Safely
Always run in sandbox mode for safety. Enabling YOLO mode (-y) prevents constant tool execution prompts during the loop:
gemini -s -y
6. Installation (Gemini CLI)
gemini extensions install https://github.com/gemini-cli-extensions/ralph --auto-update
Required in ~/.gemini/settings.json:
{
"hooksConfig": { "enabled": true },
"context": {
"includeDirectories": ["~/.gemini/extensions/ralph"]
}
}
6. Codexìì ì¬ì© (ê¶ì¥ ë³´ì )
ralphë Geminiìì AfterAgent í
기ë°ì¼ë¡ ìë ë°ë³µëë©°, Codexë íì¬ ë¤ì´í°ë¸ ì¢
ë£-íí¬ë¥¼ ë³´ì¥íì§ ììµëë¤.
ë°ë¼ì Codexìì ralph를 ì¸ ëë ìë ë³´ì ì¤í¬ë¦½í¸ë¥¼ ì¤ì¹í´ ì¬ì©íë ê²ì ê¶ì¥í©ëë¤.
bash <your-agent-skills>/ralph/scripts/setup-codex-hook.sh
ì´ ì¤í¬ë¦½í¸ê° ìííë ê²:
~/.codex/config.tomlìdeveloper_instructionsìralphì¬ìì ê³ì½ ì 보를 기ë¡~/.codex/prompts/ralph.mdìì± (/prompts:ralphë¡ ë¹ ë¥¸ ì¤í)--dry-runìµì ì¼ë¡ ì ì© ì 미리보기
Usage:
bash <your-agent-skills>/ralph/scripts/setup-codex-hook.sh
bash <your-agent-skills>/ralph/scripts/setup-codex-hook.sh --dry-run
â ï¸ ì íì± ì ì:
- Codexìì ìì ìë 루í를 ê°ì íë ë¤ì´í°ë¸ í ì íì¬ ì íì ì ëë¤.
- ì ì¤ì ì
ralphëì ê³ì½ì ê³ ì ìí¤ê³ , ë¤ì ìì ì ë°ë³µí ë ìë ì¤ì(/prompts:ralphëë½, promise ëë½, max ë°ë³µ ì´ê³¼)를 ì¤ì¬ì¤ëë¤.
íë«í¼ë³ ì ì© ìí (íì¬ ì§ì 기ì¤)
| íë«í¼ | íì¬ ì§ì ë°©ì | íµì¬ ì¡°ê±´ |
|---|---|---|
| Gemini-CLI | ë¤ì´í°ë¸ | AfterAgent í
+ ralph extension ì¤ì¹ |
| Claude Code | ë¤ì´í°ë¸(ê¶ì¥) | ì¤í¬/ì¤ì¼ì¤í¸ë ì´ì
ì ì¬ í /ralph ì¬ì© |
| OpenCode | ë¤ì´í°ë¸(ëì¼ ê²½ë¡) | ralph í¤ìë ë±ë¡ í ëì¼ ëª
ë ¹ì´ ì¬ì© |
| Codex | ë³´ì 모ë | setup-codex-hook.sh ì¤í í /prompts:ralph ê¸°ë° ë°ë³µ ì´ì |
íì¬ ì¤í¬ë§ì¼ë¡ ê°ë¥íì§:
- Gemini-CLI/Claude Code/OpenCode: ê°ë¥
- Codex:
setup-codex-hook.shë¡ ë³´ì í ë¤ ì´ì ê°ë¥
Quick Reference
| Action | Command |
|---|---|
| Start loop | /ralph "task" |
| Custom promise | /ralph "task" --completion-promise=TEXT |
| Iteration cap | /ralph "task" --max-iterations=N |
| Cancel | /ralph:cancel |
| Help | /ralph:help |