An open-source AI coding agent powered by Grok, built with Bun and OpenTUI.
$git clone https://github.com/superagent-ai/grok-cliInstalls into the current project.
Install grok-cli by running `git clone https://github.com/superagent-ai/grok-cli`, then use it for the current task and follow its documentation at https://github.com/superagent-ai/grok-cli.
| 1 | # grok-cli: an open-source coding agent for the Grok API |
| 2 | |
| 3 | [](https://github.com/superagent-ai/grok-cli/actions/workflows/typecheck.yml) |
| 4 | [](https://www.npmjs.com/package/grok-dev) |
| 5 | [](./LICENSE) |
| 6 | [](https://www.typescriptlang.org/) |
| 7 | [](https://bun.sh/) |
| 8 | |
| 9 | > **Disclaimer:** This project is community-built, open-source, and **not affiliated with, endorsed by, or sponsored by xAI Corp.** "Grok" is a trademark of xAI Corp. This tool uses the publicly available Grok API. |
| 10 | |
| 11 | An open-source terminal coding agent that connects to xAI’s Grok API — real-time **X search**, **web search**, the full Grok model lineup, **sub-agents on by default**, **remote control via Telegram** (pair once, drive the agent from your phone while the CLI runs), and a terminal UI built with **Bun** and **OpenTUI**. |
| 12 | |
| 13 | [https://github.com/user-attachments/assets/7ca4f6df-50ca-4e9c-91b2-d4abad5c66cb](https://github.com/user-attachments/assets/7ca4f6df-50ca-4e9c-91b2-d4abad5c66cb) |
| 14 | |
| 15 | --- |
| 16 | |
| 17 | ## Install |
| 18 | |
| 19 | ```bash |
| 20 | curl -fsSL https://raw.githubusercontent.com/superagent-ai/grok-cli/main/install.sh | bash |
| 21 | ``` |
| 22 | |
| 23 | **Alternative installs** (requires Bun on PATH): |
| 24 | |
| 25 | ```bash |
| 26 | bun add -g grok-dev |
| 27 | ``` |
| 28 | |
| 29 | **Self-management** (script-installed only): |
| 30 | |
| 31 | ```bash |
| 32 | grok update |
| 33 | grok uninstall |
| 34 | grok uninstall --dry-run |
| 35 | grok uninstall --keep-config |
| 36 | ``` |
| 37 | |
| 38 | **Prerequisites:** a **Grok API key** from [x.ai](https://x.ai) and a modern terminal emulator for the interactive OpenTUI experience. Headless `--prompt` mode does not depend on terminal UI support. If you want host desktop automation via the built-in computer sub-agent, also enable **Accessibility** permission for your terminal app on macOS. |
| 39 | |
| 40 | --- |
| 41 | |
| 42 | ## Run it |
| 43 | |
| 44 | **Interactive (default)** — launches the OpenTUI coding agent: |
| 45 | |
| 46 | ```bash |
| 47 | grok |
| 48 | ``` |
| 49 | |
| 50 | ### Supported terminals |
| 51 | |
| 52 | For the most reliable interactive OpenTUI experience, use a modern terminal emulator. We currently document and recommend: |
| 53 | |
| 54 | - **WezTerm** (cross-platform) |
| 55 | - **Alacritty** (cross-platform) |
| 56 | - **Ghostty** (macOS and Linux) |
| 57 | - **Kitty** (macOS and Linux) |
| 58 | |
| 59 | Other modern terminals may work, but these are the terminal apps we currently recommend and document for interactive use. |
| 60 | |
| 61 | **Pick a project directory:** |
| 62 | |
| 63 | ```bash |
| 64 | grok -d /path/to/your/repo |
| 65 | ``` |
| 66 | |
| 67 | **Headless** — one prompt, then exit (scripts, CI, automation): |
| 68 | |
| 69 | ```bash |
| 70 | grok --prompt "run the test suite and summarize failures" |
| 71 | grok -p "show me package.json" --directory /path/to/project |
| 72 | grok --prompt "refactor X" --max-tool-rounds 30 |
| 73 | grok --prompt "summarize the repo state" --format json |
| 74 | grok --prompt "review the repo overnight" --batch-api |
| 75 | grok --verify |
| 76 | ``` |
| 77 | |
| 78 | `--batch-api` uses xAI's Batch API for lower-cost unattended runs. It is a good |
| 79 | fit for scripts, CI, schedules, and other non-interactive workflows where a |
| 80 | delayed result is fine. |
| 81 | |
| 82 | **Continue a saved session:** |
| 83 | |
| 84 | ```bash |
| 85 | grok --session latest |
| 86 | grok -s <session-id> |
| 87 | ``` |
| 88 | |
| 89 | Works in interactive mode too—same flag. |
| 90 | |
| 91 | **Structured headless output:** |
| 92 | |
| 93 | ```bash |
| 94 | grok --prompt "summarize the repo state" --format json |
| 95 | ``` |
| 96 | |
| 97 | `--format json` emits a newline-delimited JSON event stream instead of the |
| 98 | default human-readable text output. Events are semantic, step-level records such |
| 99 | as `step_start`, `text`, `tool_use`, `step_finish`, and `error`. |
| 100 | |
| 101 | ### Computer sub-agent |
| 102 | |
| 103 | Grok ships a built-in `**computer**` sub-agent backed by `[agent-desktop](https://github.com/lahfir/agent-desktop)` for host desktop automation on macOS. |
| 104 | |
| 105 | Ask for it in natural language, for example: |
| 106 | |
| 107 | ```bash |
| 108 | grok "Use the computer sub-agent to take a screenshot of my host desktop and tell me what is open." |
| 109 | grok "Use the computer sub-agent to launch Google Chrome, snapshot the UI, and |