Skip to content

feat: add ralph-loop for autonomous task completion#9312

Open
ktsaou wants to merge 1 commit intoanomalyco:devfrom
ktsaou:feature/ralph-loop
Open

feat: add ralph-loop for autonomous task completion#9312
ktsaou wants to merge 1 commit intoanomalyco:devfrom
ktsaou:feature/ralph-loop

Conversation

@ktsaou
Copy link

@ktsaou ktsaou commented Jan 18, 2026

Closes #9199

Summary

Add Ralph Loop - a plugin-based mechanism that enables OpenCode to autonomously continue working on tasks without requiring human input after the initial prompt.

This feature is inspired by Ralph and allows the model to iterate on tasks until a completion condition is met or safety limits are reached.

How it works

  1. User starts a loop with /ralph-loop "your task" -p "COMPLETION_TEXT"
  2. The model works on the task
  3. When the model finishes, the chat.waiting hook fires
  4. If the model's response contains <promise>COMPLETION_TEXT</promise>, the loop stops
  5. Otherwise, the prompt is re-injected and the model continues
  6. Loop also stops when max iterations reached (default 20, max 100)

Usage

# Start a loop with completion promise
/ralph-loop -p "I_AM_DONE" Read the TODO file and complete all tasks

# Start with custom iteration limit
/ralph-loop -m 10 -p "FINISHED" Review and fix all linting errors

# Cancel an active loop
/ralph-loop:cancel

Features

  • Completion detection: Model signals completion with <promise>TEXT</promise> tags
  • Safety limits: Default 20 iterations, configurable up to 100 max
  • Cancel support: /ralph-loop:cancel or command palette
  • Server-side state: Loop persists across UI refreshes
  • TUI integration: Command palette entries for start/cancel

Test plan

  • Unit tests for state management and arg parsing (21 tests)
  • Integration tests for hook flow (17 tests)
  • Manual testing: loop starts, iterates, and stops on completion promise
  • Manual testing: cancel command stops active loop
  • Typecheck passes

Add a plugin-based mechanism to repeatedly inject prompts into sessions,
allowing autonomous task completion without human intervention.

- Add `chat.waiting` hook triggered when assistant finishes
- Register ralph-loop as internal plugin with state management
- Support `/ralph-loop` and `/ralph-loop:cancel` slash commands
- Add command palette entries for start/cancel
- Include completion promise detection with `<promise>` tags
- Enforce safety limits (default 20, max 100 iterations)
- Add 40 unit and integration tests
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@Shape6253
Copy link

Hey! If I’m understanding this correctly, this solution doesn’t really match the original idea behind Ralph Loop. As far as I can tell, in this implementation each loop step doesn’t get a fresh/clean context window, and that’s pretty critical for this approach. Could you take a look at this breakdown? I might be misunderstanding something, so happy to be corrected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Ralph behaviour on demand

2 participants

Comments