Skip to content

fix(claude-agent-sdk): stop denied native tool calls from burning Opus sessions #494

Description

@ddotz

Summary

The Claude Agent SDK adapter intentionally sets permissionMode: "dontAsk" and makes canUseTool always deny native Claude Code tools, expecting execution to go through Senpi's in-process MCP custom-tools pipeline.

In OMO/Senpi task runs, the model can still select native Bash. That call is denied, and the outer continuation path treats the resulting shutdown as unfinished work. It creates another external SDK/Opus session and replays the full serialized task context. This repeats until the account hits its session/token limit.

Observed evidence

  • Every affected child session has entrypoint: "sdk-ts", promptSource: "sdk", and userType: "external".
  • The affected sessions start in permissionMode: "dontAsk".
  • Native Bash calls return Permission to use Bash has been denied.
  • The session then records interruptedByShutdown: true; the continuation starts a fresh Opus session.
  • Replayed prompts were about 300k characters per session.

Why this appears to be an adapter gap

Commit 5fd13840785a65d5d8b34528843b20709b195e8e explicitly documents that native tool calls are denied while Senpi executes through its own pipeline. The failure path above lets a denied native call escape into continuation/retry instead of executing the equivalent custom tool or returning a terminal failure to the parent.

Expected behavior

  1. The SDK agent should reliably use mcp__custom-tools__* for executable tools, or native tools should be routed through the Senpi permission pipeline.
  2. A native-tool denial, permission rejection, user interrupt, shutdown, or provider-limit error must be terminal to the current continuation; it must not create a new provider session automatically.
  3. If an actual retry is appropriate, resume the existing SDK session rather than replaying the whole task transcript into a fresh Opus session.

Impact

This can exhaust an Anthropic account by repeatedly opening Opus sessions for a task that cannot execute its first Bash command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions