eyaltoledano/claude-task-master · error

Task with ID ${existingTaskIdNum} not found

Error message

Task with ID ${existingTaskIdNum} not found

What it means

When converting an existing task into a subtask, addSubtask looks up existingTaskId in the tasks array; this error is thrown when the given ID does not match any top-level task. The conversion cannot proceed without the source task record.

Source

Thrown at scripts/modules/task-manager/add-subtask.js:59

		}

		// 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) {
				throw new Error(`Task with ID ${existingTaskIdNum} not found`);
			}

			const existingTask = data.tasks[existingTaskIndex];

			// Check if task is already a subtask
			if (existingTask.parentTaskId) {
				throw new Error(
					`Task ${existingTaskIdNum} is already a subtask of task ${existingTask.parentTaskId}`
				);
			}

			// Check for circular dependency
			if (existingTaskIdNum === parentIdNum) {
				throw new Error(`Cannot make a task a subtask of itself`);
			}

			// Check if parent task is a subtask of the task we're converting
			// This would create a circular dependency

View on GitHub (pinned to c0c98d367c)

Solutions

  1. List current tasks to confirm the ID of the task you want to convert.
  2. Pass a valid top-level task ID as existingTaskId.
  3. If the task is actually a subtask already, reference its top-level ID or handle it via update-subtask instead.
  4. Verify you are in the correct tag/context.

Example fix

// before
await addSubtask('1', '4.2'); // '4.2' is not a top-level task
// after
await addSubtask('1', '5'); // top-level task 5 exists
Defensive patterns

Strategy: type-guard

Validate before calling

const data = readJSON(tasksPath, projectRoot, tag);
const idNum = parseInt(existingTaskId, 10);
if (!data.tasks.some(t => t.id === idNum)) {
  throw new Error(`Cannot convert: task ${idNum} does not exist`);
}

Type guard

function isTopLevelTask(data, id) {
  const n = Number(id);
  return data?.tasks?.some(t => t.id === n && !t.parentTaskId && !String(t.id).includes('.'));
}

Try / catch

try {
  await addSubtask(tasksPath, parentId, existingTaskId);
} catch (err) {
  if (/Task with ID .* not found/.test(err.message)) {
    console.error('Refresh task list and retry with a valid top-level ID');
  } else throw err;
}

Prevention

When it happens

Trigger: Calling addSubtask(parentId, existingTaskId) where existingTaskId refers to a nonexistent, deleted, or out-of-range task ID.

Common situations: Passing a subtask ID ('1.2') instead of a top-level ID, stale IDs after renumbering or regeneration, or referencing tasks in a different tag.

Related errors


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