eyaltoledano/claude-task-master · warning

Invalid subtask count determined (${finalSubtaskCount}), def

Error message

Invalid subtask count determined (${finalSubtaskCount}), defaulting to 3.

What it means

After resolving the subtask count from the --num-subtasks flag, the complexity report, or the default setting, expandTask sanity-checks it. If the final value is NaN or negative (e.g. a non-numeric complexity value in the report), it warns and hard-codes the count to 3.

Source

Thrown at scripts/modules/task-manager/expand-task.js:203

		// Determine final subtask count
		const explicitNumSubtasks = parseInt(numSubtasks, 10);
		if (!Number.isNaN(explicitNumSubtasks) && explicitNumSubtasks >= 0) {
			finalSubtaskCount = explicitNumSubtasks;
			logger.info(
				`Using explicitly provided subtask count: ${finalSubtaskCount}`
			);
		} else if (taskAnalysis?.recommendedSubtasks) {
			finalSubtaskCount = parseInt(taskAnalysis.recommendedSubtasks, 10);
			logger.info(
				`Using subtask count from complexity report: ${finalSubtaskCount}`
			);
		} else {
			finalSubtaskCount = getDefaultSubtasks(session);
			logger.info(`Using default number of subtasks: ${finalSubtaskCount}`);
		}
		if (Number.isNaN(finalSubtaskCount) || finalSubtaskCount < 0) {
			logger.warn(
				`Invalid subtask count determined (${finalSubtaskCount}), defaulting to 3.`
			);
			finalSubtaskCount = 3;
		}

		// Determine prompt content AND system prompt
		// Calculate the next subtask ID to match current behavior:
		// - Start from the number of existing subtasks + 1
		// - This creates sequential IDs: 1, 2, 3, 4...
		// - Display format shows as parentTaskId.subtaskId (e.g., "1.1", "1.2", "2.1")
		const nextSubtaskId = (task.subtasks?.length || 0) + 1;

		// Load prompts using PromptManager
		const promptManager = getPromptManager();

		// Check if a codebase analysis provider is being used
		const hasCodebaseAnalysisCapability = hasCodebaseAnalysis(
			useResearch,

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass an explicit valid count: task-master expand 5 --num-subtasks=4.
  2. Fix tasks.defaultSubtasks in .taskmaster/config.json to a positive integer.
  3. Regenerate the complexity report ('task-master analyze-complexity') if its recommendedSubtasks values are invalid.
  4. The CLI already self-corrects to 3 subtasks, so this is advisory only.

Example fix

// before
task-master expand 5 --num-subtasks=abc
// after
task-master expand 5 --num-subtasks=4
Defensive patterns

Strategy: validation

Validate before calling

const n = parseInt(numSubtasks, 10);
if (Number.isNaN(n) || n < 0) {
  throw new Error(`--num-subtasks must be a non-negative integer, got: ${numSubtasks}`);
}

Type guard

function isValidSubtaskCount(v) {
  return Number.isInteger(v) && v >= 0;
}

Prevention

When it happens

Trigger: finalSubtaskCount ends up NaN or < 0 — typically parseInt(numSubtasks) is NaN and no explicit/default value applied, or the complexity report contained a non-numeric/negative recommendedSubtasks value.

Common situations: Passing --num-subtasks=abc; a corrupt complexity report entry with missing/invalid numbers; getDefaultSubtasks returning NaN due to a bad tasks.defaultSubtasks config value.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/ed2c931e345b0301. Report an issue: GitHub.