LLM API Guide

Claude Code v2.1.318 & v2.1.317: Gateway assume_role, Agent SDK & /schedule

Configure Claude Code v2.1.318 and v2.1.317 features including Mantle gateway assume_role, Agent SDK onFailure: "block" hooks, Mod fork effort, and /schedule connector cleanup.

Summary

  1. Upgrade all Claude apps gateway replicas to v2.1.318 before adding assume_role to mantle upstreams.
  2. Set onFailure: "block" (or on_failure="block" in Python) in Agent SDK PreToolUse hooks on v2.1.317+ so crashed or timed-out policy callbacks block execution.
  3. Pass effort in $.model.fork inside session Mods to run side tasks at low effort while keeping the parent session's prompt cache warm.
  4. Audit and remove silently injected third-party plugins such as Postman from local MCP configs and /schedule cloud tasks.

Upgrading to Claude Code v2.1.318 (released November 4, 2026) and Claude Code v2.1.317 (released November 3, 2026) changes four critical control surfaces for enterprise gateways and unattended agent pipelines. Across these two releases, Anthropic added cross-account AWS role assumption (assume_role) on mantle upstreams in the Claude apps gateway, fail-closed hook execution (onFailure: "block") in the Agent SDK, per-fork effort overrides and persistent approval receipts for session-written Mods, and active warnings when /schedule cloud tasks inherit unrequested MCP connectors.

If you manage a multi-replica gateway cluster, run claude -p or the Agent SDK in CI, or use desktop API tools that recently modified local agent configs behind the scenes, applying these settings in the wrong order will break startup or leave unattended runs exposed.

Feature / Setting Minimum Version Scope What Happens If Misconfigured
assume_role on mantle upstream Gateway v2.1.318 Claude apps gateway Older gateway replicas crash at startup with Unrecognized key(s) in object: 'assume_role'
onFailure: "block" / on_failure="block" CLI v2.1.317, TS SDK v0.3.317, Python SDK v0.2.177 Agent SDK hooks Hook exceptions fail open by default; older binaries abort at startup with does not honor
$.model.fork effort & Mod consent receipts CLI v2.1.318 Session Mods & claude -p Side queries inherit the main session's high effort tier and burn unnecessary reasoning tokens
/schedule connector warnings & deniedMcpServers CLI v2.1.317 / v2.1.318 Cloud scheduled tasks & MCP Background tasks inherit silently installed third-party connectors (such as Postman)

On this page

Configuring assume_role on mantle Upstreams in the Claude Apps Gateway

Until v2.1.318, cross-account IAM role assumption in the Claude apps gateway only worked on standard bedrock upstreams. If you routed traffic through Amazon Bedrock Mantle endpoints (provider: mantle), the gateway had to execute inference using its own local IAM identity. In Claude apps gateway configuration on v2.1.318, mantle upstreams now accept an assume_role block so the gateway can assume an IAM role in another AWS account and tag AWS STS sessions per developer for granular cost attribution.

Before you commit assume_role to your gateway configuration file, verify that every single gateway replica in your cluster is running Claude Code v2.1.318 or newer. When I tested a rolling config reload with a leftover v2.1.317 container in the pool, the older replica immediately exited on boot with Unrecognized key(s) in object: 'assume_role'. Upgrade all running gateway binaries first, then push the YAML change.

yaml
upstreams:
  - provider: mantle
    region: us-east-1
    models:
      - claude-opus-4-7
      - claude-haiku-4-5
    auth: {}
    assume_role:
      role_arn: arn:aws:iam::222222222222:role/claude-gateway-mantle
      external_id: "984120553"
      session_name: email

The assume_role block takes three parameters: role_arn (required), external_id (optional, required if your target role's trust policy checks sts:ExternalId; wrap purely numeric IDs in quotes so YAML parses them as strings), and session_name (optional, accepts email or sub).

Setting session_name: email or session_name: sub instructs the gateway to extract that claim from the caller's OIDC token and pass it as the AWS STS RoleSessionName. If you omit session_name, every request shares the static session name claude-apps-gateway. When using email, the gateway automatically sanitizes characters outside the AWS-allowed ASCII set ([a-zA-Z0-9_+,.@-]) by encoding UTF-8 bytes as =XX hex sequences, and truncates strings longer than 64 characters while appending a deterministic hash suffix. That per-developer session naming pairs directly with the gateway cost reporting endpoint (GET /v1/organizations/analytics/cost) added in v2.1.317 and the OIDC claim mappings we covered in our Claude Code v2.1.316 pooled budgets and OIDC guide, letting you reconcile AWS CloudTrail and Cost Explorer records against internal gateway spend.

There are three operational traps specific to mantle upstreams that will break requests if you copy a standard Bedrock IAM policy:

First, standard bedrock:InvokeModel permissions do not work on Mantle endpoints. Your target IAM role (arn:aws:iam::222222222222:role/claude-gateway-mantle in the example above) must grant the bedrock-mantle: action prefix—specifically bedrock-mantle:CreateInference and bedrock-mantle:CountTokens. The gateway's own execution role (such as your ECS task role or EKS IRSA service account) does not need any Bedrock or Mantle permissions at all; it only needs sts:AssumeRole permission for the target role ARN.

Second, the gateway does not apply Bedrock Guardrails to mantle upstreams. If your gateway config defines a mantle upstream alongside a standard bedrock upstream that has guardrail enabled, the gateway refuses to start. Also keep in mind that upstream beta header mismatches across Bedrock and Mantle endpoints can still trigger an API Error 400 invalid beta flag if a client sends experimental flags the upstream rejects.

Third, watch how STS failover works across multiple upstreams. If sts:AssumeRole is denied or times out on a mantle upstream, the gateway never falls back to its own local auth credentials for that upstream. Instead, it logs the error and moves to the next upstream in your upstreams array. If your second upstream is a fallback bedrock or mantle block without assume_role, the request succeeds using the gateway's default credentials, which silently corrupts your per-developer AWS cost attribution. To enforce strict billing separation, configure assume_role with session_name on every Bedrock and Mantle upstream in the list.


Setting onFailure: "block" in Agent SDK Hooks for Fail-Closed Security

Prior to v2.1.317, Agent SDK hooks defaulted to a fail-open model. If you wrote a PreToolUse callback to validate shell commands or check external policy endpoints, and your callback threw an unhandled exception, timed out, or returned a malformed object, the SDK emitted an SDKInformationalMessage with the tag hook_callback_failed and allowed the tool call to proceed anyway. In an interactive terminal, a human might catch the subsequent permission prompt, but in an unattended pipeline, a crashed policy script meant unrestricted Bash execution.

Starting in Claude Code CLI v2.1.317, TypeScript @anthropic-ai/claude-agent-sdk v0.3.317, and Python claude-agent-sdk v0.2.177, you can set onFailure: "block" (or on_failure="block" in Python) on any hook matcher to enforce fail-closed behavior.

Here is the TypeScript configuration:

typescript
import type { Options } from "@anthropic-ai/claude-agent-sdk";

const options: Options = {
  hooks: {
    PreToolUse: [
      {
        matcher: "Bash",
        hooks: [verifyCommandPolicy],
        onFailure: "block",
      },
    ],
  },
};

And the equivalent Python configuration:

python
from claude_agent_sdk import ClaudeAgentOptions, HookMatcher

options = ClaudeAgentOptions(
    hooks={
        "PreToolUse": [
            HookMatcher(
                matcher="Bash",
                hooks=[verify_command_policy],
                on_failure="block",
            )
        ]
    }
)

When verifyCommandPolicy throws an error or exceeds its timeout under onFailure: "block", the SDK immediately halts the tool execution and returns a tool result containing failed; blocking because onFailure is "block". Your internal exception stack trace is stripped so sensitive policy logic or internal URLs are never leaked into the model's context window.

To prevent silent downgrades, the SDK validates support at session initialization before sending your first prompt. If the underlying Claude Code binary on the runner is older than v2.1.317, startup aborts immediately with an error message containing does not honor. Similarly, if you resume or attach to an existing session that did not register your hooks, the process exits at startup with did not register your hooks.

Not every hook event can halt execution after the fact. Keep these lifecycle boundaries in mind when designing your matchers:

Hook Event Behavior When onFailure: "block" Triggers
PreToolUse Immediately blocks the tool call from running and returns the blocked status to the model.
PermissionRequest Blocks execution only if the callback failure happens before canUseTool responds.
PostToolUse Cannot undo a tool that already ran; converts the callback failure into feedback for Claude.
PreCompact, Elicitation, WorktreeCreate Both exceptions and callback timeouts block the compaction, elicitation, or worktree creation.
Stop, SubagentStop, TaskCompleted, TeammateIdle Ignores "block"; session teardown and completion transitions proceed normally.

Be careful when attaching onFailure: "block" to PreCompact. If your PreCompact hook calls a slow logging server and times out, blocking compaction on a long-running session will cause subsequent turns to hit the context ceiling and fail with API Error 400 Input is too long in Claude Code.


Controlling Mod $.model.fork Effort Levels and Auditing Session-Written Mods

If you use Claude Code Mods to run auxiliary tasks—such as extracting file symbols, summarizing diffs, or tagging commit metadata—v2.1.318 fixes a major token-spend inefficiency by adding an effort parameter to $.model.fork.

Unlike $.model.complete, which fires an isolated, stateless prompt, $.model.fork branches directly off the current conversation transcript. Because the prefix matches the parent session, almost the entire input payload is served from Anthropic's prompt cache. Previously, however, a forked call inherited the parent session's reasoning effort. If your main session was running complex architectural work at high effort, every small background fork burned high-effort output tokens.

In v2.1.318, you can pass effort: "low" (or "medium" / "high") directly inside $.model.fork:

javascript
const summaryResult = await $.model.fork({
  prompt: "Extract a JSON list of modified function names from the last turn.",
  effort: "low"
});
// summaryResult.effort reflects the actual effort tier sent ("low")

The returned object now includes the actual effort value dispatched to the upstream API. If your organization restricts maximum reasoning tiers on specific models, pinning "low" in your Mod forks also prevents auxiliary tasks from tripping an API Error 400 Invalid effort level.

Three additional Mod changes in v2.1.318 close reliability and audit gaps in automated workflows:

First, content appended by a Mod inside a prompt.submit handler now stays inside the user's current turn rather than being injected as an out-of-band system message. That preserves prompt cache prefixes and stops downstream gateways from rejecting unexpected system blocks.

Second, v2.1.318 fixes two critical bugs with the turn.step Mod hook in headless runs. Previously, when a Mod registered a turn.step hook, both claude -p and the Agent SDK erroneously reported an exit code 0 (success) even when the response was truncated mid-stream by an upstream API error or manually stopped. Unattended CI jobs now receive the proper failure status.

Third, when Claude Code writes or edits a Mod during an active session and prompts you to enable it, v2.1.318 permanently records your approval or rejection decision. Instead of treating consent as a fleeting terminal prompt that disappears once the turn finishes, the persistent record gives security and compliance teams verifiable proof of whether a human operator authorized a session-generated extension.


Cleaning Up Unauthorized /schedule Connectors After the Silent Postman Plugin Injection

The security controls in v2.1.317 and v2.1.318 around MCP connectors and outbound network checks address a very real supply-chain problem that hit developer machines this week. During background updates of Postman Desktop (versions 12.33.4 and 12.35.1, particularly on macOS), the installer silently modified local coding agent configurations without prompting the user. In Claude Code, it automatically enabled postman@claude-plugins-official in user settings and registered local MCP connectors (often causing unexpected Auth required prompts for developers who weren't even signed into Postman). In OpenAI Codex, it installed and auto-approved a startup hook forcing the agent to load a postman:api-engineer skill before answering API tasks.

Although Postman reverted the silent auto-installation behavior on November 5, 2026, the update does not retroactively clean up machines that were already modified. That creates an immediate hazard when you use /schedule in Claude Code to create cloud scheduled tasks (formerly Routines).

By default, a new scheduled task created via /schedule inherits every MCP connector currently linked to your account. If an unrequested connector like the injected Postman integration is sitting in your configuration, your unattended cloud runs inherit it automatically. To stop silent connector inheritance, Claude Code v2.1.317 now prints an explicit warning whenever /schedule attaches connectors you did not ask for in the task prompt, complete with removal instructions.

If you see unexpected connector warnings when running /schedule, or if you have Postman Desktop installed on your workstation, run through these four steps to purge the unauthorized hooks and lock down your environment:

  1. Check and remove the injected Postman agent plugin: Run Postman's plugin utility in your terminal to see if its hooks and skills were injected into your local coding agents, then strip them out:

    bash
    npx @postman/postman-plugin status
    npx @postman/postman-plugin remove
    

    You can also open the Postman Desktop app, navigate to Help > Postman CLI and Plugins, and uninstall the coding agent integration from the GUI.

  2. Audit and remove unauthorized MCP servers in Claude Code: List all registered MCP servers and remove any entry you did not explicitly configure:

    bash
    claude mcp list
    claude mcp remove postman
    

    Next, open ~/.claude/settings.json and delete any reference to postman@claude-plugins-official, then inspect ~/.claude/plugins/installed_plugins.json and remove cached entries for the plugin.

  3. Strip extra connectors from existing /schedule cloud tasks: Inside an interactive Claude Code session, inspect your scheduled routines and run the interactive updater to uncheck inherited connectors:

    text
    /schedule list
    /schedule update
    

    Alternatively, open https://claude.ai/code/routines or https://claude.ai/customize/connectors in your browser and detach the unneeded connectors from each scheduled task.

  4. Block unwanted connector URLs with deniedMcpServers: In v2.1.318, deniedMcpServers rules using serverUrl were expanded beyond local stdio servers. A serverUrl deny rule now blocks matching Anthropic-provided upstream servers as well as cloud session and self-hosted runner connectors whenever the connector's own URL is passed to the session:

    json
    {
      "deniedMcpServers": [
        { "serverUrl": "https://mcp.postman.com/*" }
      ]
    }
    

    For connectors fetched directly by Claude Code from claude.ai, always prefer serverUrl over serverName, because serverUrl survives display-name changes.

Finally, as a last line of defense against rogue plugins or skills attempting to phone home with developer identity data, Claude Code v2.1.317 added an outbound exfiltration check to the built-in Web and Shell tools. If any tool call or shell command attempts to send your authenticated account's email address over the network, Claude Code now intercepts the call and forces an explicit confirmation prompt before the request leaves your machine.

Sources and checks

  1. Claude Code v2.1.318
  2. Claude Code v2.1.317
  3. Claude apps gateway configuration
  4. Agent SDK hooks
  5. scheduled task