Claude Code loop engineering: build agents that keep moving

Overview
Agent Engineering
June 20, 2026Updated June 28, 2026Agent EngineeringClaude Code loop engineering

Design Claude Code loop engineering workflows with goals, checkpoints, reviewer gates, and proof artifacts instead of relying on one-off prompts.

Claude CodeLoop engineeringAI agentsWorkflow automation

What you will build

This guide shows how to build a Claude Code loop that can keep working without losing the thread. The loop has a goal, a plan, a state file, a bounded execution step, a reviewer step, and a proof gate.

The human still owns intent and approval. The loop owns repetition, bookkeeping, and the boring discipline that people skip when they are tired.

Workflow

Claude Code loop engineering system

  1. 1

    Define the mission

    Write one goal, one done definition, and one stop condition before the agent touches files.

    Why: A loop without a stop condition becomes a wandering conversation.

  2. 2

    Create durable state

    Store current task, completed steps, blockers, evidence, and next action in a small Markdown or JSON file.

    Why: The loop needs memory outside the model window.

  3. 3

    Execute one slice

    Let the worker agent handle one scoped unit of work.

    Why: Small slices make failure recoverable and reviewable.

  4. 4

    Review the slice

    Ask a reviewer agent or review prompt to check correctness, tests, and missing evidence.

    Why: The reviewer protects the loop from confident drift.

  5. 5

    Update proof

    Record tests, screenshots, diffs, links, or command output that prove the slice is done.

    Why: Proof is the difference between progress and vibes.

  6. 6

    Decide next action

    Continue, revise, escalate, or stop based on the state file.

    Why: The loop becomes a state machine instead of another chat.

Setup
3

Before you start

  • Claude Code or another coding agent with shell and file access
  • A repository with tests, lint, and a clear review gate
  • A writable run log such as docs/agent-runs or .agent/runs

Step 1 - Write the loop contract

Start with a short contract. Put it somewhere the agent can read every cycle, for example .agent/loop-contract.md.

# Loop contract

Goal: Migrate the checkout to a working blog article system.
Done: Articles render, navigation links work, lint/build pass, and changes are committed.
Stop when: A test requires missing credentials, a destructive migration is needed, or the goal changes.
Evidence required: changed file list, route URLs, lint/build output, and final git status.

Keep this file boring. It should not contain every preference you have ever had. It should contain the contract that matters for this run.

Step 2 - Create a state file

The loop needs a place to write what happened. JSON is useful when scripts read it; Markdown is useful when humans read it.

{
  "goal": "publish agent loop blog articles",
  "status": "in_progress",
  "cycle": 3,
  "completed": ["found content renderer", "created article draft"],
  "nextAction": "run lint and fix failures",
  "blockers": [],
  "evidence": [
    "content/tutorials/claude-code-loop-engineering-guide.md",
    "npm run lint"
  ]
}

The state file is not a diary. It is the smallest durable record another agent needs to continue.

Step 3 - Make each cycle small

A practical loop cycle looks like this:

  1. Read the contract and state file.
  2. Inspect only the files needed for the next action.
  3. Do one scoped edit or one scoped investigation.
  4. Run the narrowest useful verification.
  5. Update the state file.
  6. Decide whether to continue, revise, or stop.

If a cycle cannot be summarized in one sentence, split it.

Step 4 - Add a reviewer gate

The reviewer prompt should be stricter than the worker prompt. It should ask for defects, missing proof, bad assumptions, and overreach.

Review this cycle as a release gate.

Check:
- Does the diff match the loop contract?
- Are there unrelated changes?
- Did tests actually run?
- Are there hidden assumptions that need user approval?
- Is the next action concrete?

Return:
- pass or fail
- required fixes
- evidence that supports the decision

For code changes, the reviewer should prefer file and line references. For content changes, it should check source attribution, originality, titles, summaries, and reader usefulness.

Step 5 - Make proof part of the output

The loop should not say "done" because it edited files. It should say "done" when proof exists.

Useful proof types:

  • lint, typecheck, unit test, and build output;
  • browser or simulator screenshots for UI work;
  • route checks for generated pages;
  • changed file list;
  • final git status --short;
  • commit hash after commit.

This is where loop engineering becomes more than prompt engineering. The agent is not rewarded for sounding done. It is rewarded for making done observable.

Step 6 - Decide how the loop stops

A good stop condition is specific:

  • stop if a command needs credentials that are not available;
  • stop if the next step would overwrite unrelated user work;
  • stop if the task requires a product decision;
  • stop if verification reveals a pre-existing failure outside the requested scope;
  • stop when the done definition passes.

Avoid vague stop conditions like "when the agent feels confident." Confidence is not a control plane.

Step 7 - Integrate the loop into daily development

You do not need a large framework at first. Start with three files:

FilePurpose
.agent/loop-contract.mdDefines goal, done, stop, and proof
.agent/run-state.jsonStores current cycle and next action
.agent/reviewer.mdDefines the release gate

Then add a script only after the manual loop proves useful. The script can rotate state files, spawn agents, collect proof, and fail closed when required evidence is missing.

Tutorial
Guide

Answer Engine Summary

Design Claude Code loop engineering workflows with goals, checkpoints, reviewer gates, and proof artifacts instead of relying on one-off prompts. Use this tutorial to turn Claude Code loop engineering into a buildable workflow with prerequisites, source citations, implementation examples, review boundaries, and proof artifacts.

For AI search, the extractable answer is direct: Claude Code loop engineering should be implemented as a bounded workflow with clear setup, source-grounded behavior, human review for risky actions, and a verification artifact before it is reused or scaled. The supporting keywords are Claude Code, Loop engineering, AI agents, Workflow automation, Agent Engineering.

Source-Backed Guidance

This guide uses source article, and Claude Code documentation as its source baseline. Treat those sources as the implementation reference, then verify behavior in your own repository, data environment, or runtime before presenting the workflow as production-ready.

SEO elementRecommendation
Primary queryClaude Code loop engineering
Search intentimplementation guide
AudienceDevelopers turning Claude Code sessions into repeatable stateful engineering loops.
Citation angleExplain the build path, cite the source behavior, and show the verification artifact
Related internal pathsUse adjacent tutorials with matching tags.

Implementation Examples and Checks

ExampleHow to use itProof to capture
First setup passStart with Claude Code or another coding agent with shell and file access.Command output, config diff, or local route evidence showing the environment is ready.
Controlled implementationUse a repository with tests, lint, and a clear review gate for one narrow, reviewable case.A small artifact, report, test, retrieval result, or code diff that a reviewer can inspect.
Source-grounded reviewCompare the result against source article.A reference link plus notes on what changed from the source example.
Expansion decisionUse a writable run log such as docs/agent-runs or .agent/runs as the owner, approval input, or readiness check for the next scope.A written pass/fail decision with owner, limitation, and next action.

FAQ

FAQ

FAQ for Claude Code loop engineering

What does this tutorial help me build?

It helps you build or evaluate Claude Code loop engineering as a bounded workflow with setup steps, implementation examples, source citations, and verification evidence instead of a loose prompt or concept note.

Which keywords should this page target?

Target Claude Code loop engineering as the primary phrase, then support it with Claude Code, Loop engineering, AI agents, Workflow automation, Agent Engineering. Use those phrases in natural headings, examples, metadata, and related links rather than repeating them mechanically.

How should I validate the implementation?

Run the smallest command, route check, retrieval test, or code review that proves the workflow works in your environment. Capture the output and keep it next to the source references.

What should stay human-reviewed?

Keep data access, customer-facing output, regulated decisions, production code changes, financial actions, and destructive operations behind human review until logs, approvals, and recovery paths are proven.

How often should I refresh this tutorial?

Refresh it when the linked source docs, SDK behavior, model interfaces, or deployment target changes. AI-agent and RAG tutorials should be rechecked at least quarterly because platform behavior moves quickly.

Related resources
4
References
2

References

The source article popularizes the language of loop engineering. This article turns the idea into a practical implementation pattern for repository work: external state, small cycles, reviewer gates, and proof-first completion.

Stefan Creadore · @Eldergenix - generated and hand-seeded tutorials for governed agent systems