claude-code-action icon indicating copy to clipboard operation
claude-code-action copied to clipboard

max_turns is never passed to SDK in run.ts, defaults to 10

Open DougLifeOfficial opened this issue 8 months ago • 2 comments

Bug Description

maxTurns is never wired through to the SDK in src/entrypoints/run.ts, causing all runs to hit the SDK's default limit of 10 turns regardless of configuration.

Root Cause

src/entrypoints/run.ts line 268 calls runClaude() without passing maxTurns:

const claudeResult: ClaudeRunResult = await runClaude(promptConfig.path, {
  claudeArgs: prepareResult.claudeArgs,
  appendSystemPrompt: process.env.APPEND_SYSTEM_PROMPT,
  model: process.env.ANTHROPIC_MODEL,
  pathToClaudeCodeExecutable: process.env.INPUT_PATH_TO_CLAUDE_CODE_EXECUTABLE,
  showFullOutput: process.env.INPUT_SHOW_FULL_OUTPUT,
  // maxTurns is MISSING
});

The ClaudeOptions type in base-action/src/run-claude.ts supports maxTurns, and parse-sdk-options.ts correctly parses it:

maxTurns: options.maxTurns ? parseInt(options.maxTurns, 10) : undefined,

But since run.ts never provides it, sdkOptions.maxTurns is always undefined, and the SDK defaults to 10.

Notably, the base-action/src/index.ts entrypoint does pass it correctly:

maxTurns: process.env.INPUT_MAX_TURNS,

But the main action uses src/entrypoints/run.ts, not the base-action entrypoint.

Why --max-turns in claude_args doesn't work either

Passing --max-turns 50 via claude_args puts the value into extraArgs["max-turns"], which is passed through to the CLI subprocess. However, the SDK enforces its own turn counter from sdkOptions.maxTurns (which is undefined → 10), so the CLI never gets a chance to process more than 10 turns.

Error

Claude Code returned an error result: Reached maximum number of turns (10)
  at readMessages (/home/runner/work/_actions/anthropics/claude-code-action/v1/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs:58:14849)

Suggested Fix

Add maxTurns to the runClaude() call in src/entrypoints/run.ts, and add a max_turns input to action.yml:

action.yml:

max_turns:
  description: "Maximum number of conversation turns for the SDK"
  required: false

src/entrypoints/run.ts:

const claudeResult: ClaudeRunResult = await runClaude(promptConfig.path, {
  claudeArgs: prepareResult.claudeArgs,
  appendSystemPrompt: process.env.APPEND_SYSTEM_PROMPT,
  model: process.env.ANTHROPIC_MODEL,
  maxTurns: process.env.INPUT_MAX_TURNS,  // <-- add this
  pathToClaudeCodeExecutable: process.env.INPUT_PATH_TO_CLAUDE_CODE_EXECUTABLE,
  showFullOutput: process.env.INPUT_SHOW_FULL_OUTPUT,
});

And wire INPUT_MAX_TURNS in the run step env:

INPUT_MAX_TURNS: ${{ inputs.max_turns }}

Same issue likely applies to systemPrompt, allowedTools, disallowedTools, mcpConfig, and fallbackModel — all supported by ClaudeOptions but not passed from run.ts.

Reproduction

  1. Create a workflow using anthropics/claude-code-action@v1
  2. Set claude_args: "--max-turns 50" or max_turns: 50
  3. Trigger the action with a task requiring more than 10 turns
  4. Observe: Reached maximum number of turns (10)

Environment

  • Action version: anthropics/claude-code-action@v1
  • Claude Code version installed by action: 2.1.92

DougLifeOfficial avatar Apr 05 '26 05:04 DougLifeOfficial

Confirmed still present on current main (2026-04-13). The scope matches the OP's suspicion — and it's verifiable by diffing the two entrypoints:

src/entrypoints/run.ts passes only 5 options:

await runClaude(promptConfig.path, {
  claudeArgs: prepareResult.claudeArgs,
  appendSystemPrompt: process.env.APPEND_SYSTEM_PROMPT,
  model: process.env.ANTHROPIC_MODEL,
  pathToClaudeCodeExecutable: process.env.INPUT_PATH_TO_CLAUDE_CODE_EXECUTABLE,
  showFullOutput: process.env.INPUT_SHOW_FULL_OUTPUT,
});

ClaudeOptions (base-action/src/run-claude.ts) defines 11:

type ClaudeOptions = {
  claudeArgs?: string;
  model?: string;
  pathToClaudeCodeExecutable?: string;
  allowedTools?: string;
  disallowedTools?: string;
  maxTurns?: string;
  mcpConfig?: string;
  systemPrompt?: string;
  appendSystemPrompt?: string;
  fallbackModel?: string;
  showFullOutput?: string;
};

base-action/src/index.ts (the other entrypoint) correctly passes all 11.

Confirmed missing from src/entrypoints/run.ts (not just likely):

  • allowedTools
  • disallowedTools
  • maxTurns
  • mcpConfig
  • systemPrompt
  • fallbackModel

The fix is copying these 6 lines from base-action/src/index.ts, which already implements this correctly. Any action.yml inputs for those 6 fields silently have no effect today.

ZWhiteTrace avatar Apr 13 '26 01:04 ZWhiteTrace

Follow-up: checked action.yml — none of the 6 missing fields are defined as inputs or wired as INPUT_* env vars, so even if run.ts is patched to read them, they'd be undefined at runtime.

Fix scope is larger than my previous comment suggested: it needs action.yml input definitions + env wiring + run.ts option passes.

That said, this raises a design question: base-action/src/index.ts exposes 11 individual inputs, but src/entrypoints/run.ts appears to intentionally minimize surface area and funnel most config through claude_args. Is the expected path for users hitting this issue to use claude_args: "--max-turns N", or should the main action expose these as first-class inputs?

(OP already notes --max-turns via claude_args doesn't work because the SDK's turn counter overrides it — which points to either an SDK-level override or the main action needing first-class inputs.)

ZWhiteTrace avatar Apr 13 '26 01:04 ZWhiteTrace