Skip to content

[Spec 1912] consult: run the claude lane on the installed claude CLI, on the subscription - #1913

Merged
waleedkadous merged 45 commits into
mainfrom
builder/aspir-1912
Nov 17, 2026
Merged

waleedkadous merged 45 commits into
mainfrom
builder/aspir-1912

Conversation

@waleedkadous

Copy link
Copy Markdown
Contributor

Summary

consult -m claude no longer uses the bundled Claude Agent SDK. It runs the user's installed claude CLI in read-only print mode (claude -p --output-format stream-json). By default it uses the CLI's own login, which is the subscription for most people. ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are withheld unless consult.claudeAuth: "api-key" opts in. codev doctor checks the installed CLI with no model call, and @anthropic-ai/claude-agent-sdk is removed.

Closes #1912

Changes

  • lib/claude-cli.ts (new): binary resolution (CODEV_CLAUDE_BIN pin, else PATH; refused unpinned under a test runner) and a version floor (CLAUDE_MIN_VERSION = 2.1.141). Also the auth mode (consult.claudeAuth: login default | api-key, validated at config load), the child env (session markers and, by default, API credentials removed; process.env never mutated), the auth status --json preflight, and the [CLAUDE] binary: / [CLAUDE] auth: lines.
  • Consult claude lane: spawns claude -p --output-format stream-json --verbose --tools Read,Glob,Grep --permission-mode dontAsk --allowedTools Read,Glob,Grep --setting-sources "" --strict-mcp-config --disable-slash-commands --no-session-persistence --max-turns 200 --max-budget-usd 25 --model <id> --system-prompt-file <0600 file> --add-dir <sandbox>, with the prompt on stdin.
    • The init event's tool list is checked at runtime.
    • Every failure is loud, with no fallback to the SDK or an API key, and is classified: missing, too old, logged out, error result, error subtype, no result, non-JSON line, "Prompt is too long" (consult -m claude fails with 'Prompt is too long' on a large PR (5 attempts, 2 callers, PR #1640) #1641).
    • SIGINT/SIGTERM kill the child and wait for it to exit.
    • A claude-lane-only capability note replaces the shell instructions the reviewer can no longer follow; consultant.md is unchanged.
    • permission_denials are reported on stderr.
  • Doctor: a real Claude version and login check (claude auth status, using the lane's env, so withheld .env keys are reported truthfully). No model call.
  • SDK removed from packages/codev/package.json and pnpm-lock.yaml. The lockfile has no version changes; it marks 54 @modelcontextprotocol/sdk-subtree packages optional: true.
  • Docs in every tree: CLAUDE.md/AGENTS.md (byte-identical), the consult and codev skills (4 copies each, hashes regenerated), consult.md and codev.md (both trees), DEPENDENCIES.md (both trees), and arch.md / lessons-learned.md (cold tier).
  • Adjacent fixes, made in place: arch.md's pre-SDK claude spawn line and its stale "Claude nesting limitation" paragraph; codev.md's doctor section, which listed @anthropic-ai/claude-code.

Testing

  • Stub-driven unit tests (helpers/stub-claude.ts records argv, env and stdin, and replays fixtures captured from a real 2.1.326 stream): claude-cli.test.ts, claude-cli-lane.test.ts, plus migrated consult, doctor, bugfix-1754-dotenv-auth, lane-models, tripwire-wiring, metrics, consultant-role and test-isolation. No live model calls in the suite.
  • Full suite via porch's checks for each phase (build and tests green).
  • Live review from this worktree's build, on the subscription: consult -m claude --protocol bugfix --type pr --issue 1821. Exit 0, VERDICT COMMENT, --output byte-identical to stdout. Metrics row: claude-opus-5, 148.9 s, 18 / 186,510 cached / 11,019 tokens, $0.7473. stdout was JSON-only, with no hook or plugin output.
    [CLAUDE] binary: /Users/mwk/.local/bin/claude, 2.1.326 (from PATH)
    [CLAUDE] auth: claude.ai (max) — stored claude login; ignoring ANTHROPIC_API_KEY (from .env) — set consult.claudeAuth to "api-key" to bill the API instead
    
  • One $0.018 probe confirmed that dontAsk + --add-dir permits the sandbox (PR-diff) read: permission_denials: [].
  • Not run: the opt-in real-CLI e2e consult-readonly-review.e2e.test.ts (now CODEV_ALLOW_REAL_CLAUDE). The owner's standing order bars the local e2e suite.

Flaky Tests

Pre-existing tests, untouched here. They failed once under load in a porch run and passed alone (48/48): consult/__tests__/agy-auth-cache.test.ts, agent-farm/__tests__/pir-1233-session-launch-loop.test.ts and agent-farm/__tests__/bugfix-1267-launch-loop.test.ts.

Release note (ready to paste)

consult: the claude lane now runs your installed claude CLI, on your subscription (#1912). consult -m claude no longer uses the bundled Claude Agent SDK. It runs the claude on your PATH (2.1.141 or newer, or CODEV_CLAUDE_BIN) in read-only print mode, so upgrading claude upgrades the lane. It uses the CLI's own login by default, which for most people is the Claude subscription. ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are withheld from it, whether set in the shell or in the workspace .env, and the [CLAUDE] auth: line says when a key was ignored. Breaking for key-only environments: a CI job with ANTHROPIC_API_KEY and no claude login now fails loudly. To keep billing the API, add "consult": { "claudeAuth": "api-key" } to .codev/config.json. codev doctor now checks the installed claude version and login, with no model call. The @anthropic-ai/claude-agent-sdk dependency is removed. The test-only opt-in CODEV_ALLOW_REAL_CLAUDE_SDK is renamed CODEV_ALLOW_REAL_CLAUDE.

Spec

codev/specs/1912-consult-run-the-claude-review-.md

Review

codev/reviews/1912-consult-run-the-claude-review-.md

🤖 Generated with Claude Code

waleedkadous and others added 30 commits November 16, 2026 16:17
…laudeAuth config

Everything the claude lane decides before spawning a review, built and
tested in isolation, with no consult wiring yet:

- lib/claude-cli.ts: binary resolution (CODEV_CLAUDE_BIN pin, PATH walk,
  test-runner guard), the 2.1.141 version floor, auth mode, the child env
  (session markers dropped; API keys withheld in login mode), auth status
  parsing, the auth and binary lines, and preflightClaude, whose
  ClaudePreflightError carries whichever report lines were known.
- consult.claudeAuth ("login" | "api-key"), typed in config.ts and
  validated at load time in consult-lanes.ts.
- lib/dotenv.ts: the pure .env parser; consult's loadDotenv is built on it.
- test-env: CODEV_ALLOW_REAL_CLAUDE (renamed from _SDK) and
  assertClaudeLaneAllowedUnderTest. vitest-setup pins a fake claude.
- A reusable stub-claude test helper, and stream fixtures trimmed from one
  real CLI 2.1.326 run with the lane's argv (stdout JSON-only, init tools
  exactly Glob/Grep/Read).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rtion

Error-message assertions that ran a stub-backed call twice now capture the
error once and match on it, halving the node processes those tests start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ne; absolute pin

Review iteration 1 (codex REQUEST_CHANGES, claude APPROVE with notes):

- The auth line names the credential the CLI uses, by its precedence, and
  every other credential variable present in the child env. The precedence
  agrees with the CLI's own authMethod (probed on 2.1.326). apiKeySource is
  not used to pick the winner: with both API variables set it still names
  the key while authMethod reports the bearer token.
- A relative CODEV_CLAUDE_BIN is resolved to an absolute path, so the review
  spawned with cwd = the workspace runs the file that was checked.
- A preflight timeout reads "no answer within 30s".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…installed claude CLI

The claude lane now spawns the user's own `claude -p` (stream-json, prompt on
stdin, role plus a capability note in a 0600 system-prompt file in consult's
sandbox dir) instead of the Agent SDK. No SDK import is left in consult/.

- buildClaudeReviewArgs: --tools Read,Glob,Grep (availability, not just
  approval), dontAsk + --allowedTools, no settings sources, strict empty MCP,
  no slash commands, no session persistence, 200 turns, $25, --add-dir sandbox
- init guard: the session must report only Read/Glob/Grep before any
  assistant event; a mid-stream protocol failure terminates the child and
  waits for its exit before the lane fails
- distinct failures: no result (exit code + bounded stderr tail), exit 0 with
  no result, non-JSON line, error subtype, is_error result (names the
  credential), "Prompt is too long" (context exhaustion, model id, #1641)
- SIGINT/SIGTERM: terminate the child, remove the temp file and stale
  --output, exit 130/143; handlers are removed after every run
- CLI permission denials are named on stderr, since dontAsk denies silently
- SDK_MODELS -> RUNNER_LANES; SDKResultLike -> ClaudeResultLike
- assertClaudeVersion rejects a malformed version instead of comparing NaN
  (phase_1 review nit)

Tests: new claude-cli-lane.test.ts; consult, bugfix-1754, lane-models and
tripwire-wiring drive a stub claude instead of mocking the SDK; the obsolete
claude-auth-env test is removed (its #985/#1754 cases live in
claude-cli.test.ts); the opt-in read-only e2e drives the real CLI with the
lane's argv.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…CLI; drop the Agent SDK

codev doctor's Claude rows now check what the claude lane actually runs, with no
model call:

- "AI CLI Dependencies": resolveClaudeBin + readClaudeVersion +
  assertClaudeVersion. A missing claude (install hint) or one below 2.1.141
  (`claude update`) is a warning, and claude counts as installed only when the
  row is ok, so a codex-only machine still meets the one-working-model rule.
- "AI Model Verification": `claude auth status` with the child env the lane
  would build (workspace .env merged into a copy of process.env, then
  consult.claudeAuth and buildClaudeChildEnv). A withheld key is reported with
  its origin; logged out, unparseable output, a missing api-key-mode key or a
  bad consult.claudeAuth are warnings carrying the lane's own message.

The SDK probe (a one-turn model session with bypassPermissions) is gone, and with
it the last import of @anthropic-ai/claude-agent-sdk, which is removed from
package.json and the lockfile. The lockfile diff deletes the SDK, its
@anthropic-ai/sdk dependency and their exclusive packages (sharp natives,
json-schema-to-ts, ts-algebra); no version changes. It also marks
@modelcontextprotocol/sdk's subtree optional: that is now reachable only through
@google/genai's optional peer.

describeWithheldKeys is factored out of describeClaudeAuth so doctor and the auth
line word the withheld-key note identically. The Bugfix #341 comment in cli.ts
no longer names the Claude Agent SDK.

Tests: doctor.test.ts drops the SDK mock and keeps execFileSync real, so the
Claude cases run a stub claude: scenarios 27-31, plus .env/shell keys withheld
(process.env untouched), api-key mode and unparseable auth status.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t guard; thread: phase_3 reviews

Co-Authored-By: Claude Opus 5.5 <[email protected]>
waleedkadous and others added 13 commits November 16, 2026 18:43
…claude CLI, in every tree

CLAUDE.md/AGENTS.md, the consult and codev skills (four copies each), and
consult.md in codev/ and codev-skeleton/ now describe the installed
`claude` CLI on the user's login. They document consult.claudeAuth (login
by default, api-key as the opt-in, which is the breaking change for
key-only CI), CODEV_CLAUDE_BIN and CODEV_ALLOW_REAL_CLAUDE. codev.md's
doctor section names the CLI check. Skill hashes are regenerated, and the
[From 0120] lesson gets a Spec 1912 note.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e does; claudeAuth source wording

The [CLAUDE] warning example now shows the quoted path excerpt() emits, and
the consult.claudeAuth bullet says the auth line names the file that set
consult.claudeAuth. Thread: phase_4 reviews, the release-note draft, and the
pre-1912 global consult billing the API key from .env.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…DEPENDENCIES floor row

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… successful review fails

PR review iter1 (codex): the runtime guard accepted any subset of the review
tools. It now also fails on a missing or repeated tool. Claude's notes: a
success result with no assistant text fails instead of writing an empty
--output, and the floor comment says what was verified at 2.1.105.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@waleedkadous

Copy link
Copy Markdown
Contributor Author

Thank you, this is careful work: --tools as the hard read-only guarantee, the init-event check, and the probe that closed the diff-read gap are exactly right.

Independent integration reviews: codex APPROVE, claude APPROVE. CI 8/8 green. Three small fold-ins before it goes to the owner:

  1. Extra-tool failure message. It says it is refusing a review "with write or shell tools" when the unexpected tool may be neither. Say what was found, and name the recovery lever: pin a known-good claude with CODEV_CLAUDE_BIN. A CLI release that adds a tool would stop every review at once, so the way out should be in the message.
  2. claude update hints do not apply to an npm-installed claude. Perhaps word the hint to cover both install routes.
  3. codev doctor and a .env-only CODEV_CLAUDE_BIN (codex's note): make doctor resolve the binary the same way the lane does, if that is the discrepancy.

Targeted tests only, please.

waleedkadous and others added 2 commits November 16, 2026 19:28
…ls, doctor honours a .env pin

Architect PR review fold-ins:
- Init-guard failures say what they found instead of "write or shell tools"
  and name the way out: pin a known-good claude with CODEV_CLAUDE_BIN.
- CLAUDE_UPDATE_HINT covers both install routes (claude update / npm).
- resolveClaudeBin(env): doctor resolves from its .env merge, as consult does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

consult: run the claude review lane through the installed claude CLI instead of the Agent SDK, on the user's subscription

1 participant