VS Code extension: opening a claude --bg background session throws "Claude Code process exited with code 1"

Open 💬 0 comments Opened Jul 13, 2026 by laahirub

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Environment

  • Claude Code VS Code extension v2.1.206 (anthropic.claude-code-2.1.206-darwin-arm64)
  • Claude Code CLI v2.1.207
  • macOS (Darwin 25.5.0)
  • Session was seeded headlessly via claude <prompt> --bg --name <name> --max-turns 40 (no --output-format/--input-format flags), i.e. a plain background/PTY session, not a stream-json session.

Steps to reproduce

  1. Seed a background agent from the CLI: claude "<prompt>" --bg --name review-test --max-turns 40
  2. Confirm it's running: claude agents --json shows an entry with "kind": "background", a pid, and "status": "idle".
  3. Open/attach to that session from a terminal: claude attach <id> — works fine, shows the live PTY output.
  4. Open the same session (by session id / from the session list) inside the VS Code extension.

Expected

The extension attaches to the running background agent and shows its transcript/output, the same as claude attach <id> does in a terminal.

Actual

The extension immediately fails with:

Error: Claude Code process exited with code 1

What Should Happen?

Expected

The extension attaches to the running background agent and shows its transcript/output, the same as claude attach <id> does in a terminal.

Error Messages/Logs

Actual
The extension immediately fails with:

Error: Claude Code process exited with code 1
The underlying agent process is untouched — claude agents --json still shows it alive and idle afterward, and claude attach <id> in a terminal continues to work normally. So nothing about the agent itself crashes; the failure is isolated to how the extension opens it.

Steps to Reproduce

Steps to reproduce

  1. Seed a background agent from the CLI: claude "<prompt>" --bg --name review-test --max-turns 40
  2. Confirm it's running: claude agents --json shows an entry with "kind": "background", a pid, and "status": "idle".
  3. Open/attach to that session from a terminal: claude attach <id> — works fine, shows the live PTY output.
  4. Open the same session (by session id / from the session list) inside the VS Code extension.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

  • Claude Code VS Code extension v2.1.206 (anthropic.claude-code-2.1.206-darwin-arm64) - Claude Code CLI v2.1.207

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Root cause (from inspecting the extension bundle)

The extension's bundled Agent SDK (extension.js, CLAUDE_CODE_ENTRYPOINT="sdk-ts") opens every session — regardless of kind — through its generic ProcessTransport, which spawns:

claude --resume <sessionId> --output-format stream-json --input-format stream-json --permission-prompt-tool stdio ...

Per claude --help, --output-format/--input-format stream-json only work with --print, i.e. this transport assumes every resumable session speaks the stream-json protocol over stdin/stdout.

A --bg session does not — it's hosted by a bg-pty-host process as a real virtual terminal (visible in ps aux as claude bg-pty-host --bg-pty-host <socket> ...). claude attach <id> works because it's just another terminal connecting to that same live PTY. The extension's stream-json resume path has no such PTY bridge.

I checked for a code path in the bundle that special-cases background/PTY sessions (a branch on session kind, a dedicated attach flow, a createTerminal call) — there isn't one. The only reference to sessionKind in the bundle is sessionKind: void 0, i.e. it's never populated when the transport spawns. So the extension has no way to tell "this is a PTY-backed background agent, open it differently" — it always takes the stream-json resume path, which fails against a PTY session and surfaces as:

getProcessExitError(e,t){if(e!==0&&e!==null)return Error(`Claude Code process exited with code ${e}`); ...}

Suggested fix

When opening a session whose kind is "background" (as reported by claude agents --json), the extension should attach via a PTY-compatible path (equivalent to claude attach <id>) instead of spawning a stream-json --resume subprocess.

View original on GitHub ↗