eyaltoledano/claude-task-master · error

Could not determine project root directory

Error message

Could not determine project root directory

What it means

updateTasks resolves the project root (explicit argument or findProjectRoot()) before reading tasks.json. If neither yields a root, it throws this error because all subsequent file operations depend on it.

Source

Thrown at scripts/modules/task-manager/update-tasks.js:71

	// Flag to easily check which logger type we have
	const isMCP = !!mcpLog;

	if (isMCP)
		logFn.info(`updateTasks called with context: session=${!!session}`);
	else logFn('info', `updateTasks called`); // CLI log

	try {
		if (isMCP) logFn.info(`Updating tasks from ID ${fromId}`);
		else
			logFn(
				'info',
				`Updating tasks from ID ${fromId} with prompt: "${prompt}"`
			);

		// Determine project root
		const projectRoot = providedProjectRoot || findProjectRoot();
		if (!projectRoot) {
			throw new Error('Could not determine project root directory');
		}

		// --- Task Loading/Filtering (Updated to pass projectRoot and tag) ---
		const data = readJSON(tasksPath, projectRoot, tag);
		if (!data || !data.tasks)
			throw new Error(`No valid tasks found in ${tasksPath}`);
		const tasksToUpdate = data.tasks.filter(
			(task) => task.id >= fromId && task.status !== 'done'
		);
		if (tasksToUpdate.length === 0) {
			if (isMCP)
				logFn.info(`No tasks to update (ID >= ${fromId} and not 'done').`);
			else
				logFn('info', `No tasks to update (ID >= ${fromId} and not 'done').`);
			if (outputFormat === 'text') console.log(/* yellow message */);
			return; // Nothing to do
		}
		// --- End Task Loading/Filtering ---

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Run 'task-master init' in the project directory (or cd into the initialized project)
  2. Pass an explicit projectRoot option to updateTasks when invoking programmatically
  3. Verify findProjectRoot's detection marker exists (e.g. .taskmaster/ folder) in the current directory or an ancestor

Example fix

// before
await updateTasks(prompt, fromId);
// after
await updateTasks(prompt, fromId, { projectRoot: '/path/to/project' });
Defensive patterns

Strategy: validation

Validate before calling

import { findProjectRoot } from '.../utils.js';
const projectRoot = findProjectRoot();
if (!projectRoot) throw new Error('Not inside a task-master project; run task-master init');

Try / catch

try {
  await updateTasks(...);
} catch (e) {
  if (e.message === 'Could not determine project root directory') {
    // cd into project or init task-master
  } else throw e;
}

Prevention

When it happens

Trigger: Calling updateTasks via API/MCP with providedProjectRoot undefined while findProjectRoot() cannot locate a .taskmaster directory (or any ancestor marker) up the directory tree.

Common situations: Running the tool outside a taskmaster-initialized project, calling the programmatic API without passing projectRoot from a non-CLI host process, or working from a directory whose ancestors lack .taskmaster/config markers.

Related errors


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