eyaltoledano/claude-task-master · warning

Failed to prepare execution command: ${error instanceof Erro

Error message

Failed to prepare execution command: ${error instanceof Error ? error.message : String(error)}

What it means

TaskExecutionService.prepareExecutionCommand builds the {executable,args,cwd} for spawning the 'claude' CLI. Any error during prompt/argument preparation is caught, logged with this warning, and null is returned so startTask can skip execution gracefully. This is a logged message, not a thrown error.

Source

Thrown at packages/tm-core/src/modules/tasks/services/task-execution-service.ts:250

	/**
	 * Prepare execution command for the CLI to run
	 */
	private async prepareExecutionCommand(
		task: Task,
		subtask?: any
	): Promise<{ executable: string; args: string[]; cwd: string } | null> {
		try {
			// Format the task into a prompt
			const taskPrompt = this.formatTaskPrompt(task, subtask);

			// Use claude command - could be extended for other executors
			const executable = 'claude';
			const args = [taskPrompt];
			const cwd = process.cwd(); // or could get from project root

			return { executable, args, cwd };
		} catch (error) {
			console.warn(
				`Failed to prepare execution command: ${error instanceof Error ? error.message : String(error)}`
			);
			return null;
		}
	}

	/**
	 * Format task into a prompt suitable for execution
	 */
	private formatTaskPrompt(task: Task, subtask?: any): string {
		const workItem = subtask || task;
		const itemType = subtask ? 'Subtask' : 'Task';
		const itemId = subtask ? `${task.id}.${subtask.id}` : task.id;

		let prompt = `${itemType} #${itemId}: ${workItem.title}\n\n`;

		if (workItem.description) {
			prompt += `Description:\n${workItem.description}\n\n`;

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Verify the task and its dependencies resolve and the prompt builds non-empty
  2. Run from a valid project root (process.cwd() exists and is writable)
  3. Check the task data for missing fields used in prompt generation
  4. Inspect the logged error detail for the underlying exception

Example fix

// before
$ cd /gone/dir && task-master start 1
// after
$ cd /valid/project && task-master start 1
Defensive patterns

Strategy: fallback

Validate before calling

import { existsSync } from 'fs';
if (!existsSync(process.cwd())) throw new Error('Invalid working directory for execution');
const task = await tmCore.tasks.get(taskId).catch(() => null);
if (!task) throw new Error('Task not found; cannot build prompt');

Type guard

function isExecutableCommand(cmd) {
  return cmd !== null && typeof cmd.executable === 'string' && Array.isArray(cmd.args) && cmd.args.length > 0;
}

Try / catch

const command = await executionService.prepareExecutionCommand(taskId);
if (command === null) {
  console.warn('Execution skipped: command preparation failed — check the logged error');
  return;
}

Prevention

When it happens

Trigger: Calling prepareExecutionCommand (via startTask) when assembling the task prompt or command throws — e.g. task/subtask lookup fails, prompt templating hits missing fields, or process.cwd() is inaccessible.

Common situations: Claude Code CLI not the intended runner; malformed task data yielding empty prompts; running from a deleted working directory; env missing required prompt variables.

Related errors


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