eyaltoledano/claude-task-master · error

INVALID_TASKS_FILE

INVALID_TASKS_FILE

Error message

No valid tasks found in ${tasksJsonPath}${tag ? ` for tag '${tag}'` : ''}

What it means

removeTaskDirect reads the tasks file with readJSON before removing tasks. If the file cannot be read, parses to nothing, or contains no `tasks` array (e.g. under the given tag), the function returns INVALID_TASKS_FILE because there is no task data to validate ids against.

Source

Thrown at mcp-server/src/core/direct-functions/remove-task.js:70

					message: 'Task ID is required'
				}
			};
		}

		// Split task IDs if comma-separated
		const taskIdArray = id.split(',').map((taskId) => taskId.trim());

		log.info(
			`Removing ${taskIdArray.length} task(s) with ID(s): ${taskIdArray.join(', ')} from ${tasksJsonPath}${tag ? ` in tag '${tag}'` : ''}`
		);

		// Validate all task IDs exist before proceeding
		const data = readJSON(tasksJsonPath, projectRoot, tag);
		if (!data || !data.tasks) {
			return {
				success: false,
				error: {
					code: 'INVALID_TASKS_FILE',
					message: `No valid tasks found in ${tasksJsonPath}${tag ? ` for tag '${tag}'` : ''}`
				}
			};
		}

		const invalidTasks = taskIdArray.filter(
			(taskId) => !taskExists(data.tasks, taskId)
		);

		if (invalidTasks.length > 0) {
			return {
				success: false,
				error: {
					code: 'INVALID_TASK_ID',
					message: `The following tasks were not found${tag ? ` in tag '${tag}'` : ''}: ${invalidTasks.join(', ')}`
				}
			};
		}

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Verify the tasks.json file exists at tasksJsonPath and contains a top-level `tasks` array (run task-master list to confirm)
  2. Check the `projectRoot` and `tag` arguments resolve to the right file/tag; create the tag first if needed (tag tool or task-master tags --create)
  3. Re-initialize or regenerate the task data (task-master init / parse-prd) if the file is missing or corrupt
  4. Restore tasks.json from backup or version control if a manual edit removed the tasks array

Example fix

// before
await client.callTool('remove_task', { id: '5', tasksJsonPath: './tasks.json' });

// after
await client.callTool('remove_task', { id: '5', projectRoot: '/correct/project', tasksJsonPath: '/correct/project/.taskmaster/tasks/tasks.json' });
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync } from 'fs';
function tasksFileLooksValid(tasksJsonPath, tag) {
  try {
    const data = JSON.parse(readFileSync(tasksJsonPath, 'utf8'));
    if (!Array.isArray(data.tasks)) return false;
    if (tag && data.tags && !data.tags[tag]) return false;
    return true;
  } catch {
    return false;
  }
}

Type guard

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

Try / catch

try {
  const res = await client.callTool('remove_task', { id, projectRoot });
  if (res.error?.code === 'INVALID_TASKS_FILE') {
    console.error(`Tasks file missing or empty at ${res.error.message} — run task-master init or fix projectRoot/tag`);
  }
} catch (e) {
  console.error('remove_task failed:', e.message);
}

Prevention

When it happens

Trigger: tasksJsonPath points to a missing or empty file, the JSON root has no `tasks` array, the file is corrupt/partially written, or the `tag` filter targets a tag that has no tasks array in .taskmaster/state or the tasks file.

Common situations: Running remove_task before any tasks exist (no init/generate yet); wrong projectRoot so the path resolves to a non-existent file; switching tags where the target tag was never created; manual edits that dropped the tasks key; interrupted writes leaving truncated JSON.

Related errors


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