> ## Documentation Index
> Fetch the complete documentation index at: https://opencompass-docs-preview-pr-335-0.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

`claude_code` Harness 在 Benchmark 准备好的工作区中以非交互方式运行 [Claude Code](https://claude.com/product/claude-code)。

## 工作原理

* **准备 Claude Code CLI。** 可选 Runtime Capsule 可先提供通用工具链，随后 Harness 仍按 `install_strategy` 使用镜像内 CLI、按需安装或上传可执行文件。
* **配置并运行。** Harness 写入当前会话使用的 Anthropic 兼容 model 配置，并以无头模式运行 Claude Code。Recipe 可以传入仓库外的设置文件，避免凭据进入最终补丁。
* **回收结果。** Claude Code 的 JSON 记录会被规整为轨迹、最终回答和执行状态，并返回 `RunResult`。

## 参数

通过 `--harness-params '{...}'` 传入 Harness 参数。这里只列出通常需要调整的安装与 agent 行为，其余路径和上传配置使用内置默认值。

### 参数总览

<div style={{ overflowX: 'auto' }}>
  <table style={{ minWidth: '1040px', width: '100%' }}>
    <thead>
      <tr><th style={{ whiteSpace: 'nowrap' }}>参数</th><th style={{ whiteSpace: 'nowrap' }}>类型</th><th style={{ whiteSpace: 'nowrap' }}>默认值</th><th style={{ whiteSpace: 'nowrap' }}>可选值 / 取值</th><th>说明</th></tr>
    </thead>

    <tbody>
      <tr><td style={{ whiteSpace: 'nowrap' }}><code>install\_strategy</code></td><td style={{ whiteSpace: 'nowrap' }}>字符串</td><td><code>install\_if\_missing</code></td><td><code>preinstalled</code> / <code>install\_if\_missing</code> / <code>upload</code></td><td>准备 Claude Code 的方式。</td></tr>
      <tr><td style={{ whiteSpace: 'nowrap' }}><code>install\_command</code></td><td style={{ whiteSpace: 'nowrap' }}>字符串</td><td><code>npm install -g @anthropic-ai/claude-code</code></td><td>命令</td><td>缺少 Claude Code 时执行的安装命令；版本也在此指定。</td></tr>
      <tr><td style={{ whiteSpace: 'nowrap' }}><code>setup\_capsule\_tag</code></td><td style={{ whiteSpace: 'nowrap' }}>字符串</td><td>未设置</td><td><code>node24-v1</code></td><td>在安装 Claude Code 前注入可选的预定义工具链 Capsule。</td></tr>
      <tr><td style={{ whiteSpace: 'nowrap' }}><code>max\_turns</code></td><td style={{ whiteSpace: 'nowrap' }}>整数</td><td><code>400</code></td><td>整数 ≥ 1</td><td>单个任务的最大 agent 轮数。</td></tr>
      <tr><td style={{ whiteSpace: 'nowrap' }}><code>max\_output\_tokens</code></td><td style={{ whiteSpace: 'nowrap' }}>整数 / 空值</td><td>未设置</td><td>整数 ≥ 1 或 <code>null</code></td><td>单次响应最大输出词元；未设置时沿用 Claude Code 默认值。</td></tr>
      <tr><td style={{ whiteSpace: 'nowrap' }}><code>append\_system\_prompt</code></td><td style={{ whiteSpace: 'nowrap' }}>字符串</td><td>未设置</td><td>任意字符串</td><td>追加给 Claude Code 的额外系统提示词。</td></tr>
      <tr><td style={{ whiteSpace: 'nowrap' }}><code>dangerously\_skip\_permissions</code></td><td style={{ whiteSpace: 'nowrap' }}>布尔值</td><td><code>true</code></td><td><code>true</code> / <code>false</code></td><td>是否传 <code>--dangerously-skip-permissions</code>。仅在需要保留 Claude Code 权限确认时设为 <code>false</code>。</td></tr>
    </tbody>
  </table>
</div>

### model API

Claude Code 需要 Anthropic 兼容的 `--model-base-url` 与 `--model-api-key`，并使用 `--model-api-protocol anthropic`。基础 URL 以 `/v1` 结尾时，Harness 会自动去除该后缀，再写入 Claude Code 配置。

## 运行示例

<Tabs>
  <Tab title="默认配置">
    使用默认安装与 agent 配置运行。

    ```bash theme={"system"}
    agentcompass run \
      swebench_verified \
      claude_code \
      "$MODEL_NAME" \
      --env docker \
      --model-base-url "$MODEL_BASE_URL" \
      --model-api-key "$MODEL_API_KEY" \
      --model-api-protocol anthropic
    ```
  </Tab>

  <Tab title="自定义参数">
    调整轮数、单次输出上限和追加系统提示词。

    ```bash theme={"system"}
    agentcompass run \
      swebench_verified \
      claude_code \
      "$MODEL_NAME" \
      --env docker \
      --harness-params '{
        "max_turns": 80,
        "max_output_tokens": 16384,
        "append_system_prompt": "Prefer minimal diffs."
      }' \
      --model-base-url "$MODEL_BASE_URL" \
      --model-api-key "$MODEL_API_KEY" \
      --model-api-protocol anthropic
    ```
  </Tab>

  <Tab title="Runtime Capsule">
    在没有兼容 Node/npm/glibc 的 Environment 中使用预构建 Capsule。

    ```bash theme={"system"}
    agentcompass run \
      swebench_verified \
      claude_code \
      "$MODEL_NAME" \
      --env docker \
      --harness-params '{
        "install_strategy": "install_if_missing",
        "install_command": "npm install -g @anthropic-ai/claude-code@<version>",
        "setup_capsule_tag": "node24-v1"
      }' \
      --model-base-url "$MODEL_BASE_URL" \
      --model-api-key "$MODEL_API_KEY" \
      --model-api-protocol anthropic
    ```

    构建与分发方式见 [Runtime Capsule](/zh/developer_guide/architecture/runtime_capsules)。
  </Tab>
</Tabs>

## 输出

Harness 为每个任务返回 `RunResult`：轨迹、最终回答与执行状态。单任务详情与聚合指标由 Benchmark 写入 [运行目录](/zh/user_guide/other_features/results/overview#目录布局)（详见 [结果](/zh/user_guide/other_features/results/overview)）。

任务执行 deadline 统一通过 `--execution-params` 中的 `run_timeout_seconds` 和 `run_timeout_multiplier` 设置。详见[阶段超时](/zh/user_guide/using_agentcompass/run_controls#设置合适的超时)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.