eyaltoledano/claude-task-master · error

Invalid tasks data in

Error message

Invalid tasks data in ${tasksPath}

What it means

expandTask() loads the tasks file and, before doing anything else, validates that readJSON returned an object with a tasks array. If the file is missing, unparseable, or lacks tasks, it throws this error naming the path, mirroring the same check as expand-all-tasks.

Solutions

  1. Open the tasks file at the path in the message and fix any JSON syntax errors.
  2. Ensure you are running in the correct project root / tag so the correct tasks file is resolved.
  3. If the file is unrecoverable, regenerate it (parse-prd or init) and re-run expansion.

Example fix

// before
$ cat .taskmaster/tasks/tasks.json
{ "tasks": [ ... "truncated invalid json"
// after
$ task-master parse-prd prd.txt   # regenerate valid tasks.json, then retry expand
Defensive patterns

Strategy: type-guard

Validate before calling

const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
if (!Array.isArray(data.tasks)) throw new Error(`${tasksPath} has no tasks array`);

Type guard

function isTasksData(v) {
  return !!v && typeof v === 'object' && Array.isArray(v.tasks);
}

Try / catch

try {
  await expandTask(taskId, context);
} catch (err) {
  if (err.message.startsWith('Invalid tasks data in')) {
    console.error(`Repair or regenerate ${tasksPath}, then retry.`);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling expandTask(taskId) when the tasks file at tasksPath cannot be read or parsed (readJSON → null), or its top-level JSON has no tasks field.

Common situations: Corrupted tasks.json after a failed write or merge conflict; running from a different project root so the resolved path points to a nonexistent file; wrong active tag resolving to an empty/absent per-tag file.

Related errors


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

Appendix: source

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

			projectRoot,
			tag,
			isMCP,
			outputFormat,
			report
		});

		// If remote handled it, return the result
		if (remoteResult) {
			return remoteResult;
		}
		// Otherwise fall through to file-based logic below
		// --- End BRIDGE ---

		// --- Task Loading/Filtering (Unchanged) ---
		logger.info(`Reading tasks from ${tasksPath}`);
		const data = readJSON(tasksPath, projectRoot, tag);
		if (!data || !data.tasks)
			throw new Error(`Invalid tasks data in ${tasksPath}`);
		const taskIndex = data.tasks.findIndex(
			(t) => t.id === parseInt(taskId, 10)
		);
		if (taskIndex === -1) throw new Error(`Task ${taskId} not found`);
		const task = data.tasks[taskIndex];
		logger.info(
			`Expanding task ${taskId}: ${task.title}${useResearch ? ' with research' : ''}`
		);
		// --- End Task Loading/Filtering ---

		// --- Handle Force Flag: Clear existing subtasks if force=true ---
		if (force && Array.isArray(task.subtasks) && task.subtasks.length > 0) {
			logger.info(
				`Force flag set. Clearing existing ${task.subtasks.length} subtasks for task ${taskId}.`
			);
			task.subtasks = []; // Clear existing subtasks
		}
		// --- End Force Flag Handling ---

View on GitHub (pinned to c0c98d367c)