Stop Prompting And Start Looping. A Claude Code Engineer’s Guide to /goal and /loop
Summary
Claude Code introduces "Loop Engineering" with its "/goal" and "/loop" commands, enabling autonomous AI agent workflows. The "/goal" command allows Claude to work until a specific, verifiable condition is met, using a secondary, smaller model (default Haiku) to evaluate completion based on the conversation transcript, not direct code access. This requires conditions to be measurable, include stated checks, constraints, and optional turn limits. The "/loop" command executes prompts on a schedule (e.g., every 30 minutes) or self-paced, ideal for continuous tasks like CI health monitoring or log scanning. Combining "/loop" and "/goal" creates self-healing systems, as demonstrated by a project where "/goal" autonomously fixed six bugs in Python source files across 10 turns, while a "/loop" then continuously monitored the test suite every 5 minutes. This paradigm shifts focus from prompt writing to defining precise, verifiable "finish lines" for AI agents.
Key takeaway
For AI Engineers automating development or operational tasks, embrace Loop Engineering to move beyond manual prompting. You should define precise, verifiable "/goal" conditions, specifying measurable end states and the evidence Claude must surface. Combine this with "/loop" for scheduled, continuous monitoring or maintenance, ensuring your autonomous agents adapt to situations without constant human oversight. Always set turn limits and implement hooks to prevent unintended actions or excessive token usage.
Key insights
Loop Engineering shifts AI interaction from prompting to defining verifiable "/goal"s and scheduled "/loop" tasks for autonomous agents.
Principles
- Conditions for AI autonomy must be conversation-checkable, not just codebase-correct.
- Constraints prevent AI agents from taking undesirable shortcuts.
- Turn limits are mandatory for unattended AI agent runs.
Method
Claude Code's agentic loop evaluates prompts, calls tools, and repeats. "/goal" adds a second model (e.g., Haiku) to verify conditions from the conversation. "/loop" executes prompts on a schedule.
In practice
- Define "/goal" conditions with measurable end states and explicit evidence.
- Use "/loop" for recurring tasks like CI health checks or dependency monitoring.
- Implement hooks (e.g., "PreToolUse") to enforce constraints on AI agent file modifications.
Topics
- Loop Engineering
- Claude Code
- Autonomous Agents
- AI Workflow Automation
- Goal-Based AI
- Software Testing Automation
Best for: AI Engineer, Machine Learning Engineer, MLOps Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Towards AI - Medium.