Skip to content

feat(llm): subscription CLI providers (claude-code:*, codex:*) + sampling doc correction - #592

Merged
the-data-viking merged 1 commit into
mainfrom
feat/subscription-cli-providers
Oct 9, 2026
Merged

the-data-viking merged 1 commit into
mainfrom
feat/subscription-cli-providers

Conversation

@the-data-viking

Copy link
Copy Markdown
Collaborator

Summary

Adds two subscription CLI providers so Althing can run on a signed-in Claude Code or Codex CLI instead of an API key:

  • claude-code:<model> → claude -p (e.g. claude-code:haiku, claude-code:sonnet; claude-code: uses the CLI default)
  • codex:<model> → codex exec (codex: uses the CLI default)

This is the replacement for MCP sampling as the "borrow the host's model access" path. MCP 2026-07-28 deprecated sampling (SEP-2577), and Claude Code never implemented it (anthropics/claude-code#1785), so sampling mode never activated under Claude Code even though the docs said it would.

How it works

  • Each call is an isolated, tool-less completion. The CLI's agent prompt is replaced by the request's system (persona) prompt. Tools, MCP servers, user settings and session persistence are disabled. The process runs in an empty scratch directory so no CLAUDE.md or AGENTS.md leaks in.
  • Structured output: forced single-tool requests (the StructuredOutputEngine path and SynthBench's --elicitation structured) map onto --json-schema / --output-schema and come back as normal tool-call responses. Codex needs an OpenAI strict-mode schema, so optional fields become required-but-nullable and the nulls are stripped on the way back.
  • Routing: explicit prefix only, never chosen as a credential fallback. These providers are registered ahead of Anthropic, because claude-code: would otherwise match claude-.
  • Structured-output escalation stays on the same CLI. Previously, claude-code:haiku would have escalated to the API-key sonnet.
  • MCP: an explicit CLI model makes decide_mode choose direct execution, so run_panel and the other tools work under Claude Code with no key.
  • Billing safety: ANTHROPIC_API_KEY is stripped from the claude child environment, because the CLI prefers it over the subscription login and would silently bill the key. ALTHING_CLAUDE_CODE_ALLOW_API_KEY=1 keeps it.
  • Cost: no per-call bill exists, so the cost shown is the local list-price estimate. --max-cost therefore acts as a usage budget.
  • Errors: usage-limit, auth and overload messages are classified into the existing error categories, so the normal rate-limit backoff applies.
  • Settings: ALTHING_CLI_MAX_CONCURRENT (default 4), ALTHING_CLI_TIMEOUT (300 s), ALTHING_CLAUDE_CODE_EFFORT / ALTHING_CODEX_EFFORT, ALTHING_CLAUDE_CODE_BIN / ALTHING_CODEX_BIN.

Limitations (documented)

  • No temperature / top_p / seed / max_tokens control. Results should be labelled separately from API-key runs.
  • Text only, and only forced single-tool calls. Multi-turn history is flattened into one prompt per call.
  • Throughput is bounded by subscription usage limits.
  • Codex adds about 7.5k input tokens of agent overhead per call, versus about 1k for Claude Code.

Docs (sampling correction)

README, docs/mcp.md, site/mcp (HTML re-rendered to markdown), CLAUDE.md, the CHANGELOG and the no-credentials error message no longer claim Claude Code supports sampling. They note the deprecation and point to the CLI models.

Testing

  • tests/test_subscription_cli.py: 37 tests covering routing, the arguments and environment passed to each CLI, prompt flattening, strict-schema rewriting, error classification, timeouts, stream replay, structured-engine round-trip, escalation and decide_mode.
  • Affected suites pass (sampling, site markdown, client, structured). Ruff and mypy show nothing new. The full suite on Windows has about 44 failures that also fail on main (signal handling, file locking, CRLF digests, shell hooks).
  • Live: althing prompt ran on both claude-code:haiku (about 2 s) and codex: (about 5.6 s). The 3-persona example panel run with synthesis completed cleanly in about 70 s.
  • Live SynthBench (25 GlobalOpinionQA questions × 30 samples, -p althing -m claude-code:haiku --elicitation structured): 750 out of 750 samples parsed, SPS 0.747 [0.687–0.805], 8.7 min, no errors or rate limits.

🤖 Generated with Claude Code

Route completions through a signed-in Claude Code (`claude -p`) or Codex
(`codex exec`) CLI so runs draw on the user's subscription instead of an
API key. This replaces MCP sampling as the "use the host's model access"
path: sampling was deprecated in MCP 2026-07-28 (SEP-2577) and Claude
Code never implemented it.

- New providers in llm/providers/subscription_cli.py, registered ahead of
  Anthropic (claude-code: would otherwise match claude-). Explicit prefix
  only; never a credential fallback.
- Each call is an isolated, tool-less completion: agent system prompt
  replaced, tools/MCP/user settings/session persistence disabled, empty
  scratch cwd. Forced single-tool structured output maps to
  --json-schema / --output-schema (strict-mode rewrite for Codex).
- ANTHROPIC_API_KEY is stripped from the claude child env (it would
  otherwise take precedence over the subscription login).
- Structured-output escalation stays on the same CLI; MCP decide_mode
  treats an explicit CLI model as having credentials.
- Docs: Claude Code no longer listed as sampling-capable; sampling
  deprecation noted; no-creds error points at CLI models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@the-data-viking the-data-viking added the semver:minor Bump minor version on merge label Oct 9, 2026
@the-data-viking
the-data-viking merged commit 6f2c553 into main Oct 9, 2026
22 of 23 checks passed
@the-data-viking
the-data-viking deleted the feat/subscription-cli-providers branch October 9, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:minor Bump minor version on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants