{"record":{"id":"01c698b0dbe43e3a","repo":"eyaltoledano/claude-task-master","slug":"failed-to-prepare-execution-command-error-insta","errorCode":null,"errorMessage":"Failed to prepare execution command: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to prepare execution command: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/tm-core/src/modules/tasks/services/task-execution-service.ts","lineNumber":250,"sourceCode":"\t/**\n\t * Prepare execution command for the CLI to run\n\t */\n\tprivate async prepareExecutionCommand(\n\t\ttask: Task,\n\t\tsubtask?: any\n\t): Promise<{ executable: string; args: string[]; cwd: string } | null> {\n\t\ttry {\n\t\t\t// Format the task into a prompt\n\t\t\tconst taskPrompt = this.formatTaskPrompt(task, subtask);\n\n\t\t\t// Use claude command - could be extended for other executors\n\t\t\tconst executable = 'claude';\n\t\t\tconst args = [taskPrompt];\n\t\t\tconst cwd = process.cwd(); // or could get from project root\n\n\t\t\treturn { executable, args, cwd };\n\t\t} catch (error) {\n\t\t\tconsole.warn(\n\t\t\t\t`Failed to prepare execution command: ${error instanceof Error ? error.message : String(error)}`\n\t\t\t);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Format task into a prompt suitable for execution\n\t */\n\tprivate formatTaskPrompt(task: Task, subtask?: any): string {\n\t\tconst workItem = subtask || task;\n\t\tconst itemType = subtask ? 'Subtask' : 'Task';\n\t\tconst itemId = subtask ? `${task.id}.${subtask.id}` : task.id;\n\n\t\tlet prompt = `${itemType} #${itemId}: ${workItem.title}\\n\\n`;\n\n\t\tif (workItem.description) {\n\t\t\tprompt += `Description:\\n${workItem.description}\\n\\n`;","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/tasks/services/task-execution-service.ts#L232-L268","documentation":"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.","triggerScenarios":"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.","commonSituations":"Claude Code CLI not the intended runner; malformed task data yielding empty prompts; running from a deleted working directory; env missing required prompt variables.","solutions":["Verify the task and its dependencies resolve and the prompt builds non-empty","Run from a valid project root (process.cwd() exists and is writable)","Check the task data for missing fields used in prompt generation","Inspect the logged error detail for the underlying exception"],"exampleFix":"// before\n$ cd /gone/dir && task-master start 1\n// after\n$ cd /valid/project && task-master start 1","handlingStrategy":"fallback","validationCode":"import { existsSync } from 'fs';\nif (!existsSync(process.cwd())) throw new Error('Invalid working directory for execution');\nconst task = await tmCore.tasks.get(taskId).catch(() => null);\nif (!task) throw new Error('Task not found; cannot build prompt');","typeGuard":"function isExecutableCommand(cmd) {\n  return cmd !== null && typeof cmd.executable === 'string' && Array.isArray(cmd.args) && cmd.args.length > 0;\n}","tryCatchPattern":"const command = await executionService.prepareExecutionCommand(taskId);\nif (command === null) {\n  console.warn('Execution skipped: command preparation failed — check the logged error');\n  return;\n}","preventionTips":["Run commands from a valid, existing project root","Confirm the task data is complete enough to build a prompt","Verify the 'claude' executable is on PATH if the runner depends on it","Inspect the logged underlying error before retrying"],"tags":["execution","command-preparation","claude-cli","fallback"],"backgroundTag":"command-preparation-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}