Loop Engineering: Design Systems That Prompt Your AI Coding Agents

Stop prompting AI agents manually. Learn how to design loops that orchestrate agents with patterns, CLI tools, and memory for production-grade automation.

Loop Engineering: Design Systems That Prompt Your AI Coding Agents

If you're still manually typing prompts into Claude Code, Grok, or Codex, you're leaving leverage on the table. The next evolution of AI-assisted development isn't better prompts โ€” it's designing loops that prompt agents for you.

As Peter Steinberger puts it: "You shouldn't be prompting coding agents anymore. You should be designing loops that prompt your agents." Boris Cherny, Head of Claude Code at Anthropic, echoes this: "I don't prompt Claude anymore. I have loops running that prompt Claude and figuring out what to do. My job is to write loops."

This is the core idea behind Loop Engineering, a practical reference repository by Cobus Greyling that provides patterns, starters, and CLI tools for building agent orchestration systems. It's inspired by Addy Osmani's work on the topic and is designed for developers using Grok, Claude Code, Codex, Cursor, and other AI coding agents.

Why This Matters

The leverage point has shifted. Instead of crafting individual prompts, you now design control systems that orchestrate agents over time. This means:

  • Automation on a cadence: Agents run on schedules (every hour, daily, on PR) without you being present.
  • Safe parallel execution: Worktrees isolate changes so agents don't step on each other.
  • Persistent project knowledge: Skills files encode your project's conventions, architecture, and constraints.
  • Real tool integration: MCP (Model Context Protocol) connectors give agents access to your actual tools โ€” Git, tickets, CI.
  • Memory and state: A durable spine outside any conversation, so agents don't forget context between runs.

The Five Building Blocks + Memory

The repository defines five primitives that form the foundation of any loop:

Primitive Job in the Loop
Automations / Scheduling Discovery + triage on a cadence
Worktrees Safe parallel execution
Skills Persistent project knowledge
Plugins & Connectors Reach into your real tools (MCP)
Sub-agents Maker / checker split
+ Memory / State Durable spine outside any conversation

Full details are in docs/primitives.md, and a cross-tool matrix is available in docs/primitives-matrix.md.

Anatomy of a Loop

A typical loop flow looks like this:

flowchart LR
A[Schedule / Automation] --> B[Triage Skill]
B --> C[Read + Write STATE / Memory]
C --> D[Isolated Worktree]
D --> E[Implementer Sub-agent]
E --> F[Verifier Sub-agent<br/>tests + gates]
F --> G[MCP / Git / Tickets]
G --> H{Human Gate?}
H -->|safe / allowlisted| I[Commit / PR / Action]
H -->|risky / ambiguous| J[Escalate to human<br/>with full context]
I --> A
J --> A

This cycle runs on a schedule, reads and writes state, executes in isolation, verifies results, and either commits or escalates. The human gate is a critical safety mechanism โ€” unattended loops can make unattended mistakes.

Production Patterns

The repository includes seven production-ready loop patterns, each with a defined cadence, starter template, and estimated token cost:

Pattern Cadence Starter Week 1 Token Cost
Daily Triage 1dโ€“2h minimal-loop L1 report Low
PR Babysitter 5โ€“15m pr-babysitter L1 watch High
CI Sweeper 5โ€“15m ci-sweeper L2 cautious Very high
Dependency Sweeper 6hโ€“1d dependency-sweeper L2 patch-only Medium
Changelog Drafter 1d or tag changelog-drafter L1 draft Low
Post-Merge Cleanup 1dโ€“6h post-merge-cleanup L1 off-peak Low
Issue Triage 2hโ€“1d issue-triage L1 propose-only Low

Not sure which to pick? Use the interactive pattern picker or check patterns/registry.yaml for a machine-readable index.

Getting Started in 5 Minutes

# 1. Scaffold + get your Loop Ready score (printed automatically)
npx @cobusgreyling/loop-init . --pattern daily-triage --tool grok

# 2. Estimate token spend for your cadence
npx @cobusgreyling/loop-cost --pattern daily-triage --level L1

# 3. Re-audit after improvements
npx @cobusgreyling/loop-audit . --suggest

# Optional: paste Loop Ready badge into your README
npx @cobusgreyling/loop-audit . --badge

# 4. See scores climb: empty โ†’ L1 โ†’ L2
bash scripts/before-after-demo.sh

# 5. Start report-only (Grok example)
/loop 1d Run loop-triage. Update STATE.md. No auto-fix in week one.

All three CLIs publish to npm from tagged releases โ€” no clone required. If you're contributing from source, you can develop from the monorepo:

cd tools/loop-init && npm ci && npm test && node dist/cli.js /path/to/project --pattern daily-triage --tool grok
cd tools/loop-audit && npm ci && npm test && node dist/cli.js /path/to/project --suggest
cd tools/loop-cost && npm ci && npm test && node dist/cli.js --pattern ci-sweeper --cadence 15m

Phased rollout is recommended: L1 (report only) โ†’ L2 (assisted fixes) โ†’ L3 (unattended). See the loop-design-checklist for details.

CLI Tools

The repository ships several npm packages:

  • loop-audit: Loop Readiness Score CLI (v1.5 + constraints scoring) โ€” npx @cobusgreyling/loop-audit . --suggest
  • loop-init: Scaffold starters + budget/run-log + constraints โ€” npx @cobusgreyling/loop-init . --pattern daily-triage --tool grok
  • loop-cost: Token spend estimator โ€” npx @cobusgreyling/loop-cost
  • loop-sync: Drift detection between STATE.md and LOOP.md โ€” npx @cobusgreyling/loop-sync .
  • loop-context: Stateful memory manager + circuit breaker for long runs โ€” npx @cobusgreyling/loop-context --check --ledger run.json
  • loop-mcp-server: MCP runtime lookup for patterns, skills, state (repo v1; npm pending)

Operating & Safety

Loop engineering amplifies judgment โ€” both good and bad. Key caveats:

  • Token costs can explode with sub-agents and long-running loops.
  • Verification is still on you. Unattended loops make unattended mistakes.
  • Comprehension debt grows faster unless you read what the loop ships.
  • Two people can run the same loop and get opposite results. The loop doesn't know. You do.

The repository includes comprehensive safety documentation:

Contributing

The project welcomes contributions, especially failure stories and new pattern mappings. Check the contributor quickstart for ~10 min to ~1 hr tasks with same-day review on stories and adopters.

Conclusion

Loop engineering is a paradigm shift. Instead of being the person who prompts the agent, you become the person who designs the system that prompts the agent. This repository gives you the patterns, tools, and safety practices to make that shift practical.

As Addy Osmani says: "Build the loop. But build it like someone who intends to stay the engineer, not just the person who presses go."


This post is based on the Loop Engineering repository by Cobus Greyling, licensed under MIT.

Source

cobusgreyling/loop-engineering: Practical patterns, starters & CLI tools for loop engineering with AI coding agents. Design systems that prompt and orchestrate agents (inspired by Addy Osmani and Boris Cherny). Includes loop-audit, loop-init, loop-cost.