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.
Files changed (61) hide show
  1. package/.cursor/rules/project-overview.mdc +2 -2
  2. package/.grok/settings.json +15 -1
  3. package/README.md +89 -434
  4. package/dist/agent/agent.d.ts +42 -3
  5. package/dist/agent/agent.js +294 -127
  6. package/dist/agent/agent.js.map +1 -1
  7. package/dist/agent/compaction.d.ts +35 -0
  8. package/dist/agent/compaction.js +364 -0
  9. package/dist/agent/compaction.js.map +1 -0
  10. package/dist/agent/compaction.test.d.ts +1 -0
  11. package/dist/agent/compaction.test.js.map +1 -0
  12. package/dist/headless/output.d.ts +67 -0
  13. package/dist/headless/output.js +176 -0
  14. package/dist/headless/output.js.map +1 -0
  15. package/dist/headless/output.test.d.ts +1 -0
  16. package/dist/headless/output.test.js.map +1 -0
  17. package/dist/index.js +38 -33
  18. package/dist/index.js.map +1 -1
  19. package/dist/mcp/catalog.d.ts +10 -0
  20. package/dist/mcp/catalog.js +97 -0
  21. package/dist/mcp/catalog.js.map +1 -0
  22. package/dist/mcp/parse-headers.d.ts +2 -0
  23. package/dist/mcp/parse-headers.js +33 -0
  24. package/dist/mcp/parse-headers.js.map +1 -0
  25. package/dist/mcp/parse-headers.test.d.ts +1 -0
  26. package/dist/mcp/parse-headers.test.js.map +1 -0
  27. package/dist/mcp/runtime.d.ts +8 -0
  28. package/dist/mcp/runtime.js +64 -0
  29. package/dist/mcp/runtime.js.map +1 -0
  30. package/dist/mcp/validate.d.ts +9 -0
  31. package/dist/mcp/validate.js +39 -0
  32. package/dist/mcp/validate.js.map +1 -0
  33. package/dist/storage/index.d.ts +2 -1
  34. package/dist/storage/index.js +2 -1
  35. package/dist/storage/index.js.map +1 -1
  36. package/dist/storage/migrations.js +31 -1
  37. package/dist/storage/migrations.js.map +1 -1
  38. package/dist/storage/transcript-view.d.ts +14 -0
  39. package/dist/storage/transcript-view.js +23 -0
  40. package/dist/storage/transcript-view.js.map +1 -0
  41. package/dist/storage/transcript.d.ts +8 -2
  42. package/dist/storage/transcript.js +72 -18
  43. package/dist/storage/transcript.js.map +1 -1
  44. package/dist/telegram/limits.test.d.ts +1 -0
  45. package/dist/telegram/limits.test.js.map +1 -0
  46. package/dist/ui/app.js +393 -19
  47. package/dist/ui/app.js.map +1 -1
  48. package/dist/ui/mcp-modal-types.d.ts +24 -0
  49. package/dist/ui/mcp-modal-types.js +13 -0
  50. package/dist/ui/mcp-modal-types.js.map +1 -0
  51. package/dist/ui/mcp-modal.d.ts +33 -0
  52. package/dist/ui/mcp-modal.js +94 -0
  53. package/dist/ui/mcp-modal.js.map +1 -0
  54. package/dist/utils/instructions.js +0 -8
  55. package/dist/utils/instructions.js.map +1 -1
  56. package/dist/utils/instructions.test.d.ts +1 -0
  57. package/dist/utils/instructions.test.js.map +1 -0
  58. package/dist/utils/settings.d.ts +19 -0
  59. package/dist/utils/settings.js +15 -0
  60. package/dist/utils/settings.js.map +1 -1
  61. 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) + .grok/GROK.md
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), then `.grok/GROK.md` or `~/.grok/GROK.md` last.
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
@@ -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 CLI
1
+ # There are many coding agents. **This is Grok’s.**
2
2
 
3
- A conversational AI CLI tool powered by Grok with intelligent text editor capabilities and tool usage.
3
+ [![CI](https://github.com/superagent-ai/grok-cli/actions/workflows/typecheck.yml/badge.svg)](https://github.com/superagent-ai/grok-cli/actions/workflows/typecheck.yml)
4
+ [![npm](https://img.shields.io/npm/v/grok-dev.svg)](https://www.npmjs.com/package/grok-dev)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
7
+ [![Bun](https://img.shields.io/badge/Bun-1.x-000000?logo=bun&logoColor=white)](https://bun.sh/)
4
8
 
5
- <img width="980" height="435" alt="Screenshot 2025-07-21 at 13 35 41" src="https://github.com/user-attachments/assets/192402e3-30a8-47df-9fc8-a084c5696e78" />
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
- ## Features
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
- - **🤖 Conversational AI**: Natural language interface powered by Grok-3
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
- ## Installation
15
+ ---
19
16
 
20
- ### Prerequisites
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
- bun add -g @vibe-kit/grok-cli
20
+ npm i -g grok-dev
28
21
  ```
29
22
 
30
- Or with npm (fallback):
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
- ### Local Development
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
- ## Setup
27
+ ---
45
28
 
46
- 1. Get your Grok API key from [X.AI](https://x.ai)
29
+ ## Run it
47
30
 
48
- 2. Set up your API key (choose one method):
31
+ **Interactive (default)** launches the OpenTUI coding agent:
49
32
 
50
- **Method 1: Environment Variable**
51
33
  ```bash
52
- export GROK_API_KEY=your_api_key_here
34
+ grok
53
35
  ```
54
36
 
55
- **Method 2: .env File**
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 --api-key your_api_key_here
40
+ grok -d /path/to/your/repo
64
41
  ```
65
42
 
66
- **Method 4: User Settings File**
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
- export MORPH_API_KEY=your_morph_api_key_here
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
- **Method 2: .env File**
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
- export GROK_BASE_URL=https://your-custom-endpoint.com/v1
55
+ grok --session latest
56
+ grok -s <session-id>
96
57
  ```
97
58
 
98
- **Method 2: Command Line Flag**
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
- Optional env override: `TELEGRAM_BOT_TOKEN`. Approved Telegram user IDs and per-user session mappings are stored under the **`telegram`** object in `user-settings.json`. Treat the bot token like a password.
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
- Or specify a working directory:
238
- ```bash
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
- ### Headless Mode
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 --prompt "show me the package.json file"
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
- This mode is particularly useful for:
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
- # Limit tool rounds for faster execution on simple tasks
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
- **Use Cases**:
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
- ### Model Selection
84
+ ## What you actually get
280
85
 
281
- You can specify which AI model to use with the `--model` parameter or `GROK_MODEL` environment variable:
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
- **Method 1: Command Line Flag**
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
- **Method 2: Environment Variable**
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
- **Method 3: User Settings File**
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
- **Model Priority**: `--model` flag > `GROK_MODEL` environment variable > user default model > system default (grok-code-fast-1)
105
+ ## API key (pick one)
312
106
 
313
- ### Command Line Options
107
+ **Environment (good for CI):**
314
108
 
315
109
  ```bash
316
- grok [options]
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
- ### Custom Instructions
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
- mkdir .grok
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
- For defaults across all projects, use `~/.grok/GROK.md`:
119
+ **CLI once:**
369
120
 
370
121
  ```bash
371
- mkdir -p ~/.grok
122
+ grok -k your_key_here
372
123
  ```
373
124
 
374
- Example global `GROK.md`:
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
- ## Morph Fast Apply (Optional)
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
- The AI will automatically choose between `edit_file` (Morph) for complex changes or `str_replace_editor` for simple replacements.
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
- # Add with environment variables
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
- ### Linear Integration Example
135
+ ## Telegram (remote control) — short version
465
136
 
466
- To add Linear MCP tools for project management:
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
- ```bash
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
- This enables Linear tools like:
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
- ### Managing MCP Servers
146
+ ## Instructions & project brain
480
147
 
481
- ```bash
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
- # Test server connection
486
- grok mcp test server-name
150
+ ---
487
151
 
488
- # Remove a server
489
- grok mcp remove server-name
490
- ```
152
+ ## Project settings
491
153
 
492
- ### Available Transport Types
154
+ Project file: **`.grok/settings.json`** — e.g. the current model for this project.
493
155
 
494
- - **stdio**: Run MCP server as a subprocess (most common)
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
- # Run linter
511
- bun run lint
169
+ Other useful commands:
512
170
 
513
- # Type check
171
+ ```bash
172
+ bun run dev # run from source (Bun)
514
173
  bun run typecheck
174
+ bun run lint
515
175
  ```
516
176
 
517
- ## Architecture
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