> ## Documentation Index
> Fetch the complete documentation index at: https://agent-compass.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。** 若镜像中不存在 `claude`，Harness 会按 `install_strategy` 执行 `install_command`。
* **配置并运行。** 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>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>timeout</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>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>
</Tabs>

## 输出

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