grok-dev 1.0.0-rc1 → 1.0.0-rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules/project-overview.mdc +2 -2
- package/.grok/settings.json +15 -1
- package/README.md +89 -434
- package/dist/agent/agent.d.ts +42 -3
- package/dist/agent/agent.js +294 -127
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/compaction.d.ts +35 -0
- package/dist/agent/compaction.js +364 -0
- package/dist/agent/compaction.js.map +1 -0
- package/dist/agent/compaction.test.d.ts +1 -0
- package/dist/agent/compaction.test.js.map +1 -0
- package/dist/headless/output.d.ts +67 -0
- package/dist/headless/output.js +176 -0
- package/dist/headless/output.js.map +1 -0
- package/dist/headless/output.test.d.ts +1 -0
- package/dist/headless/output.test.js.map +1 -0
- package/dist/index.js +38 -33
- package/dist/index.js.map +1 -1
- package/dist/mcp/catalog.d.ts +10 -0
- package/dist/mcp/catalog.js +97 -0
- package/dist/mcp/catalog.js.map +1 -0
- package/dist/mcp/parse-headers.d.ts +2 -0
- package/dist/mcp/parse-headers.js +33 -0
- package/dist/mcp/parse-headers.js.map +1 -0
- package/dist/mcp/parse-headers.test.d.ts +1 -0
- package/dist/mcp/parse-headers.test.js.map +1 -0
- package/dist/mcp/runtime.d.ts +8 -0
- package/dist/mcp/runtime.js +64 -0
- package/dist/mcp/runtime.js.map +1 -0
- package/dist/mcp/validate.d.ts +9 -0
- package/dist/mcp/validate.js +39 -0
- package/dist/mcp/validate.js.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.js +2 -1
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/migrations.js +31 -1
- package/dist/storage/migrations.js.map +1 -1
- package/dist/storage/transcript-view.d.ts +14 -0
- package/dist/storage/transcript-view.js +23 -0
- package/dist/storage/transcript-view.js.map +1 -0
- package/dist/storage/transcript.d.ts +8 -2
- package/dist/storage/transcript.js +72 -18
- package/dist/storage/transcript.js.map +1 -1
- package/dist/telegram/limits.test.d.ts +1 -0
- package/dist/telegram/limits.test.js.map +1 -0
- package/dist/ui/app.js +393 -19
- package/dist/ui/app.js.map +1 -1
- package/dist/ui/mcp-modal-types.d.ts +24 -0
- package/dist/ui/mcp-modal-types.js +13 -0
- package/dist/ui/mcp-modal-types.js.map +1 -0
- package/dist/ui/mcp-modal.d.ts +33 -0
- package/dist/ui/mcp-modal.js +94 -0
- package/dist/ui/mcp-modal.js.map +1 -0
- package/dist/utils/instructions.js +0 -8
- package/dist/utils/instructions.js.map +1 -1
- package/dist/utils/instructions.test.d.ts +1 -0
- package/dist/utils/instructions.test.js.map +1 -0
- package/dist/utils/settings.d.ts +19 -0
- package/dist/utils/settings.js +15 -0
- package/dist/utils/settings.js.map +1 -1
- package/package.json +7 -2
|
@@ -37,7 +37,7 @@ src/
|
|
|
37
37
|
├── utils/
|
|
38
38
|
│ ├── settings.ts # User and project settings
|
|
39
39
|
│ ├── git-root.ts # Resolve git repository root for AGENTS.md discovery
|
|
40
|
-
│ └── instructions.ts # AGENTS.md (ecosystem)
|
|
40
|
+
│ └── instructions.ts # AGENTS.md (ecosystem) custom instructions
|
|
41
41
|
└── types/
|
|
42
42
|
└── index.ts # Shared TypeScript types
|
|
43
43
|
```
|
|
@@ -48,7 +48,7 @@ src/
|
|
|
48
48
|
- **Bash-only tools**: The agent uses bash for everything (file editing, searching, git, builds, etc.).
|
|
49
49
|
- **X Search & Web Search**: Integrated via the xAI Responses API for real-time information.
|
|
50
50
|
- **Settings hierarchy**: Environment variables → User-level (`~/.grok/user-settings.json`) → Project-level (`.grok/settings.json`).
|
|
51
|
-
- **Custom instructions**: `~/.grok/AGENTS.md`, then `AGENTS.override.md` / `AGENTS.md` per directory from git root through the workspace cwd (Codex-style merge)
|
|
51
|
+
- **Custom instructions**: `~/.grok/AGENTS.md`, then `AGENTS.override.md` / `AGENTS.md` per directory from git root through the workspace cwd (Codex-style merge).
|
|
52
52
|
- **ESM only**: The project uses `"type": "module"` — all imports use `.js` extensions for compiled output.
|
|
53
53
|
|
|
54
54
|
## Latest Grok Models
|
package/.grok/settings.json
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"model": "grok-code-fast-1"
|
|
2
|
+
"model": "grok-code-fast-1",
|
|
3
|
+
"mcpServers": {
|
|
4
|
+
"github": {
|
|
5
|
+
"name": "GitHub",
|
|
6
|
+
"transport": {
|
|
7
|
+
"type": "stdio",
|
|
8
|
+
"command": "npx",
|
|
9
|
+
"args": [
|
|
10
|
+
"-y",
|
|
11
|
+
"@modelcontextprotocol/server-github"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"enabled": true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
3
17
|
}
|
package/README.md
CHANGED
|
@@ -1,525 +1,180 @@
|
|
|
1
|
-
# Grok
|
|
1
|
+
# There are many coding agents. **This is Grok’s.**
|
|
2
2
|
|
|
3
|
-
|
|
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/)
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
The rest borrowed from each other. We borrowed from *all of them*, then wired it to **Grok**—real-time **X search**, **web search**, **`grok-code-fast-1`** and 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 that doesn’t feel like it was assembled in a hurry.
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
Open source. Terminal-native. Built with **Bun** and **OpenTUI**. If you want vibes *and* velocity, you’re in the right repo.
|
|
8
12
|
|
|
9
|
-
-
|
|
10
|
-
- **📝 Smart File Operations**: AI automatically uses tools to view, create, and edit files
|
|
11
|
-
- **⚡ Bash Integration**: Execute shell commands through natural conversation
|
|
12
|
-
- **🔧 Automatic Tool Selection**: AI intelligently chooses the right tools for your requests
|
|
13
|
-
- **🚀 Morph Fast Apply**: Optional high-speed code editing at 4,500+ tokens/sec with 98% accuracy
|
|
14
|
-
- **🔌 MCP Tools**: Extend capabilities with Model Context Protocol servers (Linear, GitHub, etc.)
|
|
15
|
-
- **💬 Interactive UI**: Beautiful terminal interface built with Ink
|
|
16
|
-
- **🌍 Global Installation**: Install and use anywhere with `bun add -g @vibe-kit/grok-cli`
|
|
13
|
+
https://github.com/user-attachments/assets/7ca4f6df-50ca-4e9c-91b2-d4abad5c66cb
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
---
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
- Bun 1.0+ (or Node.js 18+ as fallback)
|
|
22
|
-
- Grok API key from X.AI
|
|
23
|
-
- (Optional, Recommended) Morph API key for Fast Apply editing
|
|
17
|
+
## Install
|
|
24
18
|
|
|
25
|
-
### Global Installation (Recommended)
|
|
26
19
|
```bash
|
|
27
|
-
|
|
20
|
+
npm i -g grok-dev
|
|
28
21
|
```
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm install -g @vibe-kit/grok-cli
|
|
33
|
-
```
|
|
23
|
+
The CLI binary is **`grok`** (yes, the package name and the command differ—deal with it).
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
git clone <repository>
|
|
38
|
-
cd grok-cli
|
|
39
|
-
bun install
|
|
40
|
-
bun run build
|
|
41
|
-
bun link
|
|
42
|
-
```
|
|
25
|
+
**Prerequisites:** Node 18+ (for the global install), and a **Grok API key** from [x.ai](https://x.ai).
|
|
43
26
|
|
|
44
|
-
|
|
27
|
+
---
|
|
45
28
|
|
|
46
|
-
|
|
29
|
+
## Run it
|
|
47
30
|
|
|
48
|
-
|
|
31
|
+
**Interactive (default)** — launches the OpenTUI coding agent:
|
|
49
32
|
|
|
50
|
-
**Method 1: Environment Variable**
|
|
51
33
|
```bash
|
|
52
|
-
|
|
34
|
+
grok
|
|
53
35
|
```
|
|
54
36
|
|
|
55
|
-
**
|
|
56
|
-
```bash
|
|
57
|
-
cp .env.example .env
|
|
58
|
-
# Edit .env and add your API key
|
|
59
|
-
```
|
|
37
|
+
**Pick a project directory:**
|
|
60
38
|
|
|
61
|
-
**Method 3: Command Line Flag**
|
|
62
39
|
```bash
|
|
63
|
-
grok
|
|
40
|
+
grok -d /path/to/your/repo
|
|
64
41
|
```
|
|
65
42
|
|
|
66
|
-
**
|
|
67
|
-
Create `~/.grok/user-settings.json`:
|
|
68
|
-
```json
|
|
69
|
-
{
|
|
70
|
-
"apiKey": "your_api_key_here"
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
3. (Optional, Recommended) Get your Morph API key from [Morph Dashboard](https://morphllm.com/dashboard/api-keys)
|
|
75
|
-
|
|
76
|
-
4. Set up your Morph API key for Fast Apply editing (choose one method):
|
|
43
|
+
**Headless** — one prompt, then exit (scripts, CI, automation):
|
|
77
44
|
|
|
78
|
-
**Method 1: Environment Variable**
|
|
79
45
|
```bash
|
|
80
|
-
|
|
46
|
+
grok --prompt "run the test suite and summarize failures"
|
|
47
|
+
grok -p "show me package.json" --directory /path/to/project
|
|
48
|
+
grok --prompt "refactor X" --max-tool-rounds 30
|
|
49
|
+
grok --prompt "summarize the repo state" --format json
|
|
81
50
|
```
|
|
82
51
|
|
|
83
|
-
**
|
|
84
|
-
```bash
|
|
85
|
-
# Add to your .env file
|
|
86
|
-
MORPH_API_KEY=your_morph_api_key_here
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Custom Base URL (Optional)
|
|
90
|
-
|
|
91
|
-
By default, the CLI uses `https://api.x.ai/v1` as the Grok API endpoint. You can configure a custom endpoint if needed (choose one method):
|
|
52
|
+
**Continue a saved session:**
|
|
92
53
|
|
|
93
|
-
**Method 1: Environment Variable**
|
|
94
54
|
```bash
|
|
95
|
-
|
|
55
|
+
grok --session latest
|
|
56
|
+
grok -s <session-id>
|
|
96
57
|
```
|
|
97
58
|
|
|
98
|
-
|
|
99
|
-
```bash
|
|
100
|
-
grok --api-key your_api_key_here --base-url https://your-custom-endpoint.com/v1
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
**Method 3: User Settings File**
|
|
104
|
-
Add to `~/.grok/user-settings.json`:
|
|
105
|
-
```json
|
|
106
|
-
{
|
|
107
|
-
"apiKey": "your_api_key_here",
|
|
108
|
-
"baseURL": "https://your-custom-endpoint.com/v1"
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## Configuration Files
|
|
113
|
-
|
|
114
|
-
Grok CLI uses two types of configuration files to manage settings:
|
|
115
|
-
|
|
116
|
-
### User-Level Settings (`~/.grok/user-settings.json`)
|
|
117
|
-
|
|
118
|
-
This file stores **global settings** that apply across all projects. These settings rarely change and include:
|
|
119
|
-
|
|
120
|
-
- **API Key**: Your Grok API key
|
|
121
|
-
- **Base URL**: Custom API endpoint (if needed)
|
|
122
|
-
- **Default Model**: Your preferred model (e.g., `grok-code-fast-1`)
|
|
123
|
-
- **Available Models**: List of models you can use
|
|
124
|
-
|
|
125
|
-
**Example:**
|
|
126
|
-
```json
|
|
127
|
-
{
|
|
128
|
-
"apiKey": "your_api_key_here",
|
|
129
|
-
"baseURL": "https://api.x.ai/v1",
|
|
130
|
-
"defaultModel": "grok-code-fast-1",
|
|
131
|
-
"models": [
|
|
132
|
-
"grok-code-fast-1",
|
|
133
|
-
"grok-4-latest",
|
|
134
|
-
"grok-3-latest",
|
|
135
|
-
"grok-3-fast",
|
|
136
|
-
"grok-3-mini-fast"
|
|
137
|
-
]
|
|
138
|
-
}
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Telegram (optional)
|
|
142
|
-
|
|
143
|
-
You can pair the CLI with a Telegram bot and send prompts from Telegram while the interactive session is running (similar in spirit to [OpenClaw-style channel pairing](https://docs.openclaw.ai/channels/telegram)).
|
|
144
|
-
|
|
145
|
-
1. Create a bot with [@BotFather](https://t.me/BotFather) and copy the bot token.
|
|
146
|
-
2. Set **`TELEGRAM_BOT_TOKEN`** in the environment, or add **`telegram.botToken`** to `~/.grok/user-settings.json` (the `/remote-control` flow can save it for you).
|
|
147
|
-
3. Start `grok`. If the bot token is already in settings or env, **long polling starts automatically** (no need to open **`/remote-control`** every time). Otherwise run **`/remote-control`** → **Telegram** and paste the token.
|
|
148
|
-
4. In Telegram, open a DM with your bot and send **`/pair`** (only needed once per user until you remove them from `approvedUserIds`).
|
|
149
|
-
5. The first time you pair a Telegram user, enter the **6-character code** in the terminal when prompted. After that, approval is remembered in `user-settings.json`.
|
|
150
|
-
6. **Keep the CLI open** while you use the bot — polling runs in that process.
|
|
59
|
+
Works in interactive mode too—same flag.
|
|
151
60
|
|
|
152
|
-
|
|
61
|
+
**Structured headless output:**
|
|
153
62
|
|
|
154
|
-
**Optional Telegram UX** (in `~/.grok/user-settings.json` under `telegram`):
|
|
155
|
-
|
|
156
|
-
| Key | Values | Default | Description |
|
|
157
|
-
|-----|--------|---------|-------------|
|
|
158
|
-
| `streaming` | `"partial"` \| `"off"` | `"partial"` | **`partial`**: live preview while the model replies (`sendMessage` + throttled `editMessageText`). **`off`**: buffer the full reply, then send (no preview updates). |
|
|
159
|
-
| `typingIndicator` | boolean | `true` | Send `typing` chat actions on an interval while the agent runs. Set `false` to disable. |
|
|
160
|
-
| `nativeDrafts` | boolean | `false` | Reserved for future Bot API `sendMessageDraft` support (private chats); not used yet. |
|
|
161
|
-
|
|
162
|
-
**Example:**
|
|
163
|
-
|
|
164
|
-
```json
|
|
165
|
-
{
|
|
166
|
-
"telegram": {
|
|
167
|
-
"streaming": "partial",
|
|
168
|
-
"typingIndicator": true
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Project-Level Settings (`.grok/settings.json`)
|
|
174
|
-
|
|
175
|
-
This file stores **project-specific settings** in your current working directory. It includes:
|
|
176
|
-
|
|
177
|
-
- **Current Model**: The model currently in use for this project
|
|
178
|
-
- **MCP Servers**: Model Context Protocol server configurations
|
|
179
|
-
|
|
180
|
-
**Example:**
|
|
181
|
-
```json
|
|
182
|
-
{
|
|
183
|
-
"model": "grok-3-fast",
|
|
184
|
-
"mcpServers": {
|
|
185
|
-
"linear": {
|
|
186
|
-
"name": "linear",
|
|
187
|
-
"transport": "stdio",
|
|
188
|
-
"command": "npx",
|
|
189
|
-
"args": ["@linear/mcp-server"]
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### How It Works
|
|
196
|
-
|
|
197
|
-
1. **Global Defaults**: User-level settings provide your default preferences
|
|
198
|
-
2. **Project Override**: Project-level settings override defaults for specific projects
|
|
199
|
-
3. **Directory-Specific**: When you change directories, project settings are loaded automatically
|
|
200
|
-
4. **Fallback Logic**: Project model → User default model → System default (`grok-code-fast-1`)
|
|
201
|
-
|
|
202
|
-
This means you can have different models for different projects while maintaining consistent global settings like your API key.
|
|
203
|
-
|
|
204
|
-
### Using Other API Providers
|
|
205
|
-
|
|
206
|
-
**Important**: Grok CLI uses **OpenAI-compatible APIs**. You can use any provider that implements the OpenAI chat completions standard.
|
|
207
|
-
|
|
208
|
-
**Popular Providers**:
|
|
209
|
-
- **X.AI (Grok)**: `https://api.x.ai/v1` (default)
|
|
210
|
-
- **OpenAI**: `https://api.openai.com/v1`
|
|
211
|
-
- **OpenRouter**: `https://openrouter.ai/api/v1`
|
|
212
|
-
- **Groq**: `https://api.groq.com/openai/v1`
|
|
213
|
-
|
|
214
|
-
**Example with OpenRouter**:
|
|
215
|
-
```json
|
|
216
|
-
{
|
|
217
|
-
"apiKey": "your_openrouter_key",
|
|
218
|
-
"baseURL": "https://openrouter.ai/api/v1",
|
|
219
|
-
"defaultModel": "anthropic/claude-3.5-sonnet",
|
|
220
|
-
"models": [
|
|
221
|
-
"anthropic/claude-3.5-sonnet",
|
|
222
|
-
"openai/gpt-4o",
|
|
223
|
-
"meta-llama/llama-3.1-70b-instruct"
|
|
224
|
-
]
|
|
225
|
-
}
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
## Usage
|
|
229
|
-
|
|
230
|
-
### Interactive Mode
|
|
231
|
-
|
|
232
|
-
Start the conversational AI assistant:
|
|
233
63
|
```bash
|
|
234
|
-
grok
|
|
64
|
+
grok --prompt "summarize the repo state" --format json
|
|
235
65
|
```
|
|
236
66
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
grok -d /path/to/project
|
|
240
|
-
```
|
|
67
|
+
`--format json` emits newline-delimited `StreamChunk` objects instead of the
|
|
68
|
+
default human-readable text stream.
|
|
241
69
|
|
|
242
|
-
|
|
70
|
+
**List Grok models and pricing hints:**
|
|
243
71
|
|
|
244
|
-
Process a single prompt and exit (useful for scripting and automation):
|
|
245
72
|
```bash
|
|
246
|
-
grok
|
|
247
|
-
grok -p "create a new file called example.js with a hello world function"
|
|
248
|
-
grok --prompt "run bun test and show me the results" --directory /path/to/project
|
|
249
|
-
grok --prompt "complex task" --max-tool-rounds 50 # Limit tool usage for faster execution
|
|
73
|
+
grok models
|
|
250
74
|
```
|
|
251
75
|
|
|
252
|
-
|
|
253
|
-
- **CI/CD pipelines**: Automate code analysis and file operations
|
|
254
|
-
- **Scripting**: Integrate AI assistance into shell scripts
|
|
255
|
-
- **Terminal benchmarks**: Perfect for tools like Terminal Bench that need non-interactive execution
|
|
256
|
-
- **Batch processing**: Process multiple prompts programmatically
|
|
257
|
-
|
|
258
|
-
### Tool Execution Control
|
|
259
|
-
|
|
260
|
-
By default, Grok CLI allows up to 400 tool execution rounds to handle complex multi-step tasks. You can control this behavior:
|
|
76
|
+
**Pass an opening message without another prompt:**
|
|
261
77
|
|
|
262
78
|
```bash
|
|
263
|
-
|
|
264
|
-
grok --max-tool-rounds 10 --prompt "show me the current directory"
|
|
265
|
-
|
|
266
|
-
# Increase limit for very complex tasks (use with caution)
|
|
267
|
-
grok --max-tool-rounds 1000 --prompt "comprehensive code refactoring"
|
|
268
|
-
|
|
269
|
-
# Works with all modes
|
|
270
|
-
grok --max-tool-rounds 20 # Interactive mode
|
|
271
|
-
grok git commit-and-push --max-tool-rounds 30 # Git commands
|
|
79
|
+
grok fix the flaky test in src/foo.test.ts
|
|
272
80
|
```
|
|
273
81
|
|
|
274
|
-
|
|
275
|
-
- **Fast responses**: Lower limits (10-50) for simple queries
|
|
276
|
-
- **Complex automation**: Higher limits (500+) for comprehensive tasks
|
|
277
|
-
- **Resource control**: Prevent runaway executions in automated environments
|
|
82
|
+
---
|
|
278
83
|
|
|
279
|
-
|
|
84
|
+
## What you actually get
|
|
280
85
|
|
|
281
|
-
|
|
86
|
+
| Thing | What it means |
|
|
87
|
+
|--------|----------------|
|
|
88
|
+
| **Grok-native** | Defaults tuned for Grok; models like **`grok-code-fast-1`**, **`grok-4-1-fast`**, flagship and fast variants—run `grok models` for the full menu. |
|
|
89
|
+
| **X + web search** | **`search_x`** and **`search_web`** tools—live posts and docs without pretending the internet stopped in 2023. |
|
|
90
|
+
| **Sub-agents (default behavior)** | Foreground **`task`** delegation (e.g. explore vs general) plus background **`delegate`** for read-only deep dives—parallelize like you mean it. |
|
|
91
|
+
| **Remote control** | Pair **Telegram** from the TUI (`/remote-control` → Telegram): DM your bot, **`/pair`**, approve the code in-terminal. Keep the CLI running while you ping it from your phone. |
|
|
92
|
+
| **No “mystery meat” UI** | OpenTUI React terminal UI—fast, keyboard-driven, not whatever glitchy thing you’re thinking of. |
|
|
93
|
+
| **Skills** | Agent Skills under **`.agents/skills/<name>/SKILL.md`** (project) or **`~/.agents/skills/`** (user). Use **`/skills`** in the TUI to list what’s installed. |
|
|
94
|
+
| **MCPs** | Extend with Model Context Protocol servers—configure via **`/mcps`** in the TUI or **`.grok/settings.json`** (`mcpServers`). |
|
|
95
|
+
| **Sessions** | Conversations persist; **`--session latest`** picks up where you left off. |
|
|
96
|
+
| **Headless** | **`--prompt`** / **`-p`** for non-interactive runs—pipe it, script it, bench it. |
|
|
97
|
+
| **Hackable** | TypeScript, clear agent loop, bash-first tools—fork it, shamelessly. |
|
|
282
98
|
|
|
283
|
-
|
|
284
|
-
```bash
|
|
285
|
-
# Use Grok models
|
|
286
|
-
grok --model grok-code-fast-1
|
|
287
|
-
grok --model grok-4-latest
|
|
288
|
-
grok --model grok-3-latest
|
|
289
|
-
grok --model grok-3-fast
|
|
290
|
-
|
|
291
|
-
# Use other models (with appropriate API endpoint)
|
|
292
|
-
grok --model gemini-2.5-pro --base-url https://api-endpoint.com/v1
|
|
293
|
-
grok --model claude-sonnet-4-20250514 --base-url https://api-endpoint.com/v1
|
|
294
|
-
```
|
|
99
|
+
### Coming soon
|
|
295
100
|
|
|
296
|
-
**
|
|
297
|
-
```bash
|
|
298
|
-
export GROK_MODEL=grok-code-fast-1
|
|
299
|
-
grok
|
|
300
|
-
```
|
|
101
|
+
**Autonomous agent testing** (think: sandboxed machine, recorded runs, Replit-style “prove it works”—the kind of thing that makes flaky human QA nervous). Not shipped yet; when it lands, we’ll be insufferable about it.
|
|
301
102
|
|
|
302
|
-
|
|
303
|
-
Add to `~/.grok/user-settings.json`:
|
|
304
|
-
```json
|
|
305
|
-
{
|
|
306
|
-
"apiKey": "your_api_key_here",
|
|
307
|
-
"defaultModel": "grok-code-fast-1"
|
|
308
|
-
}
|
|
309
|
-
```
|
|
103
|
+
---
|
|
310
104
|
|
|
311
|
-
|
|
105
|
+
## API key (pick one)
|
|
312
106
|
|
|
313
|
-
|
|
107
|
+
**Environment (good for CI):**
|
|
314
108
|
|
|
315
109
|
```bash
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
Options:
|
|
319
|
-
-V, --version output the version number
|
|
320
|
-
-d, --directory <dir> set working directory
|
|
321
|
-
-k, --api-key <key> Grok API key (or set GROK_API_KEY env var)
|
|
322
|
-
-u, --base-url <url> Grok API base URL (or set GROK_BASE_URL env var)
|
|
323
|
-
-m, --model <model> AI model to use (e.g., grok-code-fast-1, grok-4-latest) (or set GROK_MODEL env var)
|
|
324
|
-
-p, --prompt <prompt> process a single prompt and exit (headless mode)
|
|
325
|
-
--max-tool-rounds <rounds> maximum number of tool execution rounds (default: 400)
|
|
326
|
-
-h, --help display help for command
|
|
110
|
+
export GROK_API_KEY=your_key_here
|
|
327
111
|
```
|
|
328
112
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
Grok CLI loads markdown instructions from two ecosystems and merges them into the system prompt:
|
|
332
|
-
|
|
333
|
-
1. **[AGENTS.md](https://agents.md/)** — Shared convention used by many coding agents (build commands, tests, repo norms). Grok discovers these files the same way [OpenAI Codex](https://developers.openai.com/codex/guides/agents-md/) does: concatenate segments with blank lines, **broader scope first**, so later segments can refine or override earlier guidance in the combined text.
|
|
334
|
-
2. **Grok-specific** — `.grok/GROK.md` (project) or `~/.grok/GROK.md` (fallback), appended **last** so Grok-only rules win when something conflicts.
|
|
335
|
-
|
|
336
|
-
Instructions are resolved from the CLI **working directory** (canonical path), not only `process.cwd()` of a parent process.
|
|
337
|
-
|
|
338
|
-
#### AGENTS.md (project and global)
|
|
339
|
-
|
|
340
|
-
- **Global:** `~/.grok/AGENTS.md` (if present and non-empty)
|
|
341
|
-
- **Repository:** Starting at the **git repository root** (or only the current directory if you are not inside a repo), Grok walks **down** to your current directory. In each directory it loads **at most one** file:
|
|
342
|
-
- If `AGENTS.override.md` exists in that directory, it is used (and `AGENTS.md` in the same directory is **not** read).
|
|
343
|
-
- Otherwise, if `AGENTS.md` exists, it is used.
|
|
344
|
-
- Empty files are skipped. Nested directories let monorepos ship package-level guidance (e.g. root `AGENTS.md` plus `services/api/AGENTS.md`).
|
|
345
|
-
|
|
346
|
-
Put repository expectations, test commands, and PR conventions in `AGENTS.md` so the same file helps Grok and other tools.
|
|
347
|
-
|
|
348
|
-
#### Grok-specific: `.grok/GROK.md`
|
|
349
|
-
|
|
350
|
-
Create a `.grok/GROK.md` file in your project directory for instructions that apply only to Grok CLI:
|
|
113
|
+
**`.env`** in the project (see `.env.example` if present):
|
|
351
114
|
|
|
352
115
|
```bash
|
|
353
|
-
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
Example `.grok/GROK.md`:
|
|
357
|
-
|
|
358
|
-
```markdown
|
|
359
|
-
# Custom Instructions for This Project
|
|
360
|
-
|
|
361
|
-
Always use TypeScript for any new code files.
|
|
362
|
-
When creating React components, use functional components with hooks.
|
|
363
|
-
Prefer const assertions and explicit typing over inference where it improves clarity.
|
|
364
|
-
Always add JSDoc comments for public functions and interfaces.
|
|
365
|
-
Follow the existing code style and patterns in this project.
|
|
116
|
+
GROK_API_KEY=your_key_here
|
|
366
117
|
```
|
|
367
118
|
|
|
368
|
-
|
|
119
|
+
**CLI once:**
|
|
369
120
|
|
|
370
121
|
```bash
|
|
371
|
-
|
|
122
|
+
grok -k your_key_here
|
|
372
123
|
```
|
|
373
124
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
```markdown
|
|
377
|
-
# Global Custom Instructions for Grok CLI
|
|
378
|
-
|
|
379
|
-
Always prioritize code readability and maintainability.
|
|
380
|
-
Use descriptive variable names and add comments for complex logic.
|
|
381
|
-
Follow best practices for the programming language being used.
|
|
382
|
-
When suggesting code changes, consider performance implications.
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
#### GROK.md vs project `AGENTS.md`
|
|
386
|
-
|
|
387
|
-
If both exist, **both** are included: all `AGENTS.md` segments first (global `~/.grok/AGENTS.md`, then root-to-cwd walk), then **one** GROK file — **project** `.grok/GROK.md` if it exists, otherwise `~/.grok/GROK.md`. Project GROK is not merged with global GROK; the project file replaces the global file for GROK-only content.
|
|
388
|
-
|
|
389
|
-
If no instruction files are present, Grok uses its built-in behavior only.
|
|
390
|
-
|
|
391
|
-
The merged body is added to the system prompt under **CUSTOM INSTRUCTIONS** and applies to that session’s workspace directory.
|
|
392
|
-
|
|
393
|
-
### Agent Skills
|
|
394
|
-
|
|
395
|
-
[Agent Skills](https://agentskills.io) are folders of instructions (and optional scripts and assets) that Grok can load when they match the task. Grok discovers skills on disk and includes a compact catalog in the system prompt; the model should `read_file` the listed `SKILL.md` when a skill might help.
|
|
396
|
-
|
|
397
|
-
#### Layout
|
|
398
|
-
|
|
399
|
-
Each skill is a directory containing a `SKILL.md` file with YAML frontmatter (`name` and `description` required), per the [specification](https://agentskills.io/specification).
|
|
400
|
-
|
|
401
|
-
- **Project skills:** `.agents/skills/<skill-name>/SKILL.md` (under your project directory)
|
|
402
|
-
- **User skills:** `~/.agents/skills/<skill-name>/SKILL.md`
|
|
403
|
-
|
|
404
|
-
If the same `name` appears in both places, the **project** skill wins.
|
|
405
|
-
|
|
406
|
-
Install skills by copying or cloning them into those paths, or use tooling such as `skills.sh` — Grok CLI does not download skills for you.
|
|
407
|
-
|
|
408
|
-
#### Listing skills in the TUI
|
|
409
|
-
|
|
410
|
-
Open the slash command palette and choose **skills**, or type **`/skills`**, to print installed skills (name, scope, description, and path).
|
|
125
|
+
**Saved in user settings** — `~/.grok/user-settings.json`:
|
|
411
126
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
Grok CLI supports Morph's Fast Apply model for high-speed code editing at **4,500+ tokens/sec with 98% accuracy**. This is an optional feature that provides lightning-fast file editing capabilities.
|
|
415
|
-
|
|
416
|
-
**Setup**: Configure your Morph API key following the [setup instructions](#setup) above.
|
|
417
|
-
|
|
418
|
-
### How It Works
|
|
419
|
-
|
|
420
|
-
When `MORPH_API_KEY` is configured:
|
|
421
|
-
- **`edit_file` tool becomes available** alongside the standard `str_replace_editor`
|
|
422
|
-
- **Optimized for complex edits**: Use for multi-line changes, refactoring, and large modifications
|
|
423
|
-
- **Intelligent editing**: Uses abbreviated edit format with `// ... existing code ...` comments
|
|
424
|
-
- **Fallback support**: Standard tools remain available if Morph is unavailable
|
|
425
|
-
|
|
426
|
-
**When to use each tool:**
|
|
427
|
-
- **`edit_file`** (Morph): Complex edits, refactoring, multi-line changes
|
|
428
|
-
- **`str_replace_editor`**: Simple text replacements, single-line edits
|
|
429
|
-
|
|
430
|
-
### Example Usage
|
|
431
|
-
|
|
432
|
-
With Morph Fast Apply configured, you can request complex code changes:
|
|
433
|
-
|
|
434
|
-
```bash
|
|
435
|
-
grok --prompt "refactor this function to use async/await and add error handling"
|
|
436
|
-
grok -p "convert this class to TypeScript and add proper type annotations"
|
|
127
|
+
```json
|
|
128
|
+
{ "apiKey": "your_key_here" }
|
|
437
129
|
```
|
|
438
130
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
## MCP Tools
|
|
442
|
-
|
|
443
|
-
Grok CLI supports MCP (Model Context Protocol) servers, allowing you to extend the AI assistant with additional tools and capabilities.
|
|
444
|
-
|
|
445
|
-
### Adding MCP Tools
|
|
446
|
-
|
|
447
|
-
#### Add a custom MCP server:
|
|
448
|
-
```bash
|
|
449
|
-
# Add an stdio-based MCP server
|
|
450
|
-
grok mcp add my-server --transport stdio --command "bun" --args server.js
|
|
451
|
-
|
|
452
|
-
# Add an HTTP-based MCP server
|
|
453
|
-
grok mcp add my-server --transport http --url "http://localhost:3000"
|
|
131
|
+
Optional: **`GROK_BASE_URL`** (default `https://api.x.ai/v1`), **`GROK_MODEL`**, **`GROK_MAX_TOKENS`**.
|
|
454
132
|
|
|
455
|
-
|
|
456
|
-
grok mcp add my-server --transport stdio --command "python" --args "-m" "my_mcp_server" --env "API_KEY=your_key"
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
#### Add from JSON configuration:
|
|
460
|
-
```bash
|
|
461
|
-
grok mcp add-json my-server '{"command": "bun", "args": ["server.js"], "env": {"API_KEY": "your_key"}}'
|
|
462
|
-
```
|
|
133
|
+
---
|
|
463
134
|
|
|
464
|
-
|
|
135
|
+
## Telegram (remote control) — short version
|
|
465
136
|
|
|
466
|
-
|
|
137
|
+
1. Create a bot with [@BotFather](https://t.me/BotFather), copy the token.
|
|
138
|
+
2. Set **`TELEGRAM_BOT_TOKEN`** or add **`telegram.botToken`** in `~/.grok/user-settings.json` (the TUI **`/remote-control`** flow can save it).
|
|
139
|
+
3. Start **`grok`**, open **`/remote-control`** → **Telegram** if needed, then in Telegram DM your bot: **`/pair`**, enter the **6-character code** in the terminal when asked.
|
|
140
|
+
4. First user must be approved once; after that, it’s remembered. **Keep the CLI process running** while you use the bot (long polling lives in that process).
|
|
467
141
|
|
|
468
|
-
|
|
469
|
-
# Add Linear MCP server
|
|
470
|
-
grok mcp add linear --transport sse --url "https://mcp.linear.app/sse"
|
|
471
|
-
```
|
|
142
|
+
Treat the bot token like a password.
|
|
472
143
|
|
|
473
|
-
|
|
474
|
-
- Create and manage Linear issues
|
|
475
|
-
- Search and filter issues
|
|
476
|
-
- Update issue status and assignees
|
|
477
|
-
- Access team and project information
|
|
144
|
+
---
|
|
478
145
|
|
|
479
|
-
|
|
146
|
+
## Instructions & project brain
|
|
480
147
|
|
|
481
|
-
|
|
482
|
-
# List all configured servers
|
|
483
|
-
grok mcp list
|
|
148
|
+
- **`AGENTS.md`** — merged from git root down to your cwd (Codex-style; see repo docs). **`AGENTS.override.md`** wins per directory when present.
|
|
484
149
|
|
|
485
|
-
|
|
486
|
-
grok mcp test server-name
|
|
150
|
+
---
|
|
487
151
|
|
|
488
|
-
|
|
489
|
-
grok mcp remove server-name
|
|
490
|
-
```
|
|
152
|
+
## Project settings
|
|
491
153
|
|
|
492
|
-
|
|
154
|
+
Project file: **`.grok/settings.json`** — e.g. the current model for this project.
|
|
493
155
|
|
|
494
|
-
|
|
495
|
-
- **http**: Connect to HTTP-based MCP server
|
|
496
|
-
- **sse**: Connect via Server-Sent Events
|
|
156
|
+
---
|
|
497
157
|
|
|
498
158
|
## Development
|
|
499
159
|
|
|
160
|
+
From a clone:
|
|
161
|
+
|
|
500
162
|
```bash
|
|
501
|
-
# Install dependencies
|
|
502
163
|
bun install
|
|
503
|
-
|
|
504
|
-
# Development mode
|
|
505
|
-
bun run dev
|
|
506
|
-
|
|
507
|
-
# Build project
|
|
508
164
|
bun run build
|
|
165
|
+
bun run start
|
|
166
|
+
# or: node dist/index.js
|
|
167
|
+
```
|
|
509
168
|
|
|
510
|
-
|
|
511
|
-
bun run lint
|
|
169
|
+
Other useful commands:
|
|
512
170
|
|
|
513
|
-
|
|
171
|
+
```bash
|
|
172
|
+
bun run dev # run from source (Bun)
|
|
514
173
|
bun run typecheck
|
|
174
|
+
bun run lint
|
|
515
175
|
```
|
|
516
176
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
- **Agent**: Core command processing and execution logic
|
|
520
|
-
- **Tools**: Text editor and bash tool implementations
|
|
521
|
-
- **UI**: Ink-based terminal interface components
|
|
522
|
-
- **Types**: TypeScript definitions for the entire system
|
|
177
|
+
---
|
|
523
178
|
|
|
524
179
|
## License
|
|
525
180
|
|