fix(claude-code): prevent "Right-hand side of instanceof is not an object" when SDK missing; improve CLI stability (#1146)

* fix: handle missing @anthropic-ai/claude-code SDK gracefully

Add defensive checks to prevent "Right-hand side of 'instanceof' is not an object" errors when the optional Claude Code SDK is not installed.

Changes:
- Check if AbortError exists before using instanceof
- Check if query function exists before calling it
- Provide clear error messages when SDK is missing

This fixes the issue reported by users in v0.24.0 and v0.25.0 where Task Master would crash with instanceof errors when using the claude-code provider without the SDK installed.

* chore: bump @anthropic-ai/claude-code to ^1.0.88 and regenerate lockfile
This commit is contained in:
Ben Vargas
2025-08-22 05:34:54 -06:00
committed by Ralph Khreish
parent 781b8ef2af
commit 89335578ff
4 changed files with 30 additions and 13 deletions

View File

@@ -169,6 +169,11 @@ export class ClaudeCodeLanguageModel {
const warnings = this.generateUnsupportedWarnings(options);
try {
if (!query) {
throw new Error(
"Claude Code SDK is not installed. Please install '@anthropic-ai/claude-code' to use the claude-code provider."
);
}
const response = query({
prompt: messagesPrompt,
options: queryOptions
@@ -227,7 +232,7 @@ export class ClaudeCodeLanguageModel {
finishReason = 'truncated';
// Skip re-throwing: fall through so the caller receives usable data
} else {
if (error instanceof AbortError) {
if (AbortError && error instanceof AbortError) {
throw options.abortSignal?.aborted
? options.abortSignal.reason
: error;
@@ -335,6 +340,11 @@ export class ClaudeCodeLanguageModel {
const stream = new ReadableStream({
start: async (controller) => {
try {
if (!query) {
throw new Error(
"Claude Code SDK is not installed. Please install '@anthropic-ai/claude-code' to use the claude-code provider."
);
}
const response = query({
prompt: messagesPrompt,
options: queryOptions
@@ -478,7 +488,7 @@ export class ClaudeCodeLanguageModel {
} catch (error) {
let errorToEmit;
if (error instanceof AbortError) {
if (AbortError && error instanceof AbortError) {
errorToEmit = options.abortSignal?.aborted
? options.abortSignal.reason
: error;