eyaltoledano/claude-task-master · warning
Warning: Could not load tasks for ContextGatherer
Error message
Warning: Could not load tasks for ContextGatherer: ${error.message} What it means
ContextGatherer._loadAllTasks reads the tasks file via readJSON and returns [] with this warning if reading or parsing fails. The gatherer then operates with no tasks, so context gathering yields empty results rather than crashing the host command.
Solutions
- Run `task-master init` or create the tasks file if it's missing
- Validate/repair JSON syntax in .taskmaster/tasks/tasks.json
- Confirm the tag exists (task-master tags) or omit the tag option
- Re-run from the actual project root
Example fix
// before
{ "tasks": [ { "id": 1, "title": , } ] }
// after
{ "tasks": [ { "id": 1, "title": "Valid entry" } ] } Defensive patterns
Strategy: fallback
Validate before calling
import { existsSync } from 'fs';
const tasksPath = '.taskmaster/tasks/tasks.json';
if (!existsSync(tasksPath)) {
console.error('tasks.json missing — run task-master init before using ContextGatherer');
} else {
try { JSON.parse(readFileSync(tasksPath, 'utf8')); } catch { console.error('tasks.json is not valid JSON'); }
} Type guard
function isLoadableTasksFile(data) {
return data !== null && typeof data === 'object' && Array.isArray(data.tasks);
} Try / catch
const gatherer = new ContextGatherer(projectRoot, tag);
const tasks = gatherer._loadAllTasks();
if (tasks.length === 0) {
console.warn('ContextGatherer loaded 0 tasks — check for the load warning above');
} Prevention
- Initialize the project (task-master init) before context-dependent commands
- Validate tasks.json after crashes or manual edits
- Confirm the tag exists with `task-master tags`
- Run commands from the project root, not a subdirectory with a different root
When it happens
Trigger: Constructing a ContextGatherer when readJSON(tasksPath, projectRoot, tag) throws — tasks.json missing, invalid JSON, wrong --tag referenced, or unreadable path.
Common situations: Running context-dependent commands before task-master init; corrupted tasks.json after a crash; passing a tag name that has no data; wrong project root cwd.
Related errors
- ${name}: ${error}
- Warning: Could not gather task context
- ANALYZE_REPORT_MISSING
- Assets directory not found. This is likely a packaging…
- Cannot create circular dependency: task
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/48083bfc7b2469af.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/modules/utils/contextGatherer.js:42
constructor(projectRoot, tag) {
this.projectRoot = projectRoot;
this.tasksPath = path.join(
projectRoot,
'.taskmaster',
'tasks',
'tasks.json'
);
this.tag = tag;
this.allTasks = this._loadAllTasks();
}
_loadAllTasks() {
try {
const data = readJSON(this.tasksPath, this.projectRoot, this.tag);
const tasks = data?.tasks || [];
return tasks;
} catch (error) {
console.warn(
`Warning: Could not load tasks for ContextGatherer: ${error.message}`
);
return [];
}
}
/**
* Count tokens in a text string using gpt-tokens
* @param {string} text - Text to count tokens for
* @returns {number} Token count
*/
countTokens(text) {
if (!text || typeof text !== 'string') {
return 0;
}
try {
return encode(text).length;
} catch (error) {View on GitHub (pinned to c0c98d367c)