You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: flatten nested kill logic in _agent by extracting _try_graceful_group_kill
The _kill_process_group function had 4-5 levels of nesting with nested
try/except blocks. Extract the POSIX process-group kill sequence into a
dedicated helper that returns success/failure, reducing the main function
to a clean "try graceful, fall back to hard kill" pattern.
Co-authored-by: Ralphify <noreply@ralphify.co>
Copy file name to clipboardExpand all lines: docs/how-it-works.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
---
2
-
title: How Ralph Loops Work
3
-
description: Understand what happens inside each iteration of a ralph loop — command execution, prompt assembly, agent piping, and the self-healing feedback cycle.
title: How Autonomous AI Coding Loops Work — The Ralph Loop Lifecycle
3
+
description: Step-by-step breakdown of what happens inside each ralph loop iteration — command execution, prompt assembly, agent piping, and the self-healing feedback cycle that auto-fixes broken code.
4
+
keywords: autonomous coding loop lifecycle, how AI coding agents work, self-healing code loop, AI agent feedback cycle, prompt assembly pipeline, ralph loop architecture, agentic coding workflow
5
5
---
6
6
7
-
# How it works
7
+
# How the ralph loop works
8
8
9
-
This page explains what ralphify does under the hood during each iteration. Understanding the lifecycle helps you write better prompts, debug unexpected behavior, and make informed decisions about commands.
9
+
What happens inside each iteration of an autonomous coding loop? This page breaks down the lifecycle — from command execution to prompt assembly to agent piping — so you can write better prompts, debug unexpected behavior, and understand the self-healing feedback cycle.
10
10
11
-
## The iteration lifecycle
11
+
## What happens in each iteration
12
12
13
13
Every iteration follows the same sequence:
14
14
@@ -26,13 +26,13 @@ flowchart TD
26
26
27
27
Here's what happens at each step.
28
28
29
-
### 1. Re-read RALPH.md
29
+
### 1. Re-read the prompt from disk
30
30
31
31
The prompt body (everything below the frontmatter) is read from disk **every iteration**. This means you can edit the prompt text — add rules, change the task, adjust constraints — while the loop is running. Changes take effect on the next cycle.
32
32
33
33
Frontmatter fields (`agent`, `commands`, `args`) are parsed once at startup. To change those, restart the loop.
34
34
35
-
### 2. Run commands
35
+
### 2. Run commands and capture output
36
36
37
37
Each command defined in the `commands` frontmatter runs in order and captures its output (stdout + stderr). Commands run from the **project root** by default. Commands starting with `./` run relative to the **ralph directory** instead — useful for scripts bundled alongside your `RALPH.md`.
38
38
@@ -47,7 +47,7 @@ commands:
47
47
timeout: 300# 5 minutes
48
48
```
49
49
50
-
### 3. Resolve placeholders
50
+
### 3. Resolve placeholders with command output
51
51
52
52
Each `{{ commands.<name> }}` placeholder in the prompt body is replaced with the corresponding command's output. **Only commands referenced by a placeholder appear in the prompt** — if you define a command but don't use `{{ commands.<name> }}` for it, the command still runs every iteration but its output is excluded. This forces you to place data deliberately rather than accidentally dumping everything into the prompt.
53
53
@@ -63,15 +63,15 @@ These are useful for iteration-aware prompts — for example, telling the agent
63
63
64
64
Unmatched placeholders resolve to an empty string — you won't see raw `{{ }}` text in the assembled prompt.
65
65
66
-
### 4. Assemble the prompt
66
+
### 4. Assemble the final prompt
67
67
68
68
The prompt body (everything below the YAML frontmatter in `RALPH.md`) with all placeholders resolved becomes the fully assembled prompt — a single text string ready for the agent.
69
69
70
70
HTML comments (`<!-- ... -->`) are stripped during assembly — they never reach the agent. Use them for notes to yourself, like why a rule exists or what to change next. See [Annotate your prompt with HTML comments](writing-prompts.md#annotate-your-prompt-with-html-comments) for examples.
71
71
72
72
By default, ralphify appends a **co-author trailer instruction** to the end of the prompt, asking the agent to include `Co-authored-by: Ralphify <noreply@ralphify.co>` in its commit messages. This gives visibility into which commits were produced by a ralph loop. To disable it, set `credit: false` in the frontmatter.
73
73
74
-
### 5. Pipe prompt to agent
74
+
### 5. Pipe the prompt to the AI agent
75
75
76
76
The assembled prompt is piped to the agent command via stdin:
77
77
@@ -83,11 +83,11 @@ The agent reads the prompt, does work in the current directory (edits files, run
83
83
84
84
When the agent command starts with `claude`, ralphify automatically adds `--output-format stream-json --verbose` to enable structured streaming. This lets ralphify track agent activity in real time — you don't need to configure this yourself.
85
85
86
-
### 6. Repeat
86
+
### 6. Loop back with fresh context
87
87
88
88
The loop starts the next iteration from step 1. The RALPH.md is re-read, commands run again with fresh output, and the agent gets a new prompt reflecting the current state of the codebase.
89
89
90
-
## What gets re-read each iteration
90
+
## What changes between iterations
91
91
92
92
| What | When read | Why it matters |
93
93
|---|---|---|
@@ -96,7 +96,7 @@ The loop starts the next iteration from step 1. The RALPH.md is re-read, command
96
96
| Frontmatter (`agent`, `commands`, `args`) | Once at startup | Parsed when the loop starts. Restart to pick up changes. |
97
97
| User arguments | Once at startup | Passed via CLI flags, constant for the run |
98
98
99
-
## How prompt assembly looks in practice
99
+
## The self-healing feedback loop in action
100
100
101
101
Here's a concrete example. Given this `RALPH.md`:
102
102
@@ -167,7 +167,7 @@ If tests are failing, fix them first.
167
167
168
168
The agent sees the test failure and the instruction to fix it first. This is the **self-healing feedback loop**: the agent breaks something, the command captures the failure, and the agent sees it in the next iteration.
169
169
170
-
## Command execution order
170
+
## How commands run in sequence
171
171
172
172
Commands run in the order they appear in the `commands` list in the RALPH.md frontmatter. All commands run regardless of whether earlier commands fail.
Copy file name to clipboardExpand all lines: docs/llms-full.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2721,7 +2721,7 @@ commands:
2721
2721
run: scripts/run-tests.sh
2722
2722
```
2723
2723
2724
-
Commands without a `./` prefix run from the project root, so `scripts/run-tests.sh` resolves to `/scripts/run-tests.sh`. If you want to bundle the script next to your `RALPH.md`, use the `./` prefix instead — see [Working directory](how-it-works.md#2-run-commands) for details.
2724
+
Commands without a `./` prefix run from the project root, so `scripts/run-tests.sh` resolves to `/scripts/run-tests.sh`. If you want to bundle the script next to your `RALPH.md`, use the `./` prefix instead — see [Working directory](how-it-works.md#2-run-commands-and-capture-output) for details.
Copy file name to clipboardExpand all lines: docs/troubleshooting.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -315,7 +315,7 @@ commands:
315
315
run: scripts/run-tests.sh
316
316
```
317
317
318
-
Commands without a `./` prefix run from the project root, so `scripts/run-tests.sh` resolves to `<project-root>/scripts/run-tests.sh`. If you want to bundle the script next to your `RALPH.md`, use the `./` prefix instead — see [Working directory](how-it-works.md#2-run-commands) for details.
318
+
Commands without a `./` prefix run from the project root, so `scripts/run-tests.sh` resolves to `<project-root>/scripts/run-tests.sh`. If you want to bundle the script next to your `RALPH.md`, use the `./` prefix instead — see [Working directory](how-it-works.md#2-run-commands-and-capture-output) for details.
0 commit comments