eyaltoledano/claude-task-master · warning

Warning: Could not gather task context: ${error.message}

Error message

Warning: Could not gather task context: ${error.message}

What it means

ContextGatherer._gatherTaskContext collects context items for a task and formats them; on any error it warns with this message and returns {context: null, breakdown: []} so callers degrade gracefully instead of failing. This is a logged message, not a thrown error.

Source

Thrown at scripts/modules/utils/contextGatherer.js:564

				if (formattedItem && itemInfo) {
					contextItems.push(formattedItem);
					if (includeTokenCounts) {
						breakdown.push(itemInfo);
					}
				}
			}

			if (contextItems.length === 0) {
				return { context: null, breakdown: [] };
			}

			const finalContext = this._formatTaskContextSection(contextItems, format);
			return {
				context: finalContext,
				breakdown: includeTokenCounts ? breakdown : []
			};
		} catch (error) {
			console.warn(`Warning: Could not gather task context: ${error.message}`);
			return { context: null, breakdown: [] };
		}
	}

	/**
	 * Format a task for context inclusion
	 * @param {Object} task - Task object
	 * @param {string} format - Output format
	 * @returns {string} Formatted task context
	 */
	_formatTaskForContext(task, format) {
		const sections = [];

		sections.push(`**Task ${task.id}: ${task.title}**`);
		sections.push(`Description: ${task.description}`);
		sections.push(`Status: ${task.status || 'pending'}`);
		sections.push(`Priority: ${task.priority || 'medium'}`);

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Verify the target task ID exists and its dependencies resolve in tasks.json
  2. Repair malformed task/dependency data flagged in the underlying error
  3. Re-run after fixing tasks.json; treat null context as a signal the task data needs attention
  4. Check file read permissions on the task storage

Example fix

// before
{ "id": 3, "dependencies": [99] }  // dangling dep
// after
{ "id": 3, "dependencies": [1] }
Defensive patterns

Strategy: fallback

Validate before calling

const data = JSON.parse(readFileSync('.taskmaster/tasks/tasks.json', 'utf8'));
const task = data.tasks.find(t => t.id === taskId);
if (!task) console.error(`Task ${taskId} not found — context will be null`);
const depIds = (task?.dependencies ?? []).map(d => Number(d));
const missing = depIds.filter(id => !data.tasks.some(t => t.id === id));
if (missing.length) console.error(`Dangling dependencies: ${missing}`);

Type guard

function hasGatherableContext(result) {
  return result !== null && typeof result.context === 'string' && result.context.length > 0;
}

Try / catch

const { context } = await gatherer.gatherTaskContext(taskId);
if (context === null) {
  console.warn(`No context gathered for task ${taskId} — fix task data and retry`);
}

Prevention

When it happens

Trigger: Calling _gatherTaskContext (via taskContextResult) when item gathering or formatting throws — underlying task files unreadable, unexpected task structure (missing fields), or formatter errors on malformed dependency data.

Common situations: Gathering context for a task ID that doesn't exist; tasks.json with dangling dependency IDs; schema drift between task data versions; token-counting failures when includeTokenCounts is enabled.

Related errors


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