eyaltoledano/claude-task-master · error
Parent task with ID ${parentIdNum} not found
Error message
Parent task with ID ${parentIdNum} not found What it means
addSubtask converts the parentId to a number and searches the tasks array for a matching task; this error is thrown when no top-level task has that ID. The parent must exist before a subtask can be attached to it.
Source
Thrown at scripts/modules/task-manager/add-subtask.js:40
context = {}
) {
const { projectRoot, tag } = context;
try {
log('info', `Adding subtask to parent task ${parentId}...`);
// Read the existing tasks with proper context
const data = readJSON(tasksPath, projectRoot, tag);
if (!data || !data.tasks) {
throw new Error(`Invalid or missing tasks file at ${tasksPath}`);
}
// Convert parent ID to number
const parentIdNum = parseInt(parentId, 10);
// Find the parent task
const parentTask = data.tasks.find((t) => t.id === parentIdNum);
if (!parentTask) {
throw new Error(`Parent task with ID ${parentIdNum} not found`);
}
// Initialize subtasks array if it doesn't exist
if (!parentTask.subtasks) {
parentTask.subtasks = [];
}
let newSubtask;
// Case 1: Convert an existing task to a subtask
if (existingTaskId !== null) {
const existingTaskIdNum = parseInt(existingTaskId, 10);
// Find the existing task
const existingTaskIndex = data.tasks.findIndex(
(t) => t.id === existingTaskIdNum
);
if (existingTaskIndex === -1) {View on GitHub (pinned to c0c98d367c)
Solutions
- Run task-master list (or read the tasks file) to confirm the parent task ID exists.
- Use the ID of an existing top-level task as parentId.
- If the task was deleted, recreate it or pick another parent.
- Check you are operating in the correct tag/context whose task list contains the parent.
Example fix
// before await addSubtask(tasksPath, '99', '5'); // no task 99 // after await addSubtask(tasksPath, '1', '5'); // task 1 exists
Defensive patterns
Strategy: validation
Validate before calling
const data = readJSON(tasksPath, projectRoot, tag);
const parentIdNum = parseInt(parentId, 10);
if (!data.tasks.some(t => t.id === parentIdNum)) {
throw new Error(`Parent task ${parentIdNum} not found in ${tasksPath}`);
} Type guard
function parentExists(data, id) {
const n = Number(id);
return Array.isArray(data?.tasks) && data.tasks.some(t => t.id === n);
} Try / catch
try {
await addSubtask(tasksPath, parentId, opts);
} catch (err) {
if (err.message.includes('not found')) {
const missing = err.message.match(/ID (\d+)/)?.[1];
console.error(`Create or locate task ${missing} first`);
} else throw err;
} Prevention
- List tasks before scripting subtask operations to capture valid IDs
- Never reuse IDs from a different tag or stale output
- Guard against composite/subtask IDs where top-level IDs are required
- Re-fetch task IDs after regeneration, since they can change
When it happens
Trigger: Calling addSubtask with a parentId that is not any existing task's id, e.g. beyond the highest task ID or a deleted task.
Common situations: Typos in the parent ID, referencing a task from a different tag's task list, or using a subtask composite ID ('1.2') where only a top-level task ID is valid.
Related errors
- Task with ID ${existingTaskIdNum} not found
- Tag "${targetTag}" not found.
- Invalid iterations: ${iterations}. Must be a positive intege
- Invalid format: ${options.format}. Valid formats are: text,
- NOT_FOUND
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/09061cbcfc578d3b.
Report an issue: GitHub.