# Practical ways to use the Claude Agent SDK
🎛 Worried about runaway agents? Control execution precisely with turn limits, budgets, and effort levels.
Loop Execution Control (turns, budget, effort) lets you limit agent execution scope with `max_turns`, `max_budget_usd`, and `effort` to optimize cost and latency.
📌 Title: Controlling How the Loop Runs
🔗 URL:
🧩 Overview
Set `max_turns` for tool call limits, `max_budget_usd` for cost caps, and `effort` for thinking depth. Even open-ended instructions can be safely terminated at budget limits.
🛠 How to use it
Set `max_turns=30`, `max_budget_usd=1.0`, and `effort="medium"` in your `query()` options. Use `model="claude-sonnet-4-6"` to explicitly pin a model.
🏗 Practical usage
- Set `max_turns=30` and `max_budget_usd=1.0` to prevent runaway agents. Even "Improve this codebase" can be safely capped.
- Use `effort` levels: `low` (file search), `medium` (routine edits), `high` (refactoring/debugging), `xhigh` (Opus 4.7 agentic coding), `max` (deep multi-step analysis).
- Specify `model="claude-sonnet-4-6"` for subtasks that need a smaller, faster model to optimize costs.
💡 Use cases
🛡 Safe budget limits for open-ended tasks
⚡ Effort level optimization based on task difficulty
💰 Cost reduction with lighter models for subtasks
⚠️ Watch out
Exceeding `max_turns` results in `error_max_turns`. Use `resume` to continue with higher limits. `effort` at `xhigh` or above is recommended with Opus 4.7.
#
ClaudeAgentSDK# #
AI#