eyaltoledano/claude-task-master · error
No valid tasks found in ${tasksPath}.
Error message
No valid tasks found in ${tasksPath}. What it means
After confirming the tasks file exists, updateTaskById() reads it with readJSON() and requires the parsed result to contain a tasks array. This error is thrown when the file is empty, unparseable, or its JSON lacks a tasks property, so there are no tasks to search or update.
Source
Thrown at scripts/modules/task-manager/update-task-by-id.js:136
report
});
// If remote handled it, return the result
if (remoteResult) {
return remoteResult;
}
// Otherwise fall through to file-based logic below
// --- End BRIDGE ---
// For file storage, ensure the tasks file exists
if (!fs.existsSync(tasksPath))
throw new Error(`Tasks file not found: ${tasksPath}`);
// --- End Input Validations ---
// --- Task Loading and Status Check (Keep existing) ---
const data = readJSON(tasksPath, projectRoot, tag);
if (!data || !data.tasks)
throw new Error(`No valid tasks found in ${tasksPath}.`);
// File storage requires a strict numeric task ID
const idStr = String(taskId).trim();
if (!/^\d+$/.test(idStr)) {
throw new Error(
'For file storage, taskId must be a positive integer. ' +
'Use update-subtask-by-id for IDs like "1.2", or run in API storage for display IDs (e.g., "HAM-123").'
);
}
const numericTaskId = Number(idStr);
const taskIndex = data.tasks.findIndex((task) => task.id === numericTaskId);
if (taskIndex === -1) {
report('error', `Task with ID ${numericTaskId} not found`);
throw new Error(`Task with ID ${numericTaskId} not found.`);
}
const taskToUpdate = data.tasks[taskIndex];
if (taskToUpdate.status === 'done' || taskToUpdate.status === 'completed') {
report(
'warn',View on GitHub (pinned to c0c98d367c)
Solutions
- Inspect tasks.json and fix/restore valid JSON with a top-level tasks array (validate with a JSON parser)
- Restore from git or a backup if the file was corrupted
- Re-run 'task-master parse-prd' to regenerate tasks.json if contents are unrecoverable
- Avoid concurrent writes to tasks.json; let Task Master manage the file
- If this is a tag-specific file, check you are reading the right tag's file
Example fix
// before
// tasks.json: { "master": { } } // no tasks array
// after
// tasks.json: { "tasks": [ { "id": 1, "title": "...", "subtasks": [] } ] } Defensive patterns
Strategy: validation
Validate before calling
function assertValidTasksFile(tasksPath) {
let data;
try { data = JSON.parse(fs.readFileSync(tasksPath, 'utf8')); }
catch { throw new Error(`${tasksPath} is not valid JSON`); }
if (!data || !Array.isArray(data.tasks)) {
throw new Error(`${tasksPath} must contain a top-level tasks array`);
}
return data;
} Type guard
function hasTasksArray(data) {
return data !== null && typeof data === 'object' && Array.isArray(data.tasks);
} Try / catch
try {
await updateTaskById(5, prompt);
} catch (err) {
if (err.message.startsWith('No valid tasks found')) {
console.error('tasks.json is empty/corrupt; restore from git or re-run parse-prd');
} else throw err;
} Prevention
- Validate tasks.json after manual edits or merges (git hooks / JSON schema check)
- Avoid concurrent writers to tasks.json; use Task Master commands for mutations
- Commit tasks.json so corruption can be reverted
- Watch for merge-conflict markers before running update commands
When it happens
Trigger: tasks.json contains {} or truncated JSON after a failed write or merge conflict; a manually-edited file dropped the tasks key; readJSON recovers from invalid JSON and returns null/undefined.
Common situations: Merge conflicts left conflict markers in tasks.json; an interrupted process wrote a partial file; hand-editing mistakes; another tool rewriting tasks.json in an incompatible shape.
Related errors
- CONFIG_ERROR
- Invalid or missing tasks file at ${tasksPath}
- No valid tasks found in ${tasksPath}
- No valid tasks found in ${tasksPath}. The file may be corrup
- Could not determine project root directory
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/23eba0830222b941.
Report an issue: GitHub.