Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,36 @@ For auto-generated release notes, see [GitHub Releases](https://github.com/DataV
depends on `althing`
Historical changelog entries below retain the old name.

- **Sampling docs corrected.** Claude Code is no longer listed as a
sampling-capable host (it has never implemented the client side —
anthropics/claude-code#1785), the docs note the MCP 2026-07-28
sampling deprecation, and the no-credentials error now points at
subscription CLI models.

### Added

- **Subscription CLI providers: `claude-code:<model>` and `codex:<model>`.**
Completions can now run through a locally installed, signed-in Claude
Code (`claude -p`) or Codex (`codex exec`) CLI, drawing on the user's
Claude / ChatGPT subscription instead of an API key — the
forward-looking replacement for MCP sampling, which MCP 2026-07-28
deprecated (SEP-2577) and Claude Code never implemented. Each call is
an isolated, tool-less completion (agent prompt replaced by the persona
prompt; tools, MCP servers, user settings, and session persistence
disabled; empty scratch working directory), and forced-tool structured
output maps onto the CLIs' native JSON-schema flags, so panels,
extraction, and SynthBench's `althing` provider work unchanged. The
prefixes are explicit-only (never a credential fallback), structured
output escalation stays on the same CLI, and an explicit CLI model
makes MCP tools run without a key or sampling. Limits: no
temperature/top_p/seed/max_tokens control, text-only, throughput bound
by subscription usage limits (surfaced as rate limits). Knobs:
`ALTHING_CLI_MAX_CONCURRENT`, `ALTHING_CLI_TIMEOUT`,
`ALTHING_CLAUDE_CODE_EFFORT` / `ALTHING_CODEX_EFFORT`,
`ALTHING_CLAUDE_CODE_BIN` / `ALTHING_CODEX_BIN`, and
`ALTHING_CLAUDE_CODE_ALLOW_API_KEY` (by default `ANTHROPIC_API_KEY` is
stripped from the child env so the CLI can't silently bill it).

- **`cost show <result-id>`.** Per-run cost breakdown for one saved
panel result — total/panelist cost, per-model token + USD rollup, and
synthesis cost — as a thin alias over the cost section of `panel
Expand Down
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ Set the appropriate environment variable:
| OpenAI | `OPENAI_API_KEY` | (must specify --model) |
| xAI | `XAI_API_KEY` | grok-3 |
| Google | `GOOGLE_API_KEY` or `GEMINI_API_KEY` | gemini-2.5-flash |
| Claude Code CLI | none (signed-in `claude`) | explicit only: `claude-code:<model>` |
| Codex CLI | none (signed-in `codex`) | explicit only: `codex:<model>` |

Subscription CLI providers live in `llm/providers/subscription_cli.py` and
register *before* Anthropic in `_PROVIDER_REGISTRY` (`claude-code:` would
otherwise match `claude-`). They never satisfy the credential fallback.

## YAML Formats

Expand Down
62 changes: 58 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,20 @@ Add to your editor's MCP config (Claude Code, Cursor, Windsurf):

### Zero-config first run via sampling

No API key? No problem. When the invoking MCP client (Claude Desktop,
Claude Code, Cursor, Windsurf) advertises the `sampling` capability,
althing falls back to asking the client to run the LLM completion on
its behalf — using the client's own subscription. That means `run_prompt`
No API key? When the invoking MCP client advertises the `sampling`
capability, althing falls back to asking the client to run the LLM
completion on its behalf — using the client's own subscription.

> **Sampling is deprecated and not universally supported.** MCP
> 2026-07-28 deprecated sampling (SEP-2577; still functional for at
> least 12 months), and **Claude Code has never implemented it**
> ([anthropics/claude-code#1785](https://github.com/anthropics/claude-code/issues/1785)).
> To use a Claude or ChatGPT subscription from Claude Code (or anywhere
> else), pass a subscription CLI model instead — e.g.
> `model="claude-code:haiku"` — see
> [Subscription CLI models](#subscription-cli-models-claude-code--codex).

With a sampling-capable client, That means `run_prompt`
and small `run_quick_poll` calls (up to 3 personas) work with zero env
setup:

Expand Down Expand Up @@ -1083,6 +1093,8 @@ althing works with any LLM provider. Set the appropriate environment variable:
| OpenRouter | `OPENROUTER_API_KEY` | `--model openrouter/anthropic/claude-haiku-4-5` |
| xAI (Grok) | `XAI_API_KEY` | `--model grok` |
| Any OpenAI-compatible | `OPENAI_API_KEY` + `OPENAI_BASE_URL` | `--model <model-id>` |
| Claude Code CLI (subscription) | none — signed-in `claude` on PATH | `--model claude-code:sonnet` |
| Codex CLI (subscription) | none — signed-in `codex` on PATH | `--model codex:` or `--model codex:<model-id>` |

```bash
# Use Claude (default)
Expand All @@ -1096,6 +1108,48 @@ OPENAI_BASE_URL=http://localhost:11434/v1 \
althing panel run --personas p.yaml --instrument s.yaml --model llama3
```

### Subscription CLI models (`claude-code:` / `codex:`)

The `claude-code:<model>` and `codex:<model>` prefixes run each completion
through a locally installed, signed-in agent CLI in headless mode
(`claude -p` / `codex exec`), so calls draw on your Claude or ChatGPT
subscription instead of an API key. Every call is an isolated, tool-less
completion: the CLI's agent system prompt is replaced by the persona
prompt, tools / MCP servers / user settings are disabled, nothing is
persisted, and the process runs in an empty scratch directory. Structured
output maps onto the CLIs' native JSON-schema flags.

```bash
althing panel run --personas p.yaml --instrument s.yaml --model claude-code:haiku
althing prompt "Hello" --model codex: # Codex CLI's default model
```

Things to know before relying on it:

- **No sampling controls.** `temperature`, `top_p`, `seed`, and
`max_tokens` are not exposed by the CLIs and are ignored (with a
warning). Results are not directly comparable to API-key runs of the
same model — label them separately (e.g. on SynthBench).
- **Subscription usage limits** bound throughput. Usage-limit errors
surface as rate limits and get the normal backoff. Cap in-flight CLI
processes with `ALTHING_CLI_MAX_CONCURRENT` (default 4) and per-call
time with `ALTHING_CLI_TIMEOUT` (default 300 s).
- **Text only, forced single-tool only.** Attachments and free tool
use are rejected; multi-turn persona history is flattened into one
prompt per call.
- **Cost figures are estimates.** There is no per-call bill, so cost is
the local pricing-table estimate (API list-price equivalent) and
`--max-cost` acts as a usage budget.
- **API keys are stripped.** `claude` prefers `ANTHROPIC_API_KEY` over
the subscription login, so althing removes it from the child process
environment. Set `ALTHING_CLAUDE_CODE_ALLOW_API_KEY=1` to keep it.
- Optional: `ALTHING_CLAUDE_CODE_EFFORT` / `ALTHING_CODEX_EFFORT` pass a
reasoning-effort level; `ALTHING_CLAUDE_CODE_BIN` / `ALTHING_CODEX_BIN`
override the executable path.

These prefixes are only used when you ask for them — they are never
picked as an implicit default.

> **Large panels and the OpenRouter default (synthbench#261):** when
> `--model` is omitted, the default is resolved from whichever key is
> present — for an OpenRouter-only environment that's `openrouter/auto`,
Expand Down
54 changes: 50 additions & 4 deletions docs/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,17 @@ and `_resolve_mcp_default_model()` in `src/althing/mcp/server.py`.
| no | yes | (auto) | **BYOK** |
| no | (any) | `true` | **error** — host did not advertise `sampling` |
| no | (any) | `false` | **BYOK** — falls through to a missing-creds error if no key is set |
| (any) | (any) | (auto), with `model="claude-code:*"` / `"codex:*"` | **BYOK** — the subscription CLI needs no key |

"Provider key available" means any of `ANTHROPIC_API_KEY`,
`OPENAI_API_KEY`, `XAI_API_KEY`, `GOOGLE_API_KEY`, `GEMINI_API_KEY`, or
`OPENROUTER_API_KEY` — checked first against the process environment,
then against the on-disk credential store written by `althing login`
(so MCP-launched subprocesses recognise keys the CLI can see).
(so MCP-launched subprocesses recognise keys the CLI can see). An
explicit subscription CLI model (`claude-code:<model>` /
`codex:<model>`) counts as available credentials: it runs on the
signed-in CLI and needs no key (see
[Subscription CLI models](#subscription-cli-models)).

The auto rule "local key wins over sampling" exists so users who *have*
configured BYOK keep BYOK's full feature set (cross-provider ensembles,
Expand Down Expand Up @@ -589,6 +594,15 @@ failing.
See [Model Resolution Order](#model-resolution-order) for the full
configuration → mode matrix.

> **Deprecated, and not available in Claude Code.** MCP 2026-07-28
> deprecated sampling (SEP-2577) — it keeps working for at least twelve
> months, with removal no earlier than the first revision after
> 2027-07-28 — and **Claude Code has never implemented the client side**
> ([anthropics/claude-code#1785](https://github.com/anthropics/claude-code/issues/1785)),
> so sampling mode never activates under Claude Code. The
> forward-looking way to run on a subscription is a
> [subscription CLI model](#subscription-cli-models).

### Tradeoffs

Sampling mode is intentionally less capable than BYOK:
Expand Down Expand Up @@ -669,6 +683,34 @@ decided per call by probing the client's declared `sampling` capability
(from the `initialize` handshake on legacy connections, or the
per-request `_meta` envelope on modern ones).

## Subscription CLI models

`claude-code:<model>` and `codex:<model>` route each completion through a
locally installed, signed-in agent CLI in headless mode (`claude -p` /
`codex exec`), drawing on your Claude or ChatGPT subscription instead of
an API key. Unlike sampling it works under any MCP host (including
Claude Code), on the CLI and SDK, and has no persona/question caps or
structured-output restriction:

```jsonc
// run_quick_poll arguments
{ "question": "...", "pack_id": "...", "model": "claude-code:haiku" }
```

Each call is an isolated, tool-less completion — the CLI's agent prompt
is replaced by the persona prompt, tools / MCP servers / user settings
are disabled, nothing is persisted, and the process runs in an empty
scratch directory. The CLI must be installed and signed in on the
machine running `althing mcp-serve`.

Tradeoffs: no `temperature` / `top_p` / `seed` / `max_tokens` control,
text-only content, throughput bounded by subscription usage limits
(surfaced as rate limits), and cost figures that are API list-price
estimates rather than bills. See the
README's "Subscription CLI models" section for the environment knobs
(`ALTHING_CLI_MAX_CONCURRENT`, `ALTHING_CLI_TIMEOUT`,
`ALTHING_CLAUDE_CODE_ALLOW_API_KEY`, …).

## Host Integration Flags

### `ALTHING_DRIFT_DEGRADE`
Expand Down Expand Up @@ -784,9 +826,13 @@ Symptom: tool calls return `MISSING_CREDS` or a provider-specific
- Run `althing login` to seed the on-disk credential store; the MCP
server reads from there as a fallback when the env is empty (see
[Model Resolution Order](#model-resolution-order)).
- If your host advertises MCP `sampling` (Claude Desktop, Claude Code,
Cursor, Windsurf), you can omit the key entirely and althing will
borrow the host's LLM access — see [Sampling Mode](#sampling-mode).
- To run without a key, pass a subscription CLI model
(`model="claude-code:haiku"` or `"codex:"`) — it uses the signed-in
CLI on the server machine; see
[Subscription CLI models](#subscription-cli-models). If your host
advertises MCP `sampling` (**not** Claude Code), you can also omit
the key and althing will borrow the host's LLM access — see
[Sampling Mode](#sampling-mode).

### Timeouts on long panel runs

Expand Down
10 changes: 7 additions & 3 deletions site/mcp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1558,9 +1558,13 @@ <h3 class="mt-8 mb-3 text-base font-semibold text-white">
the
<code class="text-slate-300">env</code> block, run
<code class="text-slate-300">althing login</code> to
seed the on-disk credential store, or omit the key and
let MCP <em>sampling</em> borrow the host's LLM access
(Claude Desktop, Claude Code, Cursor, Windsurf).
seed the on-disk credential store, pass a subscription
CLI model such as
<code class="text-slate-300">model="claude-code:haiku"</code>
to run on the signed-in Claude Code / Codex CLI, or omit
the key and let MCP <em>sampling</em> borrow the host's
LLM access (deprecated in MCP 2026-07-28, and not
supported by Claude Code).
</dd>
</div>
<div>
Expand Down
2 changes: 1 addition & 1 deletion site/mcp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Note the two distinct locations: API keys saved by `althing login` live in the c

Server starts but no tools appear The MCP server needs the `[mcp]` extra: `pip install "althing[mcp]"`. After config edits or upgrades, fully quit and relaunch the host — tool lists are cached per server entry. Sanity-check by running `althing mcp-serve` in a terminal; it should boot silently.

Missing API key The subprocess only sees env vars from the MCP `env` block. A shell-profile export does not propagate. Set the key in the `env` block, run `althing login` to seed the on-disk credential store, or omit the key and let MCP *sampling* borrow the host's LLM access (Claude Desktop, Claude Code, Cursor, Windsurf).
Missing API key The subprocess only sees env vars from the MCP `env` block. A shell-profile export does not propagate. Set the key in the `env` block, run `althing login` to seed the on-disk credential store, pass a subscription CLI model such as `model="claude-code:haiku"` to run on the signed-in Claude Code / Codex CLI, or omit the key and let MCP *sampling* borrow the host's LLM access (deprecated in MCP 2026-07-28, and not supported by Claude Code).

Timeouts on long panels A 5-persona × 3-question BYOK panel takes 30–90 seconds; cross-provider ensembles can take 2–5 minutes. Raise the host's per-tool timeout (Hermes: `timeout: 300`). For exploratory work, prefer `run_quick_poll` over `run_panel`.

Expand Down
9 changes: 8 additions & 1 deletion src/althing/_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,14 @@ def _resolve_context_window(model: str | None) -> tuple[int, bool]:
# "haiku" doesn't falsely pick the default window.
try:
from althing.llm.aliases import resolve_alias

from althing.llm.providers.subscription_cli import SUBSCRIPTION_CLI_PREFIXES

# Subscription CLI models ("claude-code:haiku") size like the model
# they wrap.
for cli_prefix in SUBSCRIPTION_CLI_PREFIXES:
if model.startswith(cli_prefix):
model = model[len(cli_prefix) :]
break
resolved = resolve_alias(model)
except Exception:
resolved = model
Expand Down
14 changes: 13 additions & 1 deletion src/althing/llm/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from althing.llm.providers.gemini import GEMINI_CONFIG, GeminiProvider
from althing.llm.providers.openai_compat import OPENAI_COMPAT_CONFIG, OpenAICompatibleProvider
from althing.llm.providers.openrouter import OPENROUTER_CONFIG, OpenRouterProvider
from althing.llm.providers.subscription_cli import (
CLAUDE_CODE_CONFIG,
CODEX_CONFIG,
ClaudeCodeProvider,
CodexProvider,
)
from althing.llm.providers.xai import XAI_CONFIG, XAIProvider
from althing.llm.retry import (
DEFAULT_INITIAL_BACKOFF as _DEFAULT_INITIAL_BACKOFF,
Expand All @@ -39,7 +45,12 @@
logger = logging.getLogger(__name__)

# Provider detection order (SPEC.md §2 — Provider Resolution).
# Subscription CLI providers come first: ``claude-code:*`` would otherwise
# match Anthropic's ``claude-`` prefix. They never satisfy the credential
# fallback below, so they are only reachable by explicit prefix.
_PROVIDER_REGISTRY: list[tuple[ProviderConfig, type[LLMProvider]]] = [
(CLAUDE_CODE_CONFIG, ClaudeCodeProvider),
(CODEX_CONFIG, CodexProvider),
(ANTHROPIC_CONFIG, AnthropicProvider),
(GEMINI_CONFIG, GeminiProvider),
(XAI_CONFIG, XAIProvider),
Expand Down Expand Up @@ -152,7 +163,8 @@ def _resolve_provider(self, model: str) -> LLMProvider:
raise LLMError(
"No LLM provider credentials found. Run `althing login` or set "
"ANTHROPIC_API_KEY, GEMINI_API_KEY, XAI_API_KEY, OPENROUTER_API_KEY, "
"or OPENAI_API_KEY.",
"or OPENAI_API_KEY — or use a subscription CLI model "
"(claude-code:<model> / codex:<model>).",
LLMErrorCategory.MISSING_CREDENTIALS,
)

Expand Down
3 changes: 3 additions & 0 deletions src/althing/llm/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
from althing.llm.providers.gemini import GeminiProvider
from althing.llm.providers.openai_compat import OpenAICompatibleProvider
from althing.llm.providers.openrouter import OpenRouterProvider
from althing.llm.providers.subscription_cli import ClaudeCodeProvider, CodexProvider
from althing.llm.providers.xai import XAIProvider

__all__ = [
"AnthropicProvider",
"ClaudeCodeProvider",
"CodexProvider",
"GeminiProvider",
"LLMProvider",
"OpenAICompatibleProvider",
Expand Down
Loading
Loading