Repository navigation
feat: explain on the local Claude Code (M20) - #48
Merged
Merged
Conversation
M20a. A third adapter behind the LlmClient port: claudeCodeClient runs the user's own `claude -p --output-format json --json-schema --system-prompt --tools "" --safe-mode --no-session-persistence`, the user prompt on stdin, and reads structured_output, usage, total_cost_usd and modelUsage into the port's response; every failure maps onto the port's one error type. --safe-mode, never --bare, which drops the OAuth login. findClaudeCode is pure: explicit path, then CLAUDE_CODE_PATH, then PATH, then the known install locations; an explicit path that does not exist never falls through. resolveProvider takes a probe and keeps auto's precedence OpenRouter > Cloudflare > Claude Code: an exported key is deliberate, an installed CLI ambient. Tested against a fake process and a recorded result; no SDK added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PKCVh1q6FUhWzQi6KYtoTz
M20b. `codegraph explain --provider claude-code [--claude-path FILE]`; --model defaults per provider and is resolved before the plan, so --dry-run and --estimate show `sonnet`; --max-tokens is ignored on Claude Code with a note. PLAN §21 (Phase 18) records the port, the three adapters and the Anthropic API as a named empty slot; docs, README, CLAUDE.md and the website's explain pages follow. Live run on the Java fixture (Claude Code 2.1.322): 68 calls, 0 failed, 79 records stamped claude-sonnet-5-5, decode-clean, $1.03. Prompt tokens come out ~2.7x the estimate: Claude Code adds ~2 500 tokens of scaffolding per call that the estimate does not count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PKCVh1q6FUhWzQi6KYtoTz
The M20b live run billed 307 896 prompt tokens for an estimate of 114 136: every `claude -p` prompt carries Claude Code's scaffolding and the response schema, which it sends as prompt. 48 operation calls came in +2 292…+2 617 over the bare estimate. promptOverhead(provider) in @codegraph/llm says what a transport adds: nothing on the key providers (PetClinic on OpenRouter: +115 median per operation call), CLAUDE_CODE_SCAFFOLD_TOKENS (1 850) plus the schema on Claude Code. planRun takes it as a plain number, so the walk still never learns a provider; the CLI hands it over and both estimate renderings say what was added. Java fixture, re-estimated: 280 481 (was 114 136); operations within 1 % of what was billed. Types (x1.28) and modules (x1.38) stay under, as on OpenRouter: the dependency explanations a prompt inlines do not exist at plan time — a gap every provider shares, not fixed here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PKCVh1q6FUhWzQi6KYtoTz
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
codegraph | 7b514bc | Commit Preview URL Branch Preview URL |
Nov 10 2026, 10:56 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
M20 (PLAN.md §21, Phase 18):
codegraph explaincan run on the local Claude Code install — no API key — as a third adapter behind the existingLlmClientport.feat(llm)— M20a.claudeCodeClientspawns the user's ownclaude -p --output-format json --json-schema --system-prompt --tools "" --safe-mode --no-session-persistence, the user prompt on stdin (a context pack can exceed the 128 KB per-argument limit), and readsstructured_output/usage/total_cost_usd/modelUsageinto the port's response; every failure maps onto the port's one error type.--safe-mode, never--bare(which drops the OAuth login).findClaudeCodeis pure:--claude-path→CLAUDE_CODE_PATH→PATH→ known install locations.autoprecedence stays OpenRouter > Cloudflare > Claude Code: an exported key is deliberate, an installed CLI ambient. No SDK added; the Anthropic API adapter is a named empty slot (§21.6), not a stub.feat(cli)— M20b.--provider claude-code,--claude-path FILE;--modeldefaults per provider (sonnet) and is resolved before the plan, so--dry-run/--estimateshow it;--max-tokensis noted and ignored. Docs, README, CLAUDE.md and the website's explain pages name the port, the three adapters and the empty slot.fix(explain)— the estimate. The live run billed 307 896 prompt tokens for an estimate of 114 136: everyclaude -pprompt carries Claude Code's scaffolding and the response schema.promptOverhead(provider)(in@codegraph/llm) is handed toplanRunas a plain number — the walk still never learns a provider. Re-estimated: 280 481; operations within 1 % of what was billed. Key providers unchanged, byte for byte.Live run (Java fixture, Claude Code 2.1.322)
claude-sonnet-5-5), 9 templateddecodeInsightsclean, not truncated, headerprovider: "claude-code", modelssonnet/sonnettotal_cost_usd, list price)Not fixed here
Types (×1.28) and modules (×1.38) are still estimated low, on every provider (PetClinic on OpenRouter: types ×1.20…1.38): the dependency explanations a prompt inlines do not exist at plan time. Recorded in PLAN §21.4.
Test plan
@codegraph/llm96,@codegraph/insights163,@codegraph/cli1 048 tests green; red-first for the estimate fix (three new tests)pnpm -r typecheckclean; eslint clean on the touched filesanalyzer/test/scale.test.tstimed out once under full-workspace load (known flake) and passes alone--estimatere-run on the fixture for both providerswebsitebuild not checked locally (snap Hugo 0.169, issue pnpm -r build fails on a fresh clone: unknown output format "llms" for kind "home" #23) — CI's Hugo job covers it🤖 Generated with Claude Code
https://claude.ai/code/session_01PKCVh1q6FUhWzQi6KYtoTz