Skip to content

fix: present SDK Claude sessions as the CLI entrypoint - #84

Merged
SawyerHood merged 6 commits into
mainfrom
worktree-sdk-cli-traffic-parity
Jun 11, 2026
Merged

SawyerHood merged 6 commits into
mainfrom
worktree-sdk-cli-traffic-parity

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

What

Makes bb's Agent-SDK-spawned Claude sessions present their API traffic like the headless Claude CLI (claude -p) instead of as a third-party SDK app.

In buildSessionEnv:

  • Set CLAUDE_CODE_ENTRYPOINT=cli (the SDK only defaults it to sdk-ts when unset).
  • Drop CLAUDE_AGENT_SDK_CLIENT_APP (also clears any value inherited from a parent SDK process).

Effect on the wire

Captured both clients through a logging reverse-proxy (ANTHROPIC_BASE_URL) under OAuth auth, same prompt/model:

cc_entrypoint user-agent
Before (this code) sdk-ts (external, sdk-ts, agent-sdk/<ver>, client-app/bb/1.0.0)
After sdk-cli (external, sdk-cli, agent-sdk/<ver>)
Headless claude -p sdk-cli (external, sdk-cli, agent-sdk/<ver>)
Interactive claude cli (external, cli)

After this change the SDK traffic is byte-identical to headless claude -p. The request shape (system-prompt preset, betas, tools, context_management) already matched the CLI before this change — only these identity markers differed.

Honest limitation

True interactive cli parity is not reachable from the SDK: the spawned binary always adds the sdk- prefix and an agent-sdk/<ver> user-agent segment because the SDK runs it in stream-json mode. Empirically confirmed by trying CLAUDE_CODE_ENTRYPOINT=cli (→ sdk-cli, not cli) and attempting to suppress the version segment (the SDK re-injects it). sdk-cli is the closest achievable state.

Testing

  • pnpm exec turbo run typecheck --filter=@bb/agent-runtime ✅
  • pnpm exec turbo run test --filter=@bb/agent-runtime ✅ (57 tests). Updated the thread/start env assertion to check CLAUDE_CODE_ENTRYPOINT=cli and CLAUDE_AGENT_SDK_CLIENT_APP undefined.
  • Verified the resulting cc_entrypoint/user-agent end-to-end with a logging proxy.

🤖 Generated with Claude Code

SawyerHood and others added 2 commits June 10, 2026 17:33
bb spawns Claude sessions through the Agent SDK, which by default tags
its API traffic as `cc_entrypoint=sdk-ts` with a
`(external, sdk-ts, agent-sdk/<ver>, client-app/bb/1.0.0)` user-agent.
Set `CLAUDE_CODE_ENTRYPOINT=cli` and drop `CLAUDE_AGENT_SDK_CLIENT_APP`
so sessions instead report `cc_entrypoint=sdk-cli` with a
`(external, sdk-cli, agent-sdk/<ver>)` user-agent — byte-identical to the
headless `claude -p` CLI.

The spawned binary always adds the `sdk-` prefix and an `agent-sdk/<ver>`
user-agent segment because the SDK runs it in stream-json mode, so the
interactive `cli` entrypoint is not reachable from the SDK; `sdk-cli` is
the closest achievable state. Verified by capturing both CLI and SDK
traffic through a logging proxy.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@SawyerHood
SawyerHood force-pushed the worktree-sdk-cli-traffic-parity branch from 01a7787 to b34a2b2 Compare June 11, 2026 00:42
@SawyerHood
SawyerHood merged commit 882b1fe into main Jun 11, 2026
6 checks passed
@SawyerHood
SawyerHood deleted the worktree-sdk-cli-traffic-parity branch June 11, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant