eyaltoledano/claude-task-master · error
Could not determine project root directory
Error message
Could not determine project root directory
What it means
expandAllTasks() needs a project root to locate .taskmaster/config.json and the tasks file. It uses the provided projectRoot from context or falls back to findProjectRoot(); if neither yields a path, it cannot resolve any file paths and throws.
Source
Thrown at scripts/modules/task-manager/expand-all-tasks.js:49
numSubtasks, // Keep this signature, expandTask handles defaults
useResearch = false,
additionalContext = '',
force = false, // Keep force here for the filter logic
context = {},
outputFormat = 'text' // Assume text default for CLI
) {
const {
session,
mcpLog,
projectRoot: providedProjectRoot,
tag,
complexityReportPath
} = context;
const isMCPCall = !!mcpLog; // Determine if called from MCP
const projectRoot = providedProjectRoot || findProjectRoot();
if (!projectRoot) {
throw new Error('Could not determine project root directory');
}
// Use mcpLog if available, otherwise use the default console log wrapper respecting silent mode
const logger =
mcpLog ||
(outputFormat === 'json'
? {
// Basic logger for JSON output mode
info: (msg) => {},
warn: (msg) => {},
error: (msg) => console.error(`ERROR: ${msg}`), // Still log errors
debug: (msg) => {}
}
: {
// CLI logger respecting silent mode
info: (msg) => !isSilentMode() && log('info', msg),
warn: (msg) => !isSilentMode() && log('warn', msg),
error: (msg) => !isSilentMode() && log('error', msg),View on GitHub (pinned to c0c98d367c)
Solutions
- Run the command from your project root (the directory containing .taskmaster) or pass an explicit projectRoot.
- Re-run `task-master init` or restore the missing .taskmaster directory.
- In programmatic/MCP calls, always supply context.projectRoot explicitly.
Example fix
// before
await expandAllTasks({ tasksPath: undefined }); // cwd has no .taskmaster
// after
await expandAllTasks({ projectRoot: '/path/to/my-project', tasksPath: undefined }); Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
const path = require('path');
function findRoot(start = process.cwd()) {
let dir = start;
while (dir !== path.parse(dir).root) {
if (fs.existsSync(path.join(dir, '.taskmaster'))) return dir;
dir = path.dirname(dir);
}
return null;
}
const projectRoot = findRoot();
if (!projectRoot) throw new Error('Run from a directory containing .taskmaster'); Type guard
function hasProjectRoot(ctx) {
return !!ctx && (typeof ctx.projectRoot === 'string' || findProjectRoot() !== null);
} Try / catch
try {
await expandAllTasks(context);
} catch (err) {
if (err.message.includes('Could not determine project root')) {
console.error('Run from your project root or pass projectRoot explicitly.');
} else throw err;
} Prevention
- Always execute task-master commands from the project root.
- Pass projectRoot explicitly in scripts, tests, and MCP calls.
- Ensure the .taskmaster directory exists (task-master init).
When it happens
Trigger: Calling expandAllTasks() programmatically without context.projectRoot while findProjectRoot() returns null — e.g. the current working directory is outside any directory containing .taskmaster (no .taskmaster folder up the tree).
Common situations: Running the CLI from a random directory instead of the project root; tests/scripts executing from a temp dir; a renamed or deleted .taskmaster directory; MCP call where projectRoot parameter was omitted.
Related errors
- Could not determine project root directory
- Could not determine project root directory
- Export API endpoint not configured. Please set TM_PUBLIC_BAS
- Required API key ${envVarName} for provider '${providerName}
- Could not determine project root directory
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/a090ef268088c18b.
Report an issue: GitHub.