Skip to main content

agentmux_srv_core/backend/providers/
claude.rs

1// Copyright 2025-2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4use super::{Tier, ProviderConfig, ControllerType};
5
6pub(super) static CLAUDE: ProviderConfig = ProviderConfig {
7    id: "claude",
8    tier: Tier::FirstClass,
9    cli_command: "claude",
10    // Persistent (bidirectional stream-json) + the Agent SDK CONTROL PROTOCOL is
11    // the only way AskUserQuestion (and interactive tool-permission) works headless.
12    // The CLI auto-rejects AskUserQuestion with `Error: Answer questions?` in any
13    // mode UNLESS the driver speaks the control protocol: launch with
14    // `--permission-prompt-tool stdio` (+ a non-bypass `--permission-mode`), then
15    // answer the CLI's `can_use_tool` control_request with a control_response
16    // carrying `updatedInput.answers`. See SPEC_AGENT_CONTROL_PROTOCOL_2026_06_15.md
17    // (§2 captured the exact wire bytes against bundled CLI v2.1.178).
18    //
19    // CRITICAL: `--dangerously-skip-permissions` DISABLES that routing (it bypasses
20    // canUseTool), so it must NOT be in persistent_launch_args. The persistent
21    // controller's ControlChannel auto-allows ordinary tools to preserve today's
22    // yolo UX; only AskUserQuestion is surfaced to the user.
23    controller_type: ControllerType::Persistent,
24    app_server: None,
25    launch_args: &[
26        "-p",
27        "--output-format",
28        "stream-json",
29        "--verbose",
30        "--include-partial-messages",
31        "--dangerously-skip-permissions",
32        // Moves per-machine sections (cwd, env info, memory paths, git status)
33        // out of the system prompt into the first user message, so the system
34        // prompt stays byte-identical across agents/machines and the 1hr
35        // prompt cache (docs/analysis/TOKEN_TAX_ANALYSIS_2026_06_19.md) isn't
36        // invalidated by per-instance dynamic content. No-op if the default
37        // system prompt is overridden — not guaranteed here, since
38        // `agent.provider_flags` (app_api/agent_open.rs) is a free-form
39        // user-configurable string appended after these args; a user-set
40        // `--system-prompt` there would silently no-op this flag. Harmless
41        // either way (that's the flag's own documented ignore-if-overridden
42        // behavior), just not something this hardcoded default can prevent.
43        // reagent P2 on PR #1964.
44        "--exclude-dynamic-system-prompt-sections",
45    ],
46    persistent_launch_args: Some(&[
47        "--input-format",
48        "stream-json",
49        "--output-format",
50        "stream-json",
51        "--verbose",
52        "--include-partial-messages",
53        "--exclude-dynamic-system-prompt-sections",
54        // Replays the user turns the CLI takes in, with their typed origin, so a message
55        // another session sends this agent shows up in the stream (`backend::cli_native`).
56        "--replay-user-messages",
57        // Enable the control protocol so the sidecar can answer can_use_tool /
58        // AskUserQuestion. Replaces --dangerously-skip-permissions (which bypasses it).
59        "--permission-prompt-tool",
60        "stdio",
61        "--permission-mode",
62        "default",
63    ]),
64    resume_flag: Some("--resume"),
65    session_id_field: "session_id",
66    styled_output_format: "claude-stream-json",
67    auth_config_dir_env_var: "CLAUDE_CONFIG_DIR",
68    auth_dir_name: "claude",
69    history_native_subdir: Some("projects"),
70    auth_extra_env: &[],
71    unset_env: &["CLAUDECODE"],
72    npm_package: "@anthropic-ai/claude-code",
73    // Keep in sync with the frontend catalog's `pinnedVersion`, enforced by
74    // frontend/app/view/agent/providers/pin-consistency.test.ts. Host installs and
75    // the container agents' first-start install both use this version.
76    pinned_version: "2.1.321",
77    // Documented Claude Code behavior: redirects the CLI at a non-Anthropic
78    // (or proxied) backend — Bedrock, Vertex, OpenRouter, a custom proxy.
79    base_url_env_var: Some("ANTHROPIC_BASE_URL"),
80    supported_vendors: &["anthropic"],
81    startup_instructions_filename: Some("CLAUDE.md"),
82    // Read set = the write target. Claude Code auto-discovers CLAUDE.md;
83    // `.claude/AGENTMUX_MEMORY.md` is reached only through an @import line
84    // AgentMux itself adds (SPEC_CLAUDE_MD_OWNERSHIP_PROTECTION_2026_08_22.md),
85    // so it is not a native source. Nested/parent CLAUDE.md discovery is
86    // real but out of scope here: this field is working-directory-relative.
87    native_instruction_sources: &["CLAUDE.md"],
88    native_instruction_dirs: &[],
89};