Skip to content

Claude Code fork fails with "Session … not found" when CLAUDE_CONFIG_DIR comes from project environment variables #6325

Closed

Description

@irium

Summary

Forking a Claude Code thread fails right away if CLAUDE_CONFIG_DIR is set as a bb project environment variable, not in the environment of the bb host process. The forked thread goes to error with:

Command thread.start failed — Session <session-id> not found

Both forking paths fail: bb thread fork <id> and "Fork into new thread" in the UI.

Steps to reproduce

  1. Set the project environment variable CLAUDE_CONFIG_DIR to a non-default Claude config directory. Do not set it in the environment of the bb host process.
  2. Start a Claude Code thread in that project and complete at least one turn. Its session transcript is written under <CLAUDE_CONFIG_DIR>/projects/….
  3. Fork the thread: bb thread fork <thread-id>.

Expected: the fork opens with the source thread's history.
Actual: thread.start fails with Session <id> not found. If you then send a message to the forked thread, bb starts a new empty session. The source history is silently lost.

Root cause

Project env vars reach Claude Code only through the session env: config.envVars → buildSessionEnv(readConfigEnvOverrides(params.config)) in plugins/provider-claude-code/src/bridge/bridge.ts.

handleThreadFork (bridge.ts:2457) calls the Agent SDK's forkSession(params.sourceProviderThreadId, …) inside the bridge process (bridge.ts:2474). It passes no dir and no env. The SDK finds the transcript through process.env.CLAUDE_CONFIG_DIR of the bridge process and falls back to ~/.claude. It never looks in the session's configured config dir, so the transcript is not found.

Possible fixes

  • In handleThreadFork, read CLAUDE_CONFIG_DIR from readConfigEnvOverrides(params.config) and pass it to the fork. Today the SDK reads only process.env, so this means scoping the env for the call or using a sessionStore.
  • Or don't fork in-process: start the session with resume: <source> and forkSession: true in the query() options. The CLI then forks with the correct session env.

Related: retrying the failed fork is rejected

bb thread retry <forked-thread-id> fails with Command thread.start failed — Invalid host RPC command. The host daemon rejects the retried thread.start during schema validation (apps/host-daemon/src/server-connection.ts):

ZodError: input must contain at least one entry (path: command.input)

A fork start has no user input, and retry sends thread.start again with an empty input. So a failed fork start can never be retried, whatever made it fail.

Activity

  1. added
    providers
    threads
    provider-claude-code
    on Oct 26, 2026
  2. added theissue type on Oct 26, 2026
  3. added
    confirmed-repro
    on Oct 26, 2026
  4. bb-slop-cop commented on Oct 26, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority High · Effort Medium; providers, threads, provider-claude-code.
    • Reproduction and root-cause report: REPRODUCED, high root-cause confidence; confirmed-repro.
    • Cause: SDK fork lookup uses the bridge process environment before the project's transcript-directory settings are applied to the resumed session.
    • Evidence: The real SDK reproduces the failure in two trusted-main checkouts; the matching-environment control preserves both history messages. Retry rejection is verified at the schema boundary only; the subsequent empty-session claim remains unverified.
    • No PR: Five existing bridge tests fail under this UID-0 runner, so the required green-suite safety gate is not met.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproprovider-claude-codeprovidersthreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions