2 2
3# Grok Build3# Grok Build
4 4
5Grok Build is a powerful and extensible coding agent. Use it via an interactive TUI, headlessly in scripts or bots, or through the Agent Client Protocol (ACP) in other apps.5Grok Build is a coding agent for the terminal. Use it as an interactive TUI, headlessly in scripts or bots, or through the Agent Client Protocol (ACP) in other apps.
6
7The TUI provides a rich, mouse-interactive, fullscreen experience for coding with agents.
8 6
9## Install7## Install
10 8
9Run the command for your system. It downloads the latest stable release and adds `grok` to your `PATH`:
10
11```bash customLanguage="bashMacLinux"11```bash customLanguage="bashMacLinux"
12curl -fsSL https://x.ai/cli/install.sh | bash12curl -fsSL https://x.ai/cli/install.sh | bash
13```13```
16irm https://x.ai/cli/install.ps1 | iex16irm https://x.ai/cli/install.ps1 | iex
17```17```
18 18
19## Start an interactive session19## Run Grok
20
21Start Grok in your project folder:
20 22
21```bash customLanguage="bash"23```bash customLanguage="bash"
22cd your-project24cd your-project
23grok25grok
24```26```
25 27
26On first launch, Grok opens a browser for authentication. In non-browser environments, use an API key:28If your shell can't find `grok`, open a new terminal.
27 29
28```bash customLanguage="bash"30On first launch, Grok opens your browser to sign in, and keeps you signed in after that. If there is no browser, use another method:
29export XAI_API_KEY="xai-..."
30grok
31```
32 31
33Useful first prompts:32| Where you're working | Sign in with | Command |
33| -------------------- | ------------ | ------- |
34| Your own machine | Browser | `grok` |
35| SSH or a remote machine | Device code | `grok login --device-auth` |
36| CI and scripts | API key | `export XAI_API_KEY="xai-..."` |
34 37
35```text38For every sign-in option, see [Authentication](/build/enterprise#authentication).
36Explain this repo.
37@src/main.rs Walk me through this file.
38```
39
40## Run headlessly
41
42```bash customLanguage="bash"
43grok -p "Explain this codebase"
44grok -p "Explain the architecture" --output-format streaming-json
45```
46 39
47Headless usage is ideal for scripts, automations, or integration into other apps.40## Ask your first question
48 41
49## Custom models42At the prompt, start with a question that works in any repository:
50
51Grok supports any custom model. Add it to your user-level config file, `~/.grok/config.toml` (on Windows, `%USERPROFILE%\.grok\config.toml`):
52 43
53```text44```text
54[model.my-model]45Explain this repo.
55model = "model-id"
56base_url = "https://api.example.com/v1"
57name = "Display Name"
58env_key = "API_KEY"
59
60[models]
61default = "my-model"
62```46```
63 47
64After updating `~/.grok/config.toml`, use `grok inspect` to see what Grok discovered in the current directory, including config sources, instructions, skills, plugins, hooks, and MCP servers, then pick the model in headless mode or in the TUI:48Grok reads the files it needs, shows each step as it runs, and answers with a summary of the codebase. Once you see that, the install, sign-in and project are all working.
65
66```bash customLanguage="bash"
67grok inspect
68grok -p "Hello" -m my-model
69```
70 49
71You can also switch inside the TUI with `/model <name>`.50Then point it at a file with `@`:
72 51
73## Use Grok 4.7 on the API52```text
53@src/main.rs Walk me through this file.
54```
74 55
75[`grok-4.7`](/developers/models/grok-4.7), SpaceXSI's latest model, is available directly on the xAI API. Drop it into your own agent loop, IDE integration, or coding tool.56In a session, `/usage` shows your credit usage.
76 57
77```javascript customLanguage="javascriptAISDK"58## Run headlessly
78import { xai } from '@ai-sdk/xai';
79import { generateText } from 'ai';
80 59
81const { text } = await generateText({60Headless mode is ideal for scripts, automations, or integration into other apps:
82 model: xai.responses('grok-4.7'),
83 prompt: 'Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}',
84});
85 61
86console.log(text);62```bash customLanguage="bash"
63grok -p "Explain this codebase"
64grok -p "Explain the architecture" --output-format streaming-json
87```65```
88 66
89```python customLanguage="pythonOpenAISDK"67For its flags and output formats, see [Headless and Scripting](/build/cli/headless-scripting).
90from openai import OpenAI
91 68
92client = OpenAI(69## Update
93 api_key="<YOUR_XAI_API_KEY_HERE>",
94 base_url="https://api.x.ai/v1",
95)
96 70
97response = client.responses.create(71One command updates Grok for both interactive and headless use:
98 model="grok-4.7",
99 input="Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}",
100)
101
102print(response.output_text)
103```
104 72
105```bash customLanguage="bash"73```bash customLanguage="bash"
106curl https://api.x.ai/v1/responses \74grok update
107 -H "Authorization: Bearer $XAI_API_KEY" \
108 -H "Content-Type: application/json" \
109 -d '{
110 "model": "grok-4.7",
111 "input": "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"
112 }'
113```75```
114 76
115```python customLanguage="pythonXAI"77To see what each release changed, read the [Changelog](https://x.ai/changelog/build).
116import os
117from xai_sdk import Client
118from xai_sdk.chat import user
119 78
120client = Client(api_key=os.getenv("XAI_API_KEY"))79## Requirements
121 80
122chat = client.chat.create(model="grok-4.7")81* macOS (Apple silicon or Intel) or Linux (x86\_64 or arm64). On Windows, use PowerShell, Git Bash or WSL.
123chat.append(user("Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"))82* A terminal, and a project folder to run Grok in.
124 83* A SpaceXSI account to sign in with, or an API key.
125print(chat.sample().content)
126```
127 84
128## Features85## Features
129 86
130* [Status Line](/build/features/status-line). Live session context in a row at the bottom of the TUI.87* [Plugins, skills](/build/features/skills-plugins-marketplaces) and [MCP servers](/build/features/mcp-servers). Extend what Grok can do.
131* [Skills, Plugins & Marketplaces](/build/features/skills-plugins-marketplaces)88* [Agent Dashboard](/build/features/dashboard). Every session at a glance, and which agents need input.
132* [Modes and Commands](/build/modes-and-commands)89* [Modes and Commands](/build/modes-and-commands). Switch modes with Shift+Tab and use slash commands.
90* [CLI Reference](/build/cli/reference). The `grok` subcommands and common flags.
133 91
134## Next92## Next
135 93
136* [Headless & Scripting](/build/cli/headless-scripting)94* [Custom Models](/build/settings/reference#modelid). Use any model through `~/.grok/config.toml`.
95* [Grok 4.7 on the API](/developers/grok-4-7#using-the-api). Call the model from your own agent or tool.
137* [Enterprise Deployments](/build/enterprise)96* [Enterprise Deployments](/build/enterprise)
138* [Grok Bot](/grok-bot/overview) — AI teammates on a cloud computer97* [Grok Bot](/grok-bot/overview) — AI teammates on a cloud computer