当你希望某个任务在不启动全屏 TUI 的情况下完整执行时,使用 interpreter exec

interpreter exec "summarize the changes in the last commit"

可读的最终答案会打印到 stdout。进度和诊断信息使用 stderr,除非你选择 JSON 输出。

输入

将提示作为参数传入:

interpreter exec "find one bug in src/parser.rs"

从 stdin 读取提示:

cat task.md | interpreter exec -

将上下文通过管道传入提示:

git diff | interpreter exec "explain this diff and flag risky changes"

为第一个提示附加图片:

interpreter exec -i screenshot.png "describe the UI problem"

常用标志

标志用途
--json输出换行分隔的 JSON 事件。
--output-schema <file>要求最终答案符合 JSON Schema。
--output-last-message, -o <file>将最终的助手消息写入文件。
`--color alwaysnever
--sandbox <mode>覆盖沙箱模式。
--ask-for-approval <mode>覆盖批准策略。
--profile <name>使用指定的配置文件。
--ephemeral不持久化会话记录。
--skip-git-repo-check允许在非 Git 仓库中运行。
--ignore-user-config跳过本次运行的用户配置。
--ignore-rules跳过 execpolicy 规则。
--verify在退出前额外运行一次完成检查。
--timeout <seconds>在运行期间发送剩余时间提醒。

JSON 事件

自动化场景请使用 --json

interpreter exec --json "list the files this task would touch"

每一行都是一个 JSON 事件,表示进度、工具调用、文件更改、推理摘要或最终消息。

结构化输出

配合 --output-schema 使用模式文件:

{
  "type": "object",
  "properties": {
    "risk": { "type": "string" },
    "recommended_fix": { "type": "string" }
  },
  "required": ["risk", "recommended_fix"]
}
interpreter exec --output-schema schema.json \
  "inspect the current diff and return the highest risk"

恢复 Exec 工作

继续最近的非交互会话:

interpreter exec resume --last "now apply the plan"

或恢复指定的会话 ID:

interpreter exec resume <SESSION_ID> "continue"

添加 --all 可搜索当前工作目录之外的会话。

来自 Exec 的审查

在不打开 TUI 的情况下运行代码审查:

interpreter exec review --uncommitted
interpreter exec review --base main
interpreter exec review --commit abc123

对于自定义审查指令,可传入文本或使用 - 从 stdin 读取。

CI 模式

使用 API Key 认证并保持沙箱范围窄:

- name: Review patch
  env:
    OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
  run: |
    interpreter exec --json --sandbox read-only \
      "review this pull request diff for regressions" \
      < pr.diff > review.jsonl
非交互模式