{"record":{"id":"2ac20d2dc94e5bc4","repo":"eyaltoledano/claude-task-master","slug":"grok-cli-failed-with-exit-code-result-exitcode","errorCode":null,"errorMessage":"Grok CLI failed with exit code ${result.exitCode}: ${result.stderr || 'Unknown error'}","messagePattern":"Grok CLI failed with exit code (.+?): (.+?)","errorType":"exception","errorClass":"APICallError","httpStatus":null,"severity":"error","filePath":"packages/ai-sdk-provider-grok-cli/src/grok-cli-language-model.ts","lineNumber":315,"sourceCode":"\t\tif (this.settings.workingDirectory) {\n\t\t\targs.push('--directory', this.settings.workingDirectory);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await this.executeGrokCli(args, { apiKey });\n\n\t\t\tif (result.exitCode !== 0) {\n\t\t\t\t// Handle authentication errors\n\t\t\t\tif (\n\t\t\t\t\tresult.stderr.toLowerCase().includes('unauthorized') ||\n\t\t\t\t\tresult.stderr.toLowerCase().includes('authentication')\n\t\t\t\t) {\n\t\t\t\t\tthrow createAuthenticationError({\n\t\t\t\t\t\tmessage: `Grok CLI authentication failed: ${result.stderr}`\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tthrow createAPICallError({\n\t\t\t\t\tmessage: `Grok CLI failed with exit code ${result.exitCode}: ${result.stderr || 'Unknown error'}`,\n\t\t\t\t\texitCode: result.exitCode,\n\t\t\t\t\tstderr: result.stderr,\n\t\t\t\t\tstdout: result.stdout,\n\t\t\t\t\tpromptExcerpt: prompt.substring(0, 200),\n\t\t\t\t\tisRetryable: false\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Parse response\n\t\t\tconst response = convertFromGrokCliResponse(result.stdout);\n\t\t\tlet text = response.text || '';\n\n\t\t\t// Extract JSON if in object-json mode\n\t\t\tconst isObjectJson = (\n\t\t\t\to: unknown\n\t\t\t): o is { mode: { type: 'object-json' } } =>\n\t\t\t\t!!o &&","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/ai-sdk-provider-grok-cli/src/grok-cli-language-model.ts#L297-L333","documentation":"This is the generic failure path for a nonzero Grok CLI exit that is NOT an authentication problem. doGenerate throws an API-call error including the exit code, stderr, stdout, and a 200-char prompt excerpt, marked non-retryable. It means the CLI itself ran and failed — bad request, quota, network error inside the CLI, or invalid arguments.","triggerScenarios":"doGenerate spawns the Grok CLI, which exits nonzero with stderr not containing 'unauthorized'/'authentication' — e.g. rate limits, malformed prompt/flags, CLI crash, network failure within the CLI.","commonSituations":"Exhausted Grok rate limits or quota; passing prompts the CLI rejects; outdated CLI version incompatible with current API; network/proxy restrictions in corporate environments; prompt content triggering provider-side refusals.","solutions":["Read stderr/exitCode in the error payload to identify the root cause (quota, bad request, crash).","Update the CLI: npm update -g @vibe-kit/grok-cli and retry, since older versions break against API changes.","Check rate limits/quota on your Grok account and back off before retrying.","Reproduce manually: run the same prompt through the `grok` CLI directly to see the raw error.","Verify network/proxy configuration allows the CLI to reach the Grok API."],"exampleFix":"// before (shell)\nnpm list -g @vibe-kit/grok-cli   // outdated version, exit code 1\n// after (shell)\nnpm update -g @vibe-kit/grok-cli && node app.js","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isGrokApiCallError(e) {\n  return e instanceof Error && /Grok CLI failed with exit code/.test(e.message);\n}","tryCatchPattern":"try {\n  const result = await model.doGenerate({ prompt });\n} catch (e) {\n  if (isGrokApiCallError(e)) {\n    console.error(`Grok CLI exited ${e.exitCode ?? '?'}: ${e.stderr ?? e.message}`);\n    // inspect stderr: quota -> backoff; bad request -> fix prompt/CLI version\n  } else throw e;\n}","preventionTips":["Keep @vibe-kit/grok-cli updated; old versions break against API changes.","Implement exponential backoff for rate-limit-shaped stderr messages only.","Test prompts directly against the `grok` CLI before wiring them into automation.","Monitor stderr in logs to detect quota exhaustion early."],"tags":["grok-cli","subprocess","nonzero-exit","api-call"],"backgroundTag":"cli-command-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}