$ recombobulate _
home / tips / cap-autonomous-iterations-with-max-turns
89

Cap Autonomous Iterations with --max-turns

recombobulate @recombobulate · Mar 25, 2026 · Configuration
cap-autonomous-iterations-with-max-turns

When running Claude Code non-interactively, it can sometimes spiral into repeated attempts to fix a problem that's out of its reach. --max-turns sets a hard cap on how many tool-use cycles it takes before stopping.

claude --max-turns 10 "Migrate the database schema and run tests"

Without a limit, Claude will keep going until it either solves the problem or exhausts your context window — whichever comes first. In CI pipelines and scripts, that's unpredictable and expensive.

Set --max-turns based on the complexity of the task:

# Quick review — shouldn't need many cycles
claude -p --max-turns 5 "Review this PR for obvious issues"

# Larger refactor — give it more room to work
claude -p --max-turns 25 "Refactor the auth module and update tests"

# Migration task — medium budget
claude -p --max-turns 15 "Add soft delete to all User model queries"

When Claude hits the limit, it exits with a non-zero status code and reports what it completed. This means you can handle it in shell scripts just like any other failure:

claude -p --max-turns 10 "Fix all failing tests" \
  || echo "Turn limit hit — review output and re-run with higher limit"

Pair --max-turns with --max-budget-usd for complete cost control:

claude -p --max-turns 15 --max-budget-usd 2.00 "Full migration with tests"

Think of --max-turns like a budget: you decide up front how much autonomous work you're authorising, and Claude spends it as efficiently as it can.

Always set --max-turns in automation — an unbound loop is expensive and hard to debug.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Describe Your Users in CLAUDE.md So Claude Writes Appropriate Copy, Error Messages, and UX

When Claude writes error messages, button labels, validation text, or onboarding flows, it defaults to generic developer-speak. Add a "Users" section to your CLAUDE.md describing who your actual users are — their technical level, industry jargon, and what they care about — so Claude writes copy that makes sense to THEM, not to developers.

recombobulate @recombobulate · 1 month ago
1
Create Custom Agents with --agent for Scoped Sessions

Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.

recombobulate @recombobulate · 1 month ago
106
Add Known Gotchas and Pitfalls to Your CLAUDE.md So Claude Avoids Mistakes Your Team Already Made

Every project has traps — the billing module that silently fails if you forget to queue the job, the legacy table with column names that don't match the model, the config value that must be set before tests run. Document these gotchas in your CLAUDE.md so Claude avoids the same mistakes your team spent days debugging.

recombobulate @recombobulate · 1 month ago