Are you the author? Sign in to claim
Engineering Loop — a CLAUDE.md workflow template that turns AI coding agents into structured engineers: 9-phase process
A structured process for Claude Code — phases, planning, verification, escape hatches.
If you let Claude Code run autonomously, it code-dumps without a clear goal, forgets its own context, and declares victory before verifying the results. You end up debugging AI-generated bugs instead of shipping features.
This is a drop-in CLAUDE.md template that defines a mandatory planning process, hard limits on retry loops, and an automatic escape hatch before Claude burns through your API credits.
A single CLAUDE.md file that defines a mandatory 9-phase process for every task:
Receive → Understand → Decompose → Plan → Align → Execute → Verify → [Gap? → Plan]
Key behaviors it defines:
flowchart TD
START([🆕 New Task]) --> QA{Pure knowledge\nquestion?\nNo code · no action}
QA -->|✅ Yes| ANSWER([💬 Direct Answer])
QA -->|No| INIT[Session Init\nInteractive · Autonomous · Just Chat?]
INIT -->|Just Chat| CHAT([💬 Just Chat\nLoop suspended])
INIT -->|Interactive or Autonomous| P0[Phase 0: Receive\nGather all context]
P0 --> P1[Phase 1: Understand\nRestate & confirm goal]
P1 --> TRACK{Micro-task?\nAll criteria met?}
TRACK -->|✅ Fast Track| EX_FT[Phase 6: Execute]
TRACK -->|Full Loop| P2[Phase 2: Decompose\nBreak into blocks]
P2 --> P3[Phase 3: Plan\nMax 5–7 steps per block]
P3 --> P4[Phase 4: Review\nCoherence check]
P4 --> P5[Phase 5: Align\nPresent plan → approve]
P5 --> P6[Phase 6: Execute\nBlock by block]
EX_FT --> P7
P6 --> P7[Phase 7: Verify\nTests · scenario · plan vs result]
P7 --> P8[Phase 8: Goal Check\nOriginal goal achieved?]
P8 -->|✅ Yes| DONE([🏁 Done])
P8 -->|❌ Gap found| ESC{Escape Hatch\ntriggered?}
ESC -->|No — iteration ≤ 3| P3
ESC -->|Yes| STOP([🛑 Stop & Escalate\nReport to human])
style STOP fill:#ff4444,color:#fff
style DONE fill:#22c55e,color:#fff
style ANSWER fill:#94a3b8,color:#fff
style CHAT fill:#94a3b8,color:#fff
style START fill:#6366f1,color:#fff
style TRACK fill:#f59e0b,color:#fff
style ESC fill:#f59e0b,color:#fff
style QA fill:#f59e0b,color:#fff
curl -o CLAUDE.md https://raw.githubusercontent.com/sidan93/claude-eng-loop/main/CLAUDE.md
Review the file, fill in the ## Project Context section, then launch Claude Code and give it a task. It will ask how to proceed before touching anything.
Asking about a concept, tool, or technology — not this project? The agent answers immediately, no phases, no tracking:
The check is strict: if the question references the project, contains any action word (fix, add, check, review…), or could produce a follow-up task — the Loop runs as usual.
Fixing a typo? Renaming a variable? The agent detects micro-tasks and skips heavy planning:
Receive → Understand → Execute → Verify
Criteria: single self-contained change, no architectural decisions, no ambiguity, under 5 minutes. Everything else gets the full loop.
At the start of each task, the agent asks once (with clickable options if your environment supports it):
| Mode | When to use | What happens |
|---|---|---|
| Interactive (default) | Unclear requirements, high stakes | Agent confirms understanding and plan before each key step |
| Autonomous | Well-defined task, you want to step away | Agent proceeds without approvals, stops only on hard blockers |
| Just Chat | Questions, exploration, brainstorming | Loop suspended — agent answers directly, no phases or planning |
Two independent settings for fully autonomous runs:
Shift+Tab to cycle) — controls whether Claude prompts for permission on each file edit or shell commandBoth can be set independently. Autonomous mode without Auto mode still prompts on each file/shell action. Auto mode without Autonomous mode still pauses at phase gates.
Security: Claude Code Auto mode lets Claude act without per-action confirmation. Use only in isolated environments — never with access to production systems or credentials.
The loop never runs forever. Claude stops and asks you when:
| Phase | What happens |
|---|---|
| 0 — Receive | Read the full task and all linked context before forming any opinion |
| 1 — Understand | Restate the task; confirm with you (interactive) or document and proceed (autonomous) |
| 2 — Decompose | Break into independently plannable blocks |
| 3 — Plan | Write an explicit step-by-step plan for each block (max 5–7 steps) |
| 4 — Review | Read all plans together, check coherence against the original goal |
| 5 — Align | Summary for simple tasks; full plans for complex ones; wait for approval or proceed per mode |
| 6 — Execute | Run block by block using available tools and skills |
| 7 — Verify | Tests, core scenario, plan vs. result — mandatory before declaring done |
| 8 — Goal check | Did we achieve what was actually asked? If not — gap analysis, back to Phase 3 |
The goal isn't to save tokens — it's to actually achieve what you asked for. Without structure, Claude produces output. With the loop, Claude produces the right output.
Catching a wrong approach in Phase 3 is cheaper than unwinding it after Phase 6.
Per-project (recommended): drop CLAUDE.md into your repo root and fill in ## Project Context. Pay special attention to Off-limits — this is what prevents Claude from touching production databases, force-pushing main, or doing anything irreversible without review.
Global (all projects): place CLAUDE.md in ~/.claude/ and remove the ## Project Context section — it has no meaning at the global level.
| Scope | Location | Project Context |
|---|---|---|
| Global | ~/.claude/CLAUDE.md | Remove it |
| Per-project | <repo-root>/CLAUDE.md | Fill it in |
Both can coexist: global sets the process, per-project overrides with specifics. Claude Code loads global config first, project config second — later instructions win for the same topic.
Existing CLAUDE.md: paste the Engineering Loop content before or after your existing instructions. Project-specific instructions take priority over the loop.
The Engineering Loop is a process guide, not an enforcement system. LLMs follow instructions reliably in most cases — but a capable model with extended thinking can rationalize skipping phases when a task looks "obvious". The model reads the instructions, understands them, and still decides they don't apply right now.
This is a known property of instruction-following in LLMs, not a bug in the template.
To maximize compliance:
The loop works as a shared contract between you and the agent. When both sides reference it, compliance is high. When only the file does, it's probabilistic.
Claude should name the current phase at each transition. If it silently jumps to writing code — it's not following the loop.
Signs it's working:
"Fast Track: [reason]. Skipping Phases 2–5."Signs it's not: starts coding immediately without asking the mode question, never mentions phases in Interactive/Autonomous, declares done without verifying.
If it skips phases: this is expected occasionally — see the Probabilistic section above. Interrupt and redirect: "Stop. You skipped the loop. Ask me for mode and restart from Phase 0." The model knows the rules and self-corrects well when prompted directly.
The loop is intentionally generic. Extend it in your CLAUDE.md:
"in Phase 6, always run make lint before committing")MIT
Claude Code governance templates by tech stack : CLAUDE.md, scoped rules, architecture docs, cost control & dev-level ad
Claude Code skills for writing peer-review rebuttals: process + tactics (write-rebuttal) and 28 per-concern answer templ
Context engineering patterns and templates for AI coding agents. CLAUDE.md / AGENTS.md examples from single-file through
A tool-agnostic AI-assisted development framework template. Structured workflow (Spec → Plan → Implement → Review) with