# grok-cli — Terminal Coding Agent for Grok API > grok-cli is an open-source terminal coding agent for the Grok API with interactive and headless modes, so you can script tasks or drive a full TUI loop. ## Install Copy the content below into your project: ## Quick Use 1. Install: ```bash curl -fsSL https://raw.githubusercontent.com/superagent-ai/grok-cli/main/install.sh | bash ``` 2. Run interactive mode: ```bash grok ``` 3. Headless one-shot prompt: ```bash grok --prompt "run the tests and summarize failures" ``` ## Intro grok-cli is an open-source terminal coding agent for the Grok API with interactive and headless modes, so you can script tasks or drive a full TUI loop. - **Best for:** developers who want a Grok-powered coding agent with both TUI and scriptable headless runs - **Works with:** curl/bash installer; requires a Grok API key for real use; runs in a project directory - **Setup time:** 10–20 minutes ## Practical Notes - Use headless `--prompt` for automation; use TUI for longer sessions. - Keep prompts task-scoped (1 request = 1 outcome) for predictable runs. ## Two modes: interactive vs headless ### Interactive (TUI) Use interactive mode when you want multi-step reasoning, file browsing, and iterative edits: ```bash grok ``` ### Headless (one-shot) Use headless mode in scripts or CI: ```bash grok --prompt "explain failing tests and propose a minimal fix" ``` ## Practical guardrails - Start by asking for a plan and a dry-run command list (no destructive actions). - For code changes: request a diff-only proposal, then run tests. - Keep secrets out of pasted logs; prefer env vars or config files. ## Suggested use cases - “Run tests and summarize failures” - “Scan the repo and propose refactors” - “Draft a changelog from recent commits” Treat it like a programmable teammate: deterministic inputs → reproducible outputs. ### FAQ **Q: Do I need the Grok API key to install?** A: No. Installation is separate; you need an API key to actually use the agent. **Q: Is headless mode good for CI?** A: Yes. It’s the most repeatable mode for scripted runs. **Q: How do I keep results stable?** A: Keep prompts narrow, ask for diffs, and always run verification commands. ## Source & Thanks > Source: https://github.com/superagent-ai/grok-cli > License: MIT > GitHub stars: 3,027 · forks: 373 --- ## 快速使用 1. 安装: ```bash curl -fsSL https://raw.githubusercontent.com/superagent-ai/grok-cli/main/install.sh | bash ``` 2. 交互模式: ```bash grok ``` 3. Headless 一次性 prompt: ```bash grok --prompt "run the tests and summarize failures" ``` ## 简介 grok-cli 是面向 Grok API 的开源终端编码 agent:支持交互式 TUI 与 headless 模式,既能写脚本跑任务,也能做完整的终端 agent 循环并保存会话轨迹与产物。 - **适合谁:** 想用 Grok 做终端编码 agent,同时需要交互 TUI 与脚本化 headless 的开发者 - **可搭配:** curl/bash 安装;实际使用需要 Grok API key;在项目目录中运行 - **准备时间:** 10–20 分钟 ## 实战建议 - 自动化优先用 headless `--prompt`;长任务用 TUI 会话更合适。 - Prompt 尽量任务化(一次请求一个结果),更可控。 ## 两种模式:交互 vs headless ### 交互模式(TUI) 适合多轮推理、浏览文件、反复迭代修改: ```bash grok ``` ### Headless(一次性) 适合脚本或 CI: ```bash grok --prompt "explain failing tests and propose a minimal fix" ``` ## 实战护栏(强烈建议) - 先让它输出计划与要跑的命令清单(避免误操作)。 - 改代码时:先要“只给 diff”,再跑测试验证。 - 日志里不要粘贴敏感信息;用环境变量或配置文件传递。 ## 典型用例 - “跑测试并总结失败原因” - “扫描仓库并给出重构建议” - “根据最近提交草拟 changelog” 把它当作“可编程队友”:输入可控 → 输出可复现。 ### FAQ **安装需要 Grok API key 吗?** 答:不需要。安装和使用分开;真正运行 agent 需要 API key。 **Headless 适合 CI 吗?** 答:适合。它是最可复现、最脚本化的模式。 **如何让结果更稳定?** 答:Prompt 要窄、先给 diff、并始终跑验证命令。 ## 来源与感谢 > Source: https://github.com/superagent-ai/grok-cli > License: MIT > GitHub stars: 3,027 · forks: 373 --- Source: https://tokrepo.com/en/workflows/grok-cli-terminal-coding-agent-for-grok-api Author: Agent Toolkit