# Agent Loops — Safe Multi-Step and Unattended Runs

> Sets up multi-step or unattended agent loops with fresh context per step, separate review, stop conditions and rollback.

Agent Loops — Safe Multi-Step and Unattended Runs is a free AI agent skill on Agensi by Cristhian Zanforlin Lousa, in Agents & Orchestration. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Cristhian Zanforlin Lousa](https://www.agensi.io/creators/cristhian-zanforlin-lousa)
- Category: [Agents & Orchestration](https://www.agensi.io/skills/agents-orchestration)
- Version: 1.0
- Last updated: 2026-11-25
- Security: scan passed (2026-11-25); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/agent-loops-safe-multi-step-and-unattended-runs
- Tags: agents, automation, claude-code, workflow, agent-loops, orchestration

## About this skill

Running Agent Loops is a playbook for driving work across many steps or iterations, including unattended runs, without the run drifting, looping, or shipping sloppy code. The trade-off it is built around is isolation versus continuity. A fresh context for each step prevents drift, but then whatever needs to carry over has to be carried deliberately.

**Principles applied to every loop:**
- Each step (`claude -p` or a subagent) starts with a fresh context.
- The reviewer is never the author.
- Two focused passes beat one heavily constrained pass.
- Every loop has an explicit stop condition: maximum runs, cost, time, or a completion signal.

**Four patterns, from simplest to most involved:**
- **Sequential pipeline:** implement → de-sloppify → verify → commit.
- **PR loop:** implement → review → fix → checks, repeated until green or out of budget.
- **Parallel fan-out:** an orchestrator assigns each agent a distinct direction, run in waves of 3–5.
- **RFC → DAG:** work units with dependencies, isolated worktrees, a merge queue.

**Also covered:**
- **The cross-iteration bridge:** a `SHARED_TASK_NOTES.md` file each step reads at the start and updates at the end.
- **The de-sloppify pass:** a separate cleanup step that removes dead code, debug prints, and over-engineering. The pass is bounded: it cleans only the lines the step added and never redesigns, renames or widens the step's scope. Every step is checked against the **original** contract, not the previous step's output, so drift can't build up across iterations.
- **A pre-launch safety checklist:** green baseline tests, budget, a branch or worktree for rollback, checkpoints, and clear rules for when to escalate to a human (no progress across two checkpoints, a repeated error, off-objective drift, budget exceeded).

**Triggers on:** "loop", "run autonomously", "iterate until it's done", chaining `claude -p` calls, fanning out parallel agents, or setting up an implement → verify → commit cycle. It does not trigger for one-shot tasks.

The skill is a focused `SKILL.md` plus the slop catalog it cites for the cleanup pass (bundled under `shared/`). Free and MIT-licensed, part of claude-skills-czl.

**Source on GitHub:** [this skill](https://github.com/Cristhianzl/claude-skills-czl/tree/main/configs/agnostic/skills/running-agent-loops) · [full repository](https://github.com/Cristhianzl/claude-skills-czl)

## Requires

- Git

## Known limitations

Loops assume a shell, git and a headless agent CLI (examples use claude -p), and each iteration costs model usage. Every loop needs explicit stop conditions; the cleanup pass touches only lines the step added. Pushing and opening PRs are left to you and the related skills.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Agent Loops — Safe Multi-Step and Unattended Runs skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### Does it work outside Claude Code?

The patterns are tool-agnostic and the skill loads in any SKILL.md-compatible agent. The examples use `claude -p` as the headless runner, so with another agent you would swap in its non-interactive command. It was built and tested mainly on Claude Code.

### Will it start a loop on its own?

It triggers when you ask for a loop, an unattended run, or chained agent calls, and it puts safety in place before iteration 1: green baseline tests, a budget, a stop condition, and a branch or worktree for rollback.

### Does it push code or open PRs?

No. It commits locally per green step as a checkpoint. Pushing and opening the PR are left to you or to the separate PR skill.

### How do I install it?

Unzip it into `~/.claude/skills/` for every project, or into a project's `.claude/skills/`. The result should be `.claude/skills/running-agent-loops/SKILL.md`.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
