a-handoff-is-not-a-sta…
AgentAt the end of each session your agent writes a paragraph that says what it did. The next session still spends its first half hour…
The product team wants a single maximum number of turns that applies to every run of your agent. The agent handles one-line edits, multi-file refactors, and unattended runs that drive a computer for hours. What number do you give them, and how do you defend it?
Claude Code
$ npx -y skills add rohitg00/ai-engineering-from-scratch --agent claude-code
Cursor
Cursor also loads subagents from .claude/agents, so copy this file there to use it in Cursor.
id: a-turn-cap-for-every-task title: One turn cap for every task, what number do you give card: agents kind: estimate level: 2 roles: [agentic-ai-engineer, forward-deployed-ai-engineer] rounds: [screen, system-design] tags: [turn-budget, task-class, budgets, wall-clock, cost-cap] minutes: 8 lessons: [phases/14-agent-engineering/01-the-agent-loop, phases/15-autonomous-systems/10-claude-code-permission-modes] manuals: [] practice: [] cheatsheet: [agent-harness, autonomous-agents] related: [agents/the-agent-loops-forever, agents/pick-the-permission-mode] updated: 2026-11-03
The product team wants a single maximum number of turns that applies to every run of your agent. The agent handles one-line edits, multi-file refactors, and unattended runs that drive a computer for hours. What number do you give them, and how do you defend it?
There is no single number, and the estimate shows why. Agents run 40 to 400 steps per task, and a computer-use task runs dozens to hundreds of steps as a normal case. A cap that fits a one-line edit stops every refactor, and a cap that fits an unattended run lets a stuck edit spend hundreds of turns. Give one cap per task class, set each from the trace distribution of successful runs in that class, and pair every cap with a wall-clock budget and a cost cap.
| Task class | Normal length | Effect of one shared cap | |---|---|---| | One-line edit | A handful of turns | A high cap lets a stuck run burn hundreds of turns before anyone sees it | | Multi-file refactor | Tens of turns | A low cap ends the run with half the files changed | | Unattended computer use | Dozens to hundreds of steps | A low cap makes the mode unusable |
The lesson's rule is to pick a cap that fits the task class, not one size for all.
1. Pull the traces for the class and read the turn counts of the runs that passed the gate. 2. Set the cap above the longest passing run with a margin, and below the point where the traces show repeated actions. 3. Treat the cap as a yield, not a kill. When the loop reaches it, the caller sees the partial state and decides whether to extend. 4. Review the caps when the traces move. A new model or a new tool changes the distribution.
A turn cap alone misses two failure shapes. A run can spend few turns and a lot of wall-clock time, waiting on slow tools. A run can spend few turns and a lot of money, with long contexts on an expensive model. The unattended mode in the lesson ships a turn cap, a dollar cap that aborts the session, and action-count limits per tool. A 24-hour unattended run needs all three, plus an allowlist, and each number needs a written reason.
Give them a table, not a number: one row per task class with the turn cap, the wall-clock budget, the cost cap and the per-tool limits, and the trace data that each row came from. Offer one default for an unclassified task, set low, so that an unknown task yields early and a human decides.
The [agent loop lesson](../../../phases/14-agent-engineering/01-the-agent-loop/) sets the cap per task class, and the [permission modes lesson](../../../phases/15-autonomous-systems/10-claude-code-permission-modes/) pairs it with a cost cap and per-tool limits.
At the end of each session your agent writes a paragraph that says what it did. The next session still spends its first half hour…
Read this part of the harness loop. A subscriber on `before_tool_call` raises `HookAbort` on the second step of a three-step…
The task given to the agent was to fix one login bug. The diff changes the login route, an email helper, the database driver, the…
Read this run method from the toy agent loop. A caller shows the returned string to the user as the answer. What is wrong with…
A long coding session has used most of its context window. The runtime offers to summarize the older turns and keep going. Your…
A tool is registered with this schema, and the model sends the four argument sets below. For each one, say what the registry…
Reviews the repository's shared Claude Code configuration (.claude/settings.json, CLAUDE.md, .claude/rules/, .mcp.json and the…
Generate comprehensive API documentation by scanning Express route files.
Advisor to a busy principal. Optimizes for the user's time, attention, and decision quality. One of the starter-kit council…