Blog

Claude Code Loop Contracts: The Open-Source Framework for Reliable AI Automation Runs

June 2026 · 6 min read · Technical

Developer at workstation with loop workflow diagram visible on whiteboard
← Back to all posts

AI coding agents share a common failure mode: they run, produce output, and stop. Context from the session disappears. Decisions made, approaches tried, dead ends encountered: all of it evaporates when the terminal closes. The next session starts fresh, re-investigates the same ground, and sometimes makes the same mistakes.

Jason Zhou released an open-source framework called loop engineering that addresses this directly. Available at github.com/JayZeeDesign/loop-engineer-setup, it introduces three lightweight structures that make Claude Code runs accumulate rather than reset.

Why Claude Code Runs Fail to Compound

When your Claude Code session ends, the file structure persists but the reasoning trail does not. The model re-investigates the same options next session. It re-considers approaches that were tried and abandoned. Engineers at Australian development teams using Claude Code for internal tooling consistently report a similar ceiling: productive inside a single session, inconsistent across sessions, and nearly impossible to hand off cleanly to another developer.

This is not a flaw in Claude Code specifically. It is a structural problem with any tool that holds state only in session context. Loop engineering solves it by externalising the state that matters into three persistent structures.

The Three-Layer Architecture

1. Artifact Folders

Every output type gets its own folder with a README schema defining accepted inputs, expected output format, and constraints. Most Claude Code projects accumulate files in the project root. When an artifact lands in the wrong place or arrives in the wrong format, you waste time debugging output problems rather than building on them.

Artifact folders establish the contract between Claude Code's output and your downstream process: whether that is a CI pipeline, a manual review step, or another Claude Code run. The README schema is the interface definition. Once it exists, Claude Code can read it and produce compliant output without being told what the format should be.

2. Loop Contracts

Before Claude Code runs, you write a loop contract: a README per run specifying four things:

  • Goal: what does success look like for this specific run?

  • Workflow: the exact steps Claude Code should follow, in sequence

  • Backlog: known issues and deferred items, so they are not re-attempted mid-run

  • Timeline: expected duration and checkpoints

The loop contract is the spec. Claude Code follows it. When the run ends, you update the contract with what actually happened: adjustments made, decisions taken, scope changes encountered. The next session opens the loop contract before doing anything else.

This sounds like more process overhead. In practice, writing a loop contract takes three minutes. It saves twenty minutes of re-investigation next session, and eliminates the failure mode where Claude Code confidently re-implements something that was tried and discarded two sessions ago. For any multi-session engagement, the time investment is recovered on the second run.

3. Global Logs

A single logs.md file at project root tracks cross-run state: decisions made, blockers encountered, approaches tried and abandoned. When Claude Code opens a new session, it reads the logs file first. This prevents the model from re-litigating solved problems.

For Australian consultancies running Claude Code across multiple client engagements, a global log is the difference between a repeatable process and a one-person knowledge silo. When a developer moves off a project, the logs.md becomes the handover document. It contains the non-obvious decisions: the ones that that would otherwise live only in the departing developer's memory.

Open Loops vs Closed Loops

Loop engineering distinguishes two run modes:

Open loop: Claude Code runs, produces output, and stops. No verification. Fast, but errors accumulate across sessions because nothing checks whether the output is correct before the next session builds on it.

Closed loop: Claude Code runs, then verifies by running tests again:, checks output against the artifact schema, validates that the goal was met. Slower per cycle. But each cycle builds on verified work. Errors do not propagate. The work compounds.

For anything going to production, use closed loops. For rapid prototyping or one-off analysis scripts, open loops are acceptable where the output is human-reviewed before it has downstream effects.

The Real Cost of Skipping This

The failure mode loop engineering addresses is not dramatic. It is slow. Claude Code sessions that do not accumulate produce output that needs repeated investigation, re-work, and manual reconciliation at each session handoff.

For an Australian software consultancy billing at $180 to $250 per hour, the invisible cost is senior developer time spent re-establishing context that a loop contract would have preserved. Across a six-month project with regular Claude Code sessions, the difference between structured loop engineering and ad-hoc session management typically runs to $15,000 to $40,000 in recovered developer time, depending on team size and session frequency.

The pattern is consistent across the engagements Automata AI has reviewed: unstructured Claude Code use produces diminishing returns as project complexity grows; structured loop engineering produces compounding returns.

Implementing Loop Engineering in Your Team

Adoption is a three-step process:

  • Clone the repo and copy the artifact folder structure into your project. The README schemas are editable; adjust the accepted input and output formats to match your project conventions. This takes roughly thirty minutes for a typical project structure.

  • Before your next Claude Code session, write a loop contract. Goal, workflow, backlog, timeline. A focused session might produce an eight-line contract. The constraint is completeness, not length.

  • After the session, update logs.md with what happened: decisions made, approaches tried, scope changes. Two minutes. Future sessions and future team members will use this.

Start with one project. Run two sessions with loop contracts before evaluating. The difference in session-to-session consistency is visible immediately, particularly on the second session when Claude Code opens the loop contract and logs file before taking any action.

Getting Started

The loop engineering framework is open-source and requires no additional tools beyond Claude Code and a text editor. The structure is lightweight enough to adopt incrementally. Start with a loop contract on your next session, then add artifact folders and global logs as the project grows in complexity.

For Australian development teams looking to move Claude Code from a useful experiment to a reliable engineering asset, loop engineering supplies the persistence layer that makes that transition possible.

Talk to Automata AI about implementing structured Claude Code workflows for your team: book a session.

Ready to move from AI pilot to production?

We help mid-market Australian businesses deploy AI automations that actually reach production and deliver measurable ROI.