Anthropic Releases Claude Code v2.1.317 with Fail-Closed SDK Hooks and Gateway Cost Analytics
What changed
Anthropic released Claude Code v2.1.317, introducing enhanced security prompts, fail-closed SDK execution controls, and expanded enterprise administrative tooling. Building on earlier security patches in v2.1.309, this update prioritizes user privacy and governance controls.
Key security and authorization changes include:
- Fail-closed SDK callbacks: The Agent SDK now accepts
onFailure: "block"for hook callbacks. If a callback fails or throws an exception, the system blocks the corresponding action rather than allowing it to run. - Email transmission checks: Claude Code now requires explicit permission before a web or shell tool call sends the account’s email address over the network.
- Cloud schedule warnings: Executing
/schedulenow triggers a warning if a new cloud scheduled task receives unrequested connectors, along with instructions on how to remove them. - Managed settings notifications: Claude Desktop’s Code tab now displays explicit status notices when an organization’s remote managed settings fail to load or finish synchronizing.
Administrative, observability, and workflow updates include:
- Gateway cost analytics API: The Claude apps gateway admin API includes a new endpoint,
GET /v1/organizations/analytics/cost, allowing administrators to pull historical spend over date ranges summarized by total spend, individual developer, day, or Identity Provider (IdP) group. - IdP group tracking: Gateways with
admin:configured now store a daily record of each developer’s IdP groups for the duration specified byadmin.identity_retention_days. - Expanded OpenTelemetry spans: Added
anthropic.plan,anthropic.seat_type,anthropic.provider, andanthropic.custom_base_urlto OTel metrics, spans, and events. - Self-hosted runner session flag: Developers can set
CLAUDE_CODE_DISABLE_NESTED_SESSION_ID=1on self-hosted runners soclaude -pruns inside a session use that session’s ID and transcript, expanding on environment controls added in Claude Code v2.1.311. - Strict failure exit codes: If
claude -pfails to write transcripts or updates to~/.claude.jsondue to quota or full disk limits, it now outputs an explicit error and exits with code1instead of0.
Why it matters
Adding onFailure: "block" to the Agent SDK fixes a critical default in programmatic governance. Previously, if a custom security callback or policy filter crashed, the tool call could fail open. Developers can now mandate that failed inspection hooks strictly block tool execution.
The additions to telemetry and admin APIs give engineering leaders clearer visibility into LLM expenditure and infrastructure usage. Organizations running multi-tenant gateways or custom base URLs can track cost allocation directly back to IdP groups.
Furthermore, updating claude -p to exit with status code 1 on storage failure prevents automated CI/CD pipelines from passing silently when transcript logging or session state updates fail.
What to do next
- Enforce Fail-Closed Callbacks: Update Agent SDK hook definitions to include
onFailure: "block"on sensitive tool calls. - Query Gateway Analytics: Configure
admin.identity_retention_dayson Claude apps gateways and integrateGET /v1/organizations/analytics/costinto internal monitoring dashboards. - Configure CI Runners: If your automated workflows call nested
claude -pcommands and require unified transcript tracking, setCLAUDE_CODE_DISABLE_NESTED_SESSION_ID=1in your runner environment. - Audit Scheduled Tasks: Use
/scheduleto inspect active cloud tasks and strip out any unrequested connectors.
Limitations and Caveats
While non-zero exit codes now trigger on local disk write failures during claude -p runs, Anthropic notes that storage errors occurring on full NFS exports may still be missed.
Sources
Share Article
If this article helped you, please share it with others!