claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] "Error executing Claude query: Claude Code process exited with code 1" when executing using Typescript Claude Code SDK in VSCode Typescript debug terminal

Open monarchwadia opened this issue 5 months ago • 16 comments

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • Claude CLI version: 1.0.61 (Claude Code)
  • Operating System: Using Devcontainer mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm which uses Debian GNU/Linux 12 (bookworm)
  • Terminal: bash

Bug Description

Claude Code SDK runs just fine when running in a regular, non-debug shell with no debugger attached (kudos on job well done)

However, when running in Typescript debug console, it fails with Error executing Claude query: Claude Code process exited with code 1" when executing using Typescript Claude Code SDK and a non-useful stack trace.

Expected behaviour

Should run when debugging in VSCode

If it fails, should show useful error

Actual behaviour

Does not run when debugging in VSCode

When it fails, does not show useful error

Additional Context

    # i run using `pnpm dev`
    "dev": "pnpm dev:client & pnpm dev:server & wait",
    "dev:client": "vite serve src/client --host",
    "dev:server": "tsx --env-file=.env --watch src/server/server.ts",
Image Image
# Start of VSCode launch, right after I hit the green "Start" button on the topleft of my VSCode GUI

node ➜ /workspaces/meadowmerge/prototype (main) $  cd /workspaces/meadowmerge/prototype ; /usr/bin/env 'NODE_OPTIONS= --require /vscode/vscode-server/bin/linux-x64/c306e94f98122556ca081f527b466015e1bc37b0/extensions/ms-vscode.js-debug/src/bootloader.js  --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS=:::{"inspectorIpc":"/tmp/node-cdp.84878-dabaa516-302.sock","deferredMode":false,"waitForDebugger":"","execPath":"/usr/local/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","mandatePortTracking":true,"fileCallback":"/tmp/node-debug-callback-6637f01801d08b61"}' /usr/local/share/npm-global/bin/pnpm dev 
Debugger attached.
Debugger attached.

> @meadowmerge/[email protected] dev /workspaces/meadowmerge/prototype
> pnpm dev:client & pnpm dev:server & wait

Debugger attached.
Debugger attached.

> @meadowmerge/[email protected] dev:server /workspaces/meadowmerge/prototype
> tsx --env-file=.env --watch src/server/server.ts


> @meadowmerge/[email protected] dev:client /workspaces/meadowmerge/prototype
> vite serve src/client --host

Debugger attached.
Debugger attached.
Debugger attached.

  VITE v7.0.6  ready in 1132 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: http://172.17.0.2:5173/
Server is running on http://localhost:3001
ANTHROPIC_API_KEY:  <REDACTED, is present>

Current working directory: /tmp/git-clone-nPm5IW
Claude query response received.
Debugger attached.

Waiting for the debugger to disconnect...

Error executing Claude query: Claude Code process exited with code 1
Error: Claude Code process exited with code 1
    at ChildProcess.<anonymous> (/workspaces/meadowmerge/node_modules/.pnpm/@[email protected]/node_modules/@anthropic-ai/claude-code/sdk.mjs:224:25)
    at ChildProcess.emit (node:events:518:28)
    at maybeClose (node:internal/child_process:1101:16)
    at Socket.<anonymous> (node:internal/child_process:456:11)
    at Socket.emit (node:events:518:28)
    at Pipe.<anonymous> (node:net:351:12)
    at Pipe.callbackTrampoline (node:internal/async_hooks:130:17)
Error generating AI accomplishments report: Error: Claude Code process exited with code 1
    at ChildProcess.<anonymous> (/workspaces/meadowmerge/node_modules/.pnpm/@[email protected]/node_modules/@anthropic-ai/claude-code/sdk.mjs:224:25)
    at ChildProcess.emit (node:events:518:28)
    at maybeClose (node:internal/child_process:1101:16)
    at Socket.<anonymous> (node:internal/child_process:456:11)
    at Socket.emit (node:events:518:28)
    at Pipe.<anonymous> (node:net:351:12)
    at Pipe.callbackTrampoline (node:internal/async_hooks:130:17)
/*! 🌼 daisyUI 5.0.47 */

monarchwadia avatar Jul 28 '25 23:07 monarchwadia

+1

anonymoose avatar Jul 29 '25 00:07 anonymoose

+1

maximdolphin avatar Aug 12 '25 14:08 maximdolphin

+1

jordancasetgcs avatar Aug 12 '25 15:08 jordancasetgcs

+1

deepakkaushik2016 avatar Aug 12 '25 15:08 deepakkaushik2016

Summarized by claude itself:

Fix for VSCode Debugger Issue with Claude Code SDK

Problem

When running the Claude Code SDK in VSCode's debug mode, the subprocess crashes with exit code 1. This is caused by VSCode's auto-attach feature injecting debugger environment variables that interfere with the Claude subprocess.

Root Cause

VSCode injects these environment variables:

  • NODE_OPTIONS - Contains debugger bootstrap code
  • VSCODE_INSPECTOR_OPTIONS - Contains debugger configuration

These are inherited by the Claude subprocess, causing it to try to attach to the debugger and crash.

Solution

When using the Claude Code SDK, clean the environment variables before passing them to the query function:

import { query, Options } from '@anthropic-ai/claude-code';

// Clean environment variables to prevent VSCode debugger interference
const cleanEnv = { ...process.env };
delete cleanEnv.NODE_OPTIONS;
delete cleanEnv.VSCODE_INSPECTOR_OPTIONS;

const options: Options = {
  cwd: '/your/working/directory',
  permissionMode: 'bypassPermissions',
  // Use cleaned environment
  env: cleanEnv,
};

// Now the SDK will work even when debugging in VSCode
const iterator = query({ prompt: 'your prompt', options });

Why This Works

  • The Claude subprocess starts without debugger attachment
  • Runs in a clean environment similar to production
  • Your main process can still be debugged normally
  • The SDK gets all required environment variables (minus debugger ones)

activadee avatar Aug 23 '25 13:08 activadee

Thanks. To be honest, this is very common for development flows, so it should be handled by the SDK, not by client code. At the very least, SDK should throw a useful validation error on startup, with clear steps or a link to docs for how to handle.

monarchwadia avatar Sep 24 '25 15:09 monarchwadia

I'm having the same issue without using VSCode.

Could the SDK at least provide relevant debugging information? My stderr handler is just receiving the stack trace

Error executing Claude query: Claude Code process exited with code 1
Error: Claude Code process exited with code 1
...

gsabran avatar Sep 29 '25 19:09 gsabran

Workaround for me, just downgraded node from 24 to 22 vrsion and done!

LunaxCode avatar Oct 01 '25 20:10 LunaxCode

Anyone know how to explain this to a newbie?

Rcomer123 avatar Oct 09 '25 16:10 Rcomer123

It seems that if you don't accept the last terms of service this error can happen too.

nanemaf4-blip avatar Oct 11 '25 00:10 nanemaf4-blip

It seems that if you don't accept the last terms of service this error can happen too.

This worked for me.

moseswuniche avatar Oct 11 '25 11:10 moseswuniche

Same problem. Downgraded node from 25 to 22 version and works.

ahmsingan avatar Oct 20 '25 13:10 ahmsingan

FYI - setting DEBUG=1 in the environment is really helpful in debugging issues like this. In my case I was trying to stream inputs into the query() function and the Claude SDK subprocess was failing silently. With DEBUG=1 I was able to see some error output.

coryvirok avatar Oct 25 '25 04:10 coryvirok

In my case after setting DEBUG true I saw I was using the root user. Creating a new user fixed it.

Why isn't the actual error msg in the output by default?

WillSmithTE avatar Nov 20 '25 16:11 WillSmithTE

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 21 '25 10:12 github-actions[bot]