无头模式
grok -p "Your prompt here"常用标志
| 标志 | 功能 |
|---|---|
-p, --single <PROMPT> | 发送单个提示 |
-m, --model <MODEL> | 选择模型 |
-s, --session-id <ID> | 创建或恢复命名无头会话 |
-r, --resume <ID> | 恢复现有会话 |
-c, --continue | 继续当前目录最近的会话 |
--cwd <PATH> | 设置工作目录 |
--output-format <FMT> | 选择 plain、json 或 streaming-json |
--always-approve | 自动批准工具执行 |
--no-alt-screen | 内联运行(不接管全屏 TUI) |
无头会话(通过 --session-id、--resume、--continue)存储在 ~/.grok/sessions 中。
提示:在脚本、CI 或其他自动化环境中使用无头模式或 ACP 时, 传入 --no-auto-update 跳过后台更新检查。也可在 ~/.grok/config.toml 中 设置 [cli] auto_update = false 持久化禁用。
输出格式
plain— 人类可读文本json— 最终输出一个 JSON 对象streaming-json— 换行分隔的 JSON 事件流
grok -p "List TODO comments" --output-format json
grok -p "Explain the architecture" --output-format streaming-json流式 JSON 在事件到达时输出增量事件。
ACP(Agent Client Protocol)
当你需要 IDE 或工具集成而非终端会话时使用 ACP:
grok agent stdio这会将 Grok 作为 ACP 智能体通过 stdin/stdout 上的 JSON-RPC 运行。session/prompt 返回完成元数据;助手文本本身以 session/update 块的形式到达。