Single logo
  • Courses
  • Blog
  • About
Join free on SkoolJoin free on Skool

In this topic

Claude
  • CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
  • Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
  • One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
  • Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
  • Hooks That Block Destructive Actions: a PreToolUse Gate That Allows, Asks or Denies
  • Choosing a Claude Code Extension: Skill, Hook, Rules File, Subagent, Slash Command or Plugin
  • Rolling Out Claude Code to a Team: Settings Precedence, dontAsk in CI, a Hook for Every-Time Rules and a Plugin for Five Repos
  • A Claude Code Review Bot in CI: Headless -p, JSON Findings, Team Rules in Git and a Person on the Merge
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Configuring MCP Servers in Claude Code: A Command or a URL, Three Scopes, and Three Moves When One Breaks
  • The Claude Messages API: Your First Call, Field by Field
  • Claude Tool Use: How tool_use and tool_result Work in the Messages API
  • Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
  • Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
  • Claude Streaming Events: The Event Order, message_stop, Tool Arguments, Stop Reasons and a WebSocket Relay
  • Images, PDFs and Thinking Blocks in the Claude Messages API: Typed Blocks In, Typed Blocks Out
  • Getting Data Into Claude: PDF Documents, the Files API, Search Results and Citations
  • Opus, Sonnet or Haiku: Pick the Claude Model per Job, and Test the Request When a New Release Arrives
  • Adaptive Thinking and Effort in Claude: Two Dials, Set per Workload, and the Thinking Block You Must Pass Back
  • Claude Cost Tracking From usage: Count Before, Cap During, Read After, Then Find the Line That Drives the Bill
  • Claude Cache Breakpoints: Where to Put cache_control, How to Move It With the Chat, and Why the Reads Stay at Zero
  • Claude Message Batches or Real Time: Choose by Who Is Waiting, Match by custom_id, Resend Only the Failures
  • Calling Claude Through Amazon Bedrock, Google Cloud and Microsoft Foundry: Same Call, Different Door
  • The Life Cycle of a Claude App: Six Phases, a Model That Retires, and a Release Gate for Every Change
  • Pinning Claude Model IDs and Upgrading Safely: One Change at a Time, a Golden-Set Replay and a Staged Rollout
  • Content Boundaries and Schema Design for Claude: Fence the Input in a Tag, Let the Output Say I Don't Know
  • The Agentic Loop and stop_reason: Keep Turning on tool_use, Stop on end_turn, Cap the Turns
  • The Claude Agent SDK: query(), ClaudeAgentOptions and @tool, in Python and TypeScript
  • Fix the Agent: Four Broken Claude Agent SDK Configs, From the Symptom to the One Wrong Line
  • Claude Managed Agents: Cloud Sandbox, Self-Hosted Sandbox or Self-Hosted Service
  • Agent SDK Hooks for Deterministic Actions: PreToolUse, PostToolUse, and Four Hooks That Fail Silently
  • Memory and Context-Window Patterns for Claude Agents: Context Editing, Compaction and the Memory Tool
  • Reading an Agent Trace: Five Signatures, Five Missing Patterns, and How Long a Fact Must Live
  • Tool Descriptions for Claude: How Claude Picks a Tool, and How to Stop It Picking the Wrong One
  • Tool Input Schemas and Error Responses for Claude: Required Fields, Enums, is_error and a Retry Flag
  • Tool Response Shaping and a Lean Tool Set: Give Claude a Sticky Note, Not the Filing Cabinet
  • Fix the Tool Schema: Read the Trace, Fix the Card, Re-Run (Four Real Schema Bugs)
  • Client Tools, Server Tools and Approval Gates: Who Runs the Tool, and Who Says Yes First
  • Built-in Tool, Custom Tool, Skill or MCP Server? Pick the Lightest One That Fits
  • System Prompt or User Turn: Where Each Instruction Goes, and Output Limits Your Code Enforces
  • Refine the Prompt One Line at a Time, Then Clean and Fence the Customer's Text
  • Prompt Revision Driven by Evals: Name the Cause, Change One Thing, Rerun the Whole Suite
  • Long-Running Sessions: Compact, Prune, Isolate or Start Fresh, Decided by Naming the Failure
  • Context Isolation Through Subagents: Read the Logs Elsewhere, Keep One Line
  • Defensive Parsing of Claude Replies: Check the Stop Reason, Read the Block or the Text, Then Validate the Values
  • Full Context or Retrieval: Choose by Corpus Size, Cost and Freshness
  • Skepticism Toward Confident Output: Check the Quote, the Record and the Sum Before You Send
  • Debugging a Claude App: Three Error Types, the Recovery Each One Earns, and the First Failing Row
  • Six Ways a 200 Can Still Be Wrong: Hallucination, Refusal, Under-Acting, Context Loss, Format Drift and Inconsistency
  • Fix the Cause, Not the Symptom: Four Recovery Drills for an LLM App, Each Checked on a New Input
  • Integration Layer or Model Output? Three Taps and Three Questions to Find Where a Wrong Answer Lives
  • Which Test Layer Owns the Failure? Unit, Functional, Integration and End-to-End Tests for a Claude App
  • Designing an Overnight Document Pipeline on Claude: Batch Lane, Live Lane, a Cached Prefix and a custom_id Reconcile
  • Proving a Model Upgrade Is Ready: A Frozen Golden Set, a Calibrated Judge, the Right Layer and a Release Gate
  • From Requirement to Design for a Claude App: Eight Requirements, Five Elements and a Trace With No Gaps
  • Build a Claude Refund App: the Messages API, Two Tools, an MCP Server and a Hook in One Loop
  • Ship a Claude App: an Eval Gate, Two Guardrail Layers, a Cost Check From usage and a Pinned Model
  • Lab: a 30-Case Golden Set, a Calibrated Judge and a Per-Slice CI Gate on a Claude Refund App
  • Lab: Cut a Claude App's Bill by 62 Percent With Usage Data, Layered Cache Breakpoints and a Batch Job
  • Lab: Three Planted Bugs in a Claude App, a Vague Prompt, a Mistyped Tool Schema and a Broken Stream Handler
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Lab: Harden a Claude App, an Uncalibrated Judge, a Retry Loop That Retries Everything and a Hook Matcher With a Gap
  • Lab: Turn a Claude App Into a Reusable Template, One Pinned Model Id, No Key in Code and Evals Built From Data
  • Building an MCP Server: Tools, Resources and Prompts in Python and TypeScript
  • MCP Transports: stdio or Streamable HTTP, and Who Starts the Server
  • Deploying and Authenticating an MCP Server: Environment Keys for stdio, Bearer Tokens and Scopes for HTTP
  1. Blog
  2. /
  3. Claude
  4. /
  5. Building with the Claude API

Fix the Agent: Four Broken Claude Agent SDK Configs, From the Symptom to the One Wrong Line

Four support agents built with the Claude Agent SDK fail quietly: a denied lookup, a loop that never ends, a subagent with no tool and a rule that is ignored. Each symptom points to one field in the options, and one line fixes it.

Chaand Sheikh

·27 November 2026Building with the Claude API

What you will learn

  • Follow one tool call through the checks Claude Code applies before a tool runs
  • Fix a wrong allowlist, a missing turn cap, a subagent without its tool and a rule in the wrong field
  • Finish a half-wired agent so a large refund waits for a person
  • Map each symptom to the one option to check first

Before you start

  • The Claude Agent SDK: query and ClaudeAgentOptions
  • Claude tool use: tool_use and tool_result

A support agent for a small shop looks up orders and sends refunds. You built it with the Claude Agent SDK, and something is wrong. There's no stack trace. The agent just says it can't do something, or it never stops, or it approves a refund nobody checked.

With the Agent SDK, the agent is its options. A broken config is a broken agent, and a wrong config fails quietly. So the method is always the same: read the symptom, name the field, fix one line.

One tool call, four checks

Three of the four bugs live on the path a tool call takes. When the agent asks for a tool, Claude Code checks the call before it runs, in this order (as the lecture's stand-in applies the Agent SDK permission docs):

The checks a tool call passes before it runs tool call name + input 1. hooks 2. deny rules 3. allow rules allowed_tools 4. approval callback tool runs no callback: denied allowed_tools approves tools. It does not restrict them.
Hooks first, then deny rules, then allow rules, then a callback. Nothing approved means denied.

If the call passes, the tool runs and returns its content and an error flag, and that result goes back to the agent. Otherwise a denial does. All the code below comes from the lecture project, and a stand-in plays Claude Code, so the replies say test model reply.

Case 1: a wrong allowlist

Symptom: the lookup is denied, and the agent says it could not look the order up.

turn 1: mcp__support__lookup_order -> denied: not in allowed_tools
answer: test model reply: I could not look that order up.
"""Case 1, broken: bare names in the allowlist."""
options = ClaudeAgentOptions(
    system_prompt="You are a support agent for a shop.",
    mcp_servers={"support": support_server},
    allowed_tools=["lookup_order", "issue_refund"],
    max_turns=6,
)

Tools on an in-process server are named mcp__support__ plus the tool name, so bare names match nothing and nothing is approved. Fix: use the full names.

    allowed_tools=["mcp__support__lookup_order",
                   "mcp__support__issue_refund"],

Case 2: a loop with no end

Symptom: the lookup of order 9999 fails, and it's asked again, turn after turn.

turn 8: mcp__support__lookup_order -> error
stand-in: cut the demo at 8 turns, nothing in the options would
"""Case 2, broken: nothing ends the loop."""
options = ClaudeAgentOptions(
    system_prompt="You are a support agent for a shop.",
    mcp_servers={"support": support_server},
    allowed_tools=["mcp__support__lookup_order"],
    max_turns=None,
)

max_turns=None puts no cap on the loop, and the lookup is approved, so every retry just runs again. (The cut at turn 8 is the stand-in's, not the SDK's.) Fix: set a cap.

    max_turns=3,
turn 3: mcp__support__lookup_order -> error
result: error_max_turns, no answer

The run now ends with a result you can read: error_max_turns and no answer. Your code should handle that case rather than assume every run produces an answer.

Case 3: a subagent without its tool

Symptom: the refund checker says it has no tool to look up orders.

tools: Read
answer: test model reply: I have no tool to look up orders.
"""Case 3, broken: the subagent lacks its tool."""
from claude_agent_sdk import (AgentDefinition,
                              ClaudeAgentOptions)
from tools import support_server

checker = AgentDefinition(
    description="Use when a customer asks for a refund.",
    prompt="Look up the order, then report its total.",
    tools=["Read"],
)

options = ClaudeAgentOptions(
    mcp_servers={"support": support_server},
    allowed_tools=["Agent", "mcp__support__lookup_order"],
    agents={"refund-checker": checker},
)

A subagent sees its own tools list, not the main agent's. Read reads files and nothing more. Leave the list out and the subagent inherits every tool; a list keeps it small. Fix: list the tool it needs, by its full name.

    tools=["mcp__support__lookup_order"],
tools: mcp__support__lookup_order
answer: test model reply: order 3102 total is 180.

Note the main agent's allowed_tools includes "Agent", the tool that spawns a subagent, so the delegation itself is approved.

Case 4: the rule in the wrong field

Symptom: a refund of 180 is approved, and nobody is asked.

answer: test model reply: refund of 180 approved.
"""Case 4, broken: the rule is in description."""
reviewer = AgentDefinition(
    description="Hold refunds over 100 for a person.",
    prompt="You review refunds.",
    tools=["mcp__support__lookup_order"],
)

The description only tells Claude when to use the agent. The prompt is the subagent's own instructions, and here it says only "You review refunds." Fix: description says when, prompt says what.

reviewer = AgentDefinition(
    description="Use when a customer asks for a refund.",
    prompt="Hold refunds over 100 for a person.",
    tools=["mcp__support__lookup_order"],
)
answer: test model reply: held, a person must approve a refund over 100.

Finish a half-wired agent

Now a drill. The starting agent approves issue_refund by name, but the server only registers lookup_order. Because the tool is approved, nothing warns you: the failure only shows when it runs. And there's no hooks field, so nothing asks before a refund goes out.

"""The drill, start: the refund tool is not registered."""
TOOLS = [lookup_order]
support_server = create_sdk_mcp_server(
    name="support", version="1.0.0", tools=TOOLS)

The finished version registers both tools and adds a PreToolUse hook, matched on the refund tool's full name, so it runs before every refund:

"""The drill, done: registered, and a hook asks."""
from claude_agent_sdk import ClaudeAgentOptions, HookMatcher
from claude_agent_sdk import create_sdk_mcp_server
from tools import issue_refund, lookup_order

TOOLS = [lookup_order, issue_refund]
support_server = create_sdk_mcp_server(
    name="support", version="1.0.0", tools=TOOLS)

async def approve_refund(input_data, tool_use_id, context):
    if input_data["tool_input"]["amount"] <= 100:
        return {}
    return {"hookSpecificOutput": {
        "hookEventName": "PreToolUse",
        "permissionDecision": "deny",
        "permissionDecisionReason": "needs a person",
    }}

options = ClaudeAgentOptions(
    system_prompt="You are a support agent for a shop.",
    mcp_servers={"support": support_server},
    allowed_tools=["mcp__support__lookup_order",
                   "mcp__support__issue_refund"],
    hooks={"PreToolUse": [HookMatcher(
        matcher="mcp__support__issue_refund",
        hooks=[approve_refund])]},
    max_turns=6,
)

An empty answer lets the call through. A big refund gets a deny with a reason, and the tool never runs. Here are the three wirings, run by python main.py drill:

drill half-wired
  task: Refund order 3102.
  turn 1: mcp__support__lookup_order -> ok
  turn 2: mcp__support__issue_refund -> error: not registered
  turn 3: end_turn
  answer: test model reply: I could not send that refund.
drill registered, no approval
  task: Refund order 3102.
  turn 1: mcp__support__lookup_order -> ok
  turn 2: mcp__support__issue_refund -> ok
  turn 3: end_turn
  answer: test model reply: refunded 180 on order 3102.
drill finished
  task: Refund order 3102.
  turn 1: mcp__support__lookup_order -> ok
  turn 2: mcp__support__issue_refund -> denied: needs a person
  turn 3: end_turn
  answer: test model reply: that refund needs a person first.
drill finished
  task: Refund order 3101.
  turn 1: mcp__support__lookup_order -> ok
  turn 2: mcp__support__issue_refund -> ok
  turn 3: end_turn
  answer: test model reply: refunded 35 on order 3101.

Not registered, the refund errors. Registered with no approval, 180 goes out unasked. With the hook, the same refund is denied before it runs, and Claude tells the customer a person comes first, while a refund of 35 still passes. The limit of 100 is the lecture's own number. More on hooks in hooks for deterministic actions.

Quick recap: symptom to field

SymptomCheck firstFix
A tool call is deniedallowed_tools namesFull mcp__server__tool names
The run never endsmax_turnsSet a cap; handle error_max_turns
A subagent has no toolIts tools listList the tool by full name
A subagent skips a ruleprompt vs descriptionRules go in prompt
A risky call runs unaskedhooksA PreToolUse hook that denies with a reason

Try it yourself

Write a fifth broken case: the hook's matcher is "issue_refund". Predict which drill line changes, then fix it and check your prediction.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in Claude · 29 of 66

Previous
The Claude Agent SDK: query(), ClaudeAgentOptions and @tool, in Python and TypeScript
Next post
Claude Managed Agents: Cloud Sandbox, Self-Hosted Sandbox or Self-Hosted Service

Related course on Udemy

Claude Certified Developer - Foundations (CCDV-F) Exam Prep

Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)

Related posts

The Claude Messages API: Your First Call, Field by Field

One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.

Claude Tool Use: How tool_use and tool_result Work in the Messages API

Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.

Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared

Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.

Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move

Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.

On this page

  • One tool call, four checks
  • Case 1: a wrong allowlist
  • Case 2: a loop with no end
  • Case 3: a subagent without its tool
  • Case 4: the rule in the wrong field
  • Finish a half-wired agent
  • Quick recap: symptom to field
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Claude Certified Developer - Foundations (CCDV-F) Exam Prep

Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.