eyaltoledano/claude-task-master · error
Could not determine project root directory
Error message
Could not determine project root directory
What it means
updateTaskById() resolves the project root from the providedProjectRoot argument or by calling findProjectRoot() (which walks up looking for .taskmaster / project markers). This error is thrown when neither yields a root, meaning the code cannot locate the Task Master project directory to read tasks.json and configuration.
Source
Thrown at scripts/modules/task-manager/update-task-by-id.js:92
// Note: taskId can be a number (1), string with dot (1.2), or display ID (HAM-123)
// So we don't validate it as strictly anymore
if (taskId === null || taskId === undefined || String(taskId).trim() === '')
throw new Error('Task ID cannot be empty.');
// Allow metadata-only updates (prompt can be empty if metadata is provided)
if (
(!prompt || typeof prompt !== 'string' || prompt.trim() === '') &&
!metadata
) {
throw new Error(
'Prompt cannot be empty unless metadata is provided for update.'
);
}
// Determine project root first (needed for API key checks)
const projectRoot = providedProjectRoot || findProjectRoot();
if (!projectRoot) {
throw new Error('Could not determine project root directory');
}
if (useResearch && !isApiKeySet('perplexity', session)) {
report(
'warn',
'Perplexity research requested but API key not set. Falling back.'
);
if (outputFormat === 'text')
console.log(
chalk.yellow('Perplexity AI not available. Falling back to main AI.')
);
useResearch = false;
}
// --- BRIDGE: Try remote update first (API storage) ---
const remoteResult = await tryUpdateViaRemote({
taskId,
prompt,View on GitHub (pinned to c0c98d367c)
Solutions
- Run the command from within the Task Master project directory (where .taskmaster/ or tasks.json lives)
- Pass the correct project root explicitly via providedProjectRoot / --project-root
- Reinitialize or restore the project marker (task-master init) if .taskmaster was removed
- Check for typos in the provided project root path
Example fix
// before
await updateTaskById(5, prompt); // cwd has no project root
// after
await updateTaskById(5, prompt, { projectRoot: '/path/to/my-taskmaster-project' }); Defensive patterns
Strategy: validation
Validate before calling
import fs from 'fs';
function resolveProjectRoot(explicit) {
const root = explicit || findProjectRoot();
if (!root || !fs.existsSync(root)) {
throw new Error('Run from a Task Master project or pass --project-root');
}
return root;
} Type guard
function hasProjectRoot(root) {
return typeof root === 'string' && root.length > 0 && fs.existsSync(root);
} Try / catch
try {
await updateTaskById(5, prompt);
} catch (err) {
if (err.message === 'Could not determine project root directory') {
console.error('cd into the project or pass projectRoot explicitly');
} else throw err;
} Prevention
- Run commands from the directory containing .taskmaster/
- Pass projectRoot explicitly in scripts and CI rather than relying on cwd
- Keep the .taskmaster marker directory intact in the repo root
- In monorepos, resolve the sub-project root before invoking Task Master APIs
When it happens
Trigger: Calling updateTaskById from a directory outside any Task Master project (no .taskmaster folder up the tree) without passing providedProjectRoot; running from a temp or home directory; passing an invalid providedProjectRoot that is falsy after normalization.
Common situations: Executing the CLI from the wrong cwd in scripts/CI; monorepo layouts where the marker folder is deeper than expected; deleting or renaming the .taskmaster directory; Node scripts run with a different working directory than expected.
Related errors
- Tasks file not found: ${tasksPath}
- Could not determine project root directory
- Could not determine project root directory
- Could not determine project root directory
- No valid tasks found in ${tasksPath}.
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/cc21b38b26028ba5.
Report an issue: GitHub.