1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! The Claude Code command line tool.
//!
//! Signs in on this machine and sends every prompt to Anthropic, which is why its reach is
//! [`crate::Reach::LocalCli`] rather than self hosted: the credential is local and the data
//! is not.
use crate;
use Duration;
/// The program this preset runs.
pub const PROGRAM: &str = "claude";
/// What `claude --output-format json` prints.
///
/// **Checked against a recorded run**, not against the documentation. `claude 2.1.196`, on
/// 2026-08-31, printed an envelope kept in this repository at
/// `tests/recorded/claude-code.json`, and `tests/what_a_command_line_tool_prints.rs` holds
/// this preset to it.
///
/// The answer is at `/result` and the usage at `/usage`, spelled the way Anthropic spells it
/// everywhere else. The recorded run settles the question that matters about those names:
/// `input_tokens` there was 4685 with `cache_creation_input_tokens` at 20208 beside it, so
/// it is the **uncached remainder** and not the whole prompt, which is what
/// [`crate::Usage::input_tokens`] means. Getting that backwards produces a number that looks
/// right and is not.
///
/// `/stop_reason` is read because the recorded run has one. Before that it was not, and
/// every reply from this tool came back [`crate::StopReason::Other`], which is not
/// [complete](crate::StopReason::is_complete): a caller asking whether an answer finished was
/// told "no" for every call it ever made.
///
/// The envelope also carries `total_cost_usd`, which nothing here reads. There is nowhere in
/// [`crate::ChatResponse`] to put a cost a tool worked out itself, and inventing one is a
/// larger decision than a preset.
/// A provider that runs the Claude Code tool.
///
/// JSON mode, deliberately. In plain mode the whole document is the answer and the call
/// reports as unmeasured, which every cost report reads as free.
///
/// It knows no models until you name them. A command line tool cannot be asked what it
/// serves, so a provider that answered for every name would turn a typo into a real model.
///
/// [`llmr::Provider::validate`](crate::Provider::validate) probes with `--version`, which
/// establishes that the tool is installed and nothing about the login inside it. That is all
/// this tool answers for free, and a `Ready` from here should be read as no more than that.
///
/// ```no_run
/// use llmr::providers::anthropic::cli;
/// use llmr::{ChatRequest, Message, Provider};
/// use std::time::Duration;
///
/// # async fn example() -> llmr::Result<()> {
/// let claude = cli::provider(Duration::from_secs(300))
/// .serving(["claude-sonnet-5"]);
///
/// let reply = claude
/// .chat(ChatRequest::new("claude-sonnet-5", vec![Message::user("Hello")]))
/// .await?;
/// # Ok(())
/// # }
/// ```