{"record":{"id":"09061cbcfc578d3b","repo":"eyaltoledano/claude-task-master","slug":"parent-task-with-id-parentidnum-not-found","errorCode":null,"errorMessage":"Parent task with ID ${parentIdNum} not found","messagePattern":"Parent task with ID (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/add-subtask.js","lineNumber":40,"sourceCode":"\tcontext = {}\n) {\n\tconst { projectRoot, tag } = context;\n\ttry {\n\t\tlog('info', `Adding subtask to parent task ${parentId}...`);\n\n\t\t// Read the existing tasks with proper context\n\t\tconst data = readJSON(tasksPath, projectRoot, tag);\n\t\tif (!data || !data.tasks) {\n\t\t\tthrow new Error(`Invalid or missing tasks file at ${tasksPath}`);\n\t\t}\n\n\t\t// Convert parent ID to number\n\t\tconst parentIdNum = parseInt(parentId, 10);\n\n\t\t// Find the parent task\n\t\tconst parentTask = data.tasks.find((t) => t.id === parentIdNum);\n\t\tif (!parentTask) {\n\t\t\tthrow new Error(`Parent task with ID ${parentIdNum} not found`);\n\t\t}\n\n\t\t// Initialize subtasks array if it doesn't exist\n\t\tif (!parentTask.subtasks) {\n\t\t\tparentTask.subtasks = [];\n\t\t}\n\n\t\tlet newSubtask;\n\n\t\t// Case 1: Convert an existing task to a subtask\n\t\tif (existingTaskId !== null) {\n\t\t\tconst existingTaskIdNum = parseInt(existingTaskId, 10);\n\n\t\t\t// Find the existing task\n\t\t\tconst existingTaskIndex = data.tasks.findIndex(\n\t\t\t\t(t) => t.id === existingTaskIdNum\n\t\t\t);\n\t\t\tif (existingTaskIndex === -1) {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/add-subtask.js#L22-L58","documentation":"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.","triggerScenarios":"Calling addSubtask with a parentId that is not any existing task's id, e.g. beyond the highest task ID or a deleted task.","commonSituations":"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.","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."],"exampleFix":"// before\nawait addSubtask(tasksPath, '99', '5'); // no task 99\n// after\nawait addSubtask(tasksPath, '1', '5'); // task 1 exists","handlingStrategy":"validation","validationCode":"const data = readJSON(tasksPath, projectRoot, tag);\nconst parentIdNum = parseInt(parentId, 10);\nif (!data.tasks.some(t => t.id === parentIdNum)) {\n  throw new Error(`Parent task ${parentIdNum} not found in ${tasksPath}`);\n}","typeGuard":"function parentExists(data, id) {\n  const n = Number(id);\n  return Array.isArray(data?.tasks) && data.tasks.some(t => t.id === n);\n}","tryCatchPattern":"try {\n  await addSubtask(tasksPath, parentId, opts);\n} catch (err) {\n  if (err.message.includes('not found')) {\n    const missing = err.message.match(/ID (\\d+)/)?.[1];\n    console.error(`Create or locate task ${missing} first`);\n  } else throw err;\n}","preventionTips":["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"],"tags":["tasks","not-found","id-lookup"],"backgroundTag":"task-not-found","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}