eyaltoledano/claude-task-master · error

INVALID_TASKS_FILE

INVALID_TASKS_FILE

Error message

No valid tasks found in ${tasksPath}. readJSON returned: ${JSON.stringify(data)}

What it means

expandTaskDirect loads the tasks file via readJSON and expects an object containing a valid tasks array. If readJSON fails or returns data without usable tasks, it returns this INVALID_TASKS_FILE error, embedding the path and the raw parsed data for diagnosis.

Source

Thrown at mcp-server/src/core/direct-functions/expand-task.js:115

		log.info(
			`[expandTaskDirect] Expanding task ${taskId} into ${numSubtasks || 'default'} subtasks. Research: ${useResearch}, Force: ${forceFlag}`
		);

		// Read tasks data
		log.info(`[expandTaskDirect] Attempting to read JSON from: ${tasksPath}`);
		const data = readJSON(tasksPath, projectRoot);
		log.info(
			`[expandTaskDirect] Result of readJSON: ${data ? 'Data read successfully' : 'readJSON returned null or undefined'}`
		);

		if (!data || !data.tasks) {
			log.error(
				`[expandTaskDirect] readJSON failed or returned invalid data for path: ${tasksPath}`
			);
			return {
				success: false,
				error: {
					code: 'INVALID_TASKS_FILE',
					message: `No valid tasks found in ${tasksPath}. readJSON returned: ${JSON.stringify(data)}`
				}
			};
		}

		// Find the specific task
		log.info(`[expandTaskDirect] Searching for task ID ${taskId} in data`);
		const task = data.tasks.find((t) => t.id === taskId);
		log.info(`[expandTaskDirect] Task found: ${task ? 'Yes' : 'No'}`);

		if (!task) {
			return {
				success: false,
				error: {
					code: 'TASK_NOT_FOUND',
					message: `Task with ID ${taskId} not found`
				}
			};

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Confirm tasksJsonPath points to the real .taskmaster/tasks.json and open it to check contents.
  2. Fix JSON syntax or restore from backup; validate with a JSON parser.
  3. Regenerate tasks if empty: run the PRD parsing flow (e.g. 'task-master parse-prd') to populate tasks.
  4. Ensure the file shape is { "tasks": [ ... ] } with at least the target task present.

Example fix

// before
// tasks.json: { }  -> INVALID_TASKS_FILE
// after
// tasks.json: { "tasks": [ { "id": 1, "title": "...", "status": "pending", ... } ] }
await expandTaskDirect({ tasksJsonPath, id: '1' });
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
function tasksFileIsValid(p) {
  try {
    const data = JSON.parse(fs.readFileSync(p, 'utf8'));
    return Array.isArray(data?.tasks) && data.tasks.length > 0;
  } catch { return false; }
}
if (!tasksFileIsValid(tasksJsonPath)) {
  throw new Error(`${tasksJsonPath} is missing, malformed, or has no tasks`);
}

Type guard

function isTasksData(d) {
  return d !== null && typeof d === 'object' &&
    Array.isArray(d.tasks) && d.tasks.length > 0;
}

Try / catch

const res = await expandTaskDirect(args);
if (!res.success && res.error?.code === 'INVALID_TASKS_FILE') {
  // inspect res.error.message for the path and raw data, then repair/regenerate the file
}

Prevention

When it happens

Trigger: tasks.json missing entirely, containing malformed JSON, holding an empty tasks array, or having the wrong shape (e.g. top-level array instead of {tasks:[...]}); wrong tasksJsonPath pointing to another file.

Common situations: Fresh projects where tasks.json was never generated (no parse-prd run); manual edits corrupting the file; an empty scaffold file created by an editor; pointing at a legacy or foreign schema file.

Related errors


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