Skip to content

Add Claude structured session adapter - #13569

Closed
brennanb2025 wants to merge 4 commits into
brennanb2025/codex-structured-mobile-writefrom
brennanb2025/claude-structured
Closed

Add Claude structured session adapter#13569
brennanb2025 wants to merge 4 commits into
brennanb2025/codex-structured-mobile-writefrom
brennanb2025/claude-structured

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Adds the host-side Claude structured-session adapter as the first PR in the Claude stack. It drives the user's installed Claude CLI directly through one long-lived bidirectional stream-json child per session; no Agent SDK or package dependency is added.

The adapter pre-mints deterministic provider session IDs, resumes from the durable provider-handle chain, pins CLAUDE_CONFIG_DIR, proves ownership through system/init plus process identity, buffers events until acquisition is committed, and persists the last observed leaf on graceful close. It also implements replay-acknowledged sends, acknowledged interrupt/model/permission-mode/effort controls, live model discovery with shared-catalog fallback, bounded image inputs, permission and multi-question callbacks, and fail-closed local-only capability data for SSH/WSL.

Launches deliberately use the default interactive setting sources (user,project,local) so user MCP servers, skills, hooks, project instructions, and configured auth/gateway behavior remain intact. The adapter never strips or overrides auth environment; diagnostics expose only booleans and setting-source names, never credential values or gateway URLs.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — 49,035 passed and 99 skipped; 5 unrelated baseline/environment failures remained in the macOS Bash 3 root-directory fixture, a timed macOS helper-process fixture, and the real POSIX SSH GC scale fixture. The Claude-focused suite passes independently.
  • pnpm build — not run; this host-only adapter adds no packaging dependency or UI surface.
  • Added high-quality tests for launch/resume identity, setting-source and account pinning, stream framing, control acknowledgements, auth-diagnostic redaction, init mismatch/startup failure, dispatch replay identity, live model discovery, prompts, and graceful leaf persistence.

Additional gates:

  • Claude focused: 3 files, 18 tests passed.
  • Mobile: pnpm lint, pnpm typecheck, and pnpm test passed; 451 files and 3,451 tests passed, 3 skipped.
  • pnpm run check:max-lines-ratchet passed.
  • pnpm run check:code-quality:changed passed with zero new findings.

AI Review Report

Reviewed acquisition races, init/session proof, chain-head resume behavior, replay acknowledgement, close persistence, prompt callback cardinality, option discovery fallback, bounded input handling, and secret exposure. The review found and fixed two issues: startup exits now reject acquisition immediately instead of waiting for the init deadline, and auth-source diagnostics were reduced to booleans rather than relaying provider strings.

Cross-platform review covered macOS, Linux, and Windows command launch semantics, including the existing Windows wrapper path and platform-native process-tree cleanup. This slice intentionally reports SSH and WSL unsupported; local folder workspaces and git worktrees share the same path resolver, and no keyboard, UI, or Electron behavior changes here.

Security Audit

  • Uses an argument array and the existing Windows command wrapper; it does not compose a shell command.
  • Inherits the user's existing auth lane and pins only the managed account home plus an ownership spawn token.
  • Preserves interactive setting sources and never introduces an API-key flow.
  • Reports only boolean auth-presence signals; token and URL values are not emitted.
  • Validates and bounds local image files to 5 MiB and a fixed MIME allowlist.
  • Bounds stream lines and stderr retention, serializes stdin writes, times out control requests, and fails closed on malformed output.
  • Adds no dependency and no new IPC/wire opcode.

Notes

The subscription-auth product-policy decision remains parked; this PR uses the user's installed CLI and existing login exactly as approved, and does not implement around that dependency with API keys.

Deferred to the next stacked PRs: Claude event-to-journal translation plus runtime/wire registration, then opt-in capability-gated client selection and option UI. The branch is rebased on 9202192f10; later stack PRs will stay based on the current Codex structured tip, and this PR can be retargeted to the default branch after its base merges.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Superseded: this stack part is fully contained in the consolidated big PR (#13438 for Codex, #13584 for Claude) per the two-big-PRs plan. History and review evidence preserved on this PR.

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