Repository navigation
Description
Describe the bug
--max-turns (passed via claude_args) enforces correctly and precisely at low values — verified with a controlled test at --max-turns 1. But a real production run configured with --max-turns 60 completed with num_turns: 73 and subtype: "success" — 13 turns past the configured cap, with no error, no error_max_turns, nothing indicating the limit was ever consulted. So the flag appears to fail open (silently exceed the budget) rather than fail closed (hard error) once a session is long/complex enough, even though the same mechanism is airtight for trivial sessions.
This matters because --max-turns is the primary per-run cost/runaway-loop guardrail for automated Claude Code Action usage — a mode where it silently doesn't apply, with no error signal, is an unbounded-cost risk that's invisible to the caller.
To Reproduce
Control test (works correctly):
- Run
anthropics/claude-code-action@v1(via a thin composite-action wrapper — see workflow yml below) withclaude_argsincluding--max-turns 1,use_bedrock: true, on a trivial PR review triggered by anissue_commentevent. - Result:
"num_turns": 2, "subtype": "error_max_turns", "terminal_reason": "max_turns", "errors": ["Reached maximum number of turns (1)"]. Enforced exactly as documented.
Production run (fails to enforce):
- Same action, same
claude_argsmechanism,--max-turns 60,use_bedrock: true. - Triggered on a genuinely large review task: a 20-file, ~650-line-changed PR, checked against a large repo-specific review checklist (
REVIEW.md) injected via--append-system-prompt-file, routed to an Opus Bedrock inference profile. - Session ran ~16 minutes, made 72 sequential tool calls (confirmed via full JSONL transcript — no batching, single continuous session, one
session_id, onesystem: initevent). - Final
resultevent:"num_turns": 73, "subtype": "success", "stop_reason": "end_turn", "terminal_reason": "completed"— no error at all.
Expected behavior
--max-turns should hard-stop a session once the configured turn count is reached, regardless of session length or complexity — matching its own documented behavior ("Exits with an error when the limit is reached"). If there's a legitimate reason turns can exceed the configured cap (e.g. the --input-format stream-json "a queued message runs as its own turn with its own limit" behavior documented in the CLI reference), that should be clearly called out in claude-code-action's docs, since consumers rely on this flag as a cost guardrail. Note: we checked the full transcript of the overshooting run for a second/queued user-authored message (the documented trigger for a fresh turn-budget segment) and found none — every user-role message was a tool_result for the immediately preceding tool call — so that specific documented mechanism doesn't obviously explain this either.
Workflow yml file
Relevant excerpt from our wrapper composite action (redacted of internal ARNs/paths, and with our internal trigger name generalized):
inputs:
max-turns:
description: "Maximum Claude turns"
required: false
default: "60"
runs:
using: composite
steps:
- id: claude
uses: anthropics/claude-code-action@v1
with:
use_bedrock: "true"
show_full_output: true
trigger_phrase: "@claude-bot"
branch_prefix: "claude-bot/"
claude_args: >-
--model <BEDROCK_INFERENCE_PROFILE_ARN>
--max-turns ${{ inputs.max-turns }}
--mcp-config "<path>/mcp-config.json"
--settings "<path>/agent-settings.json"
--allowedTools "Bash(git *),Bash(gh *),Read,Edit,Write,Glob,Grep,mcp__..."
--append-system-prompt-file "<path>/system-prompt.md"API Provider
- Anthropic First-Party API (default)
- AWS Bedrock
- GCP Vertex
Additional context
- Checked existing issues: #1177 ("max_turns is never passed to SDK in run.ts, defaults to 10") describes a related-sounding but distinct symptom — our low-N control test contradicts a blanket "value is ignored" claim, since
--max-turns 1was honored exactly on our setup. #823 ("No error message displayed when Claude runs out of turns") also doesn't match — our control test'serrorsfield was populated correctly. - Both runs used the identical composite-action wiring and Bedrock inference-profile setup; they differ mainly in turn-count magnitude and session complexity (1 trivial tool call vs. 72 tool calls / ~16 min / Opus-routed review).
- Claude Code CLI version bundled at run time:
2.1.220. - This is currently our only per-run cost guardrail on top of this action, so this silent-overshoot behavior is an open operational risk for us.
Activity