Ctx loop

From ActiveMemory/ctx · View interactive version

Ctx loop is an AI agent skill from the GitHub repository ActiveMemory/ctx. Generate a shell script for running AI tools in autonomous iteration loops. Use when setting up unattended iteration, headless agent runs, or CI-driven AI workflows.

How to use this skill

Skill file

Generate a ready-to-use autonomous loop shell script.

Before Generating

  1. Check for existing loop script: look for loop.sh in the

project root; confirm before overwriting

  1. Verify PROMPT.md exists: the generated script defaults to

reading PROMPT.md; if missing, ask the user what prompt file

to use

  1. Verify the context directory exists: the loop pattern depends

on persistent context; run ctx init first if needed

When to Use

new loop script

signal, prompt file)

When NOT to Use

tool directly)

asked for changes

those up first with ctx init --ralph)

Usage Examples

/ctx-loop
/ctx-loop --tool aider
/ctx-loop --prompt TASKS.md --max-iterations 10
/ctx-loop --completion SYSTEM_BLOCKED --output my-loop.sh

Flags

| Flag | Short | Default | Purpose |

|--------------------|-------|--------------------|---------------------------------|

| --prompt | -p | PROMPT.md | Prompt file the loop reads |

| --tool | -t | claude | AI tool: claude, aider, generic |

| --max-iterations | -n | 0 (unlimited) | Stop after N iterations |

| --completion | -c | SYSTEM_CONVERGED | Signal that ends the loop |

| --output | -o | loop.sh | Output script filename |

Supported Tools

| Tool | Command generated |

|-----------|--------------------------------------|

| claude | claude --print "$(cat <prompt>)" |

| aider | aider --message-file <prompt> |

| generic | Template stub for custom AI CLI |

Completion Signals

The loop watches AI output for these signals:

| Signal | Meaning |

|----------------------|--------------------------------------|

| SYSTEM_CONVERGED | All tasks complete; loop exits |

| SYSTEM_BLOCKED | Needs human input; loop exits |

| BOOTSTRAP_COMPLETE | Initial scaffolding done; loop exits |

Execution

ctx loop $ARGUMENTS

The command writes a shell script (default loop.sh) and makes

it executable. Report the generated path and how to run it:

chmod +x loop.sh   # already done by ctx loop
./loop.sh

Safety Notes

between iterations to prevent runaway loops

suggest a reasonable default (e.g., 10) if the user omits it

failed iteration does not kill the loop

PROMPT.md: adding "think step-by-step before each change"

to the iteration prompt significantly improves accuracy and

reduces cascading mistakes in unattended runs

Quality Checklist

Before reporting success, verify:

a completion signal (warn them)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.