claude_cli_server#
Inference server backed by the Claude Code CLI in headless mode.
Satisfies the same call contract as InferenceServer
so it can be dropped into config.inference via hydra _target_ with no other changes:
- inference:
_target_: kernelfoundry.algorithm.claude_cli_server.ClaudeCLIServer model_name: opus num_completions: 1
Why this exists: the stock InferenceServer reads os.environ["OPENAI_API_KEY"] (or the
Anthropic equivalent) at construction, so every run is billed against a metered API key. The
claude CLI authenticates against a Claude subscription instead, and -p/--print makes it
non-interactive.
Classes
|
Generate completions by invoking |
Exceptions
Raised when the CLI cannot be run or returns something unusable. |
- exception kernelfoundry.algorithm.claude_cli_server.ClaudeCLIError[source]#
Raised when the CLI cannot be run or returns something unusable.
- class kernelfoundry.algorithm.claude_cli_server.ClaudeCLIServer(model_name: str | None = None, num_completions: int = 1, max_tokens: int | None = None, temperature: float | None = None, timeout: int = 900, max_retry: int = 3, claude_exe: str = 'claude', disallow_tools: bool = True, max_turns: int = 8, effort: str | None = None, verbose: bool = False, **kwargs)[source]#
Generate completions by invoking
claude -pas a subprocess.- Parameters:
model_name – Value for
--model. An alias such asopusorsonnettracks the latest model; a dated id pins one.Noneleaves the CLI default.num_completions – Completions to return per call. The CLI returns one response per invocation, so N completions cost N sequential invocations.
max_tokens – Recorded for reporting only. The CLI exposes no output-token ceiling, so unlike the API path this cannot truncate a response.
temperature – Accepted and ignored, because the CLI exposes no sampling controls. Diversity across branches comes from separate sessions and from the differing prompts the evolutionary loop constructs, not from temperature.
timeout – Per-invocation timeout in seconds.
max_retry – Retries per completion before giving up.
claude_exe – Path or name of the CLI binary.
disallow_tools – Run as a pure text completion with no tool use. Leave this on for the evolutionary loop, which wants a kernel back rather than an agent that edits files.
verbose – Log each invocation.
- __init__(model_name: str | None = None, num_completions: int = 1, max_tokens: int | None = None, temperature: float | None = None, timeout: int = 900, max_retry: int = 3, claude_exe: str = 'claude', disallow_tools: bool = True, max_turns: int = 8, effort: str | None = None, verbose: bool = False, **kwargs)[source]#
- __call__(messages: list[dict], single_question: bool = False, **kwargs)[source]#
Return
(outputs, metadata)matching InferenceServer.- Parameters:
messages – OpenAI-style
{"role", "content"}dicts.single_question – One completion, ignoring
num_completions.
- Returns:
(list[str], dict)where the dict carries model, token counts and the indices of any truncated completions.