grokcodecli 0.1.0

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 (99) hide show
  1. package/.claude/settings.local.json +32 -0
  2. package/README.md +1464 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +61 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commands/loader.d.ts +34 -0
  8. package/dist/commands/loader.d.ts.map +1 -0
  9. package/dist/commands/loader.js +192 -0
  10. package/dist/commands/loader.js.map +1 -0
  11. package/dist/config/manager.d.ts +21 -0
  12. package/dist/config/manager.d.ts.map +1 -0
  13. package/dist/config/manager.js +203 -0
  14. package/dist/config/manager.js.map +1 -0
  15. package/dist/conversation/chat.d.ts +50 -0
  16. package/dist/conversation/chat.d.ts.map +1 -0
  17. package/dist/conversation/chat.js +1145 -0
  18. package/dist/conversation/chat.js.map +1 -0
  19. package/dist/conversation/history.d.ts +24 -0
  20. package/dist/conversation/history.d.ts.map +1 -0
  21. package/dist/conversation/history.js +103 -0
  22. package/dist/conversation/history.js.map +1 -0
  23. package/dist/grok/client.d.ts +86 -0
  24. package/dist/grok/client.d.ts.map +1 -0
  25. package/dist/grok/client.js +106 -0
  26. package/dist/grok/client.js.map +1 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +8 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/permissions/manager.d.ts +26 -0
  32. package/dist/permissions/manager.d.ts.map +1 -0
  33. package/dist/permissions/manager.js +170 -0
  34. package/dist/permissions/manager.js.map +1 -0
  35. package/dist/tools/bash.d.ts +8 -0
  36. package/dist/tools/bash.d.ts.map +1 -0
  37. package/dist/tools/bash.js +102 -0
  38. package/dist/tools/bash.js.map +1 -0
  39. package/dist/tools/edit.d.ts +9 -0
  40. package/dist/tools/edit.d.ts.map +1 -0
  41. package/dist/tools/edit.js +61 -0
  42. package/dist/tools/edit.js.map +1 -0
  43. package/dist/tools/glob.d.ts +7 -0
  44. package/dist/tools/glob.d.ts.map +1 -0
  45. package/dist/tools/glob.js +38 -0
  46. package/dist/tools/glob.js.map +1 -0
  47. package/dist/tools/grep.d.ts +8 -0
  48. package/dist/tools/grep.d.ts.map +1 -0
  49. package/dist/tools/grep.js +78 -0
  50. package/dist/tools/grep.js.map +1 -0
  51. package/dist/tools/read.d.ts +8 -0
  52. package/dist/tools/read.d.ts.map +1 -0
  53. package/dist/tools/read.js +96 -0
  54. package/dist/tools/read.js.map +1 -0
  55. package/dist/tools/registry.d.ts +42 -0
  56. package/dist/tools/registry.d.ts.map +1 -0
  57. package/dist/tools/registry.js +230 -0
  58. package/dist/tools/registry.js.map +1 -0
  59. package/dist/tools/webfetch.d.ts +10 -0
  60. package/dist/tools/webfetch.d.ts.map +1 -0
  61. package/dist/tools/webfetch.js +108 -0
  62. package/dist/tools/webfetch.js.map +1 -0
  63. package/dist/tools/websearch.d.ts +7 -0
  64. package/dist/tools/websearch.d.ts.map +1 -0
  65. package/dist/tools/websearch.js +180 -0
  66. package/dist/tools/websearch.js.map +1 -0
  67. package/dist/tools/write.d.ts +7 -0
  68. package/dist/tools/write.d.ts.map +1 -0
  69. package/dist/tools/write.js +80 -0
  70. package/dist/tools/write.js.map +1 -0
  71. package/dist/utils/security.d.ts +36 -0
  72. package/dist/utils/security.d.ts.map +1 -0
  73. package/dist/utils/security.js +227 -0
  74. package/dist/utils/security.js.map +1 -0
  75. package/dist/utils/ui.d.ts +49 -0
  76. package/dist/utils/ui.d.ts.map +1 -0
  77. package/dist/utils/ui.js +302 -0
  78. package/dist/utils/ui.js.map +1 -0
  79. package/package.json +45 -0
  80. package/src/cli.ts +68 -0
  81. package/src/commands/loader.ts +244 -0
  82. package/src/config/manager.ts +239 -0
  83. package/src/conversation/chat.ts +1294 -0
  84. package/src/conversation/history.ts +131 -0
  85. package/src/grok/client.ts +192 -0
  86. package/src/index.ts +8 -0
  87. package/src/permissions/manager.ts +208 -0
  88. package/src/tools/bash.ts +119 -0
  89. package/src/tools/edit.ts +73 -0
  90. package/src/tools/glob.ts +49 -0
  91. package/src/tools/grep.ts +96 -0
  92. package/src/tools/read.ts +116 -0
  93. package/src/tools/registry.ts +248 -0
  94. package/src/tools/webfetch.ts +127 -0
  95. package/src/tools/websearch.ts +219 -0
  96. package/src/tools/write.ts +94 -0
  97. package/src/utils/security.ts +259 -0
  98. package/src/utils/ui.ts +382 -0
  99. package/tsconfig.json +22 -0
package/README.md ADDED
@@ -0,0 +1,1464 @@
1
+ # Grok Code CLI
2
+
3
+ <div align="center">
4
+
5
+ ```
6
+ ██████╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗
7
+ ██╔════╝ ██╔══██╗██╔═══██╗██║ ██╔╝ ██╔════╝██╔═══██╗██╔══██╗██╔════╝
8
+ ██║ ███╗██████╔╝██║ ██║█████╔╝ ██║ ██║ ██║██║ ██║█████╗
9
+ ██║ ██║██╔══██╗██║ ██║██╔═██╗ ██║ ██║ ██║██║ ██║██╔══╝
10
+ ╚██████╔╝██║ ██║╚██████╔╝██║ ██╗ ╚██████╗╚██████╔╝██████╔╝███████╗
11
+ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
12
+ ```
13
+
14
+ ### A Production-Ready CLI Coding Assistant Powered by xAI's Grok Models
15
+
16
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
17
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org)
18
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.3-blue)](https://www.typescriptlang.org/)
19
+ [![xAI API](https://img.shields.io/badge/xAI-Grok%20Models-orange)](https://x.ai/)
20
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/singhpratech/grokcodeclix/pulls)
21
+
22
+ **[Installation](#-quick-start)** · **[Features](#-features)** · **[Commands](#-slash-commands)** · **[Tools](#-available-tools)** · **[Security](#-security-features)** · **[Contributing](#-contributing)**
23
+
24
+ </div>
25
+
26
+ ---
27
+
28
+ ## What is Grok Code?
29
+
30
+ **Grok Code** is an agentic coding assistant that lives in your terminal. Think of it as having a senior developer pair programming with you - one that can read your files, write code, run commands, search the web, and help you build software faster.
31
+
32
+ ```
33
+ $ grok
34
+
35
+ ██████╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗
36
+ ██╔════╝ ██╔══██╗██╔═══██╗██║ ██╔╝ ██╔════╝██╔═══██╗██╔══██╗██╔════╝
37
+ ██║ ███╗██████╔╝██║ ██║█████╔╝ ██║ ██║ ██║██║ ██║█████╗
38
+ ██║ ██║██╔══██╗██║ ██║██╔═██╗ ██║ ██║ ██║██║ ██║██╔══╝
39
+ ╚██████╔╝██║ ██║╚██████╔╝██║ ██╗ ╚██████╗╚██████╔╝██████╔╝███████╗
40
+ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
41
+
42
+ ╭──────────────────────────────────────────────────────────────────────╮
43
+ │ Grok Code CLI v0.1.0 │
44
+ │ │
45
+ │ Model: grok-4-0709 │
46
+ │ CWD: ~/myproject │
47
+ │ Tools: 8 available (Read, Write, Edit, Bash, Glob, Grep, ...) │
48
+ │ │
49
+ │ Commands: /help • /model • /doctor • exit │
50
+ ╰──────────────────────────────────────────────────────────────────────╯
51
+
52
+ 💡 Tip: Use /model to switch between Grok 4.1, Grok 4, and specialized models
53
+
54
+ ❯ Help me create a REST API with Express
55
+
56
+ ╭──────────────────────────────────────────────────────────────────────╮
57
+ │ 🤖 Grok │
58
+ ╰──────────────────────────────────────────────────────────────────────╯
59
+
60
+ I'll help you create a REST API with Express. Let me start by
61
+ checking your project structure and then create the necessary files.
62
+
63
+ ┌─ 📖 Read ─────────────────────────────────────────────────────────────┐
64
+ │ Reading: package.json │
65
+ └────────────────────────────────────────────────────────────────────────┘
66
+
67
+ ┌─ ✏️ Write ────────────────────────────────────────────────────────────┐
68
+ │ Creating: src/server.ts │
69
+ │ Creating: src/routes/api.ts │
70
+ └────────────────────────────────────────────────────────────────────────┘
71
+
72
+ ┌─ ⚡ Bash ─────────────────────────────────────────────────────────────┐
73
+ │ $ npm install express │
74
+ └────────────────────────────────────────────────────────────────────────┘
75
+
76
+ ✓ Created Express API with the following endpoints:
77
+ GET /api/users - List all users
78
+ POST /api/users - Create a user
79
+ GET /api/users/:id - Get user by ID
80
+
81
+ ❯ _
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Why Grok Code?
87
+
88
+ <table>
89
+ <tr>
90
+ <td width="50%">
91
+
92
+ ### Powered by Grok AI
93
+ Access xAI's latest models including **Grok 4.1**, **Grok 4**, and specialized models. Dynamic model fetching ensures you always have access to the newest models as they're released.
94
+
95
+ ### Production Ready
96
+ Built with TypeScript, comprehensive security hardening, and battle-tested on real projects. Not a toy - a real tool for real developers.
97
+
98
+ ### Claude Code Compatible
99
+ Familiar slash commands, permission system, and workflows. If you've used Claude Code, you'll feel right at home.
100
+
101
+ </td>
102
+ <td width="50%">
103
+
104
+ ### 8 Powerful Tools
105
+ Read files, write code, execute commands, search codebases, fetch web content, and **search the web** - all with intelligent permission management.
106
+
107
+ ### Session Persistence
108
+ Resume conversations where you left off. Your context, history, and progress are automatically saved.
109
+
110
+ ### Extensible
111
+ Create custom slash commands for your team. Define project-specific workflows in `.grok/commands/`.
112
+
113
+ </td>
114
+ </tr>
115
+ </table>
116
+
117
+ ---
118
+
119
+ ## 📸 Screenshots
120
+
121
+ ### Welcome Screen
122
+
123
+ The beautiful welcome screen shows your current model, working directory, and available tools:
124
+
125
+ ```
126
+ ██████╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗
127
+ ██╔════╝ ██╔══██╗██╔═══██╗██║ ██╔╝ ██╔════╝██╔═══██╗██╔══██╗██╔════╝
128
+ ██║ ███╗██████╔╝██║ ██║█████╔╝ ██║ ██║ ██║██║ ██║█████╗
129
+ ██║ ██║██╔══██╗██║ ██║██╔═██╗ ██║ ██║ ██║██║ ██║██╔══╝
130
+ ╚██████╔╝██║ ██║╚██████╔╝██║ ██╗ ╚██████╗╚██████╔╝██████╔╝███████╗
131
+ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
132
+
133
+ ╭──────────────────────────────────────────────────────────────────────╮
134
+ │ Grok Code CLI v0.1.0 │
135
+ │ │
136
+ │ Model: grok-4-0709 │
137
+ │ CWD: /home/user/myproject │
138
+ │ Tools: 8 available (Read, Write, Edit, Bash, Glob, Grep, ...) │
139
+ │ │
140
+ │ Commands: /help • /model • /doctor • exit │
141
+ ╰──────────────────────────────────────────────────────────────────────╯
142
+
143
+ 💡 Tip: Use /compact to reduce context when conversations get long
144
+
145
+ ❯ _
146
+ ```
147
+
148
+ ### /help Command
149
+
150
+ Shows all 25+ available slash commands organized by category:
151
+
152
+ ```
153
+ ╭──────────────────────────────────────────────────────────────────────╮
154
+ │ 📚 Grok Code CLI - Help │
155
+ ╰──────────────────────────────────────────────────────────────────────╯
156
+
157
+ Session Management
158
+ ─────────────────────────────────────────────────────────────────
159
+ /clear Clear conversation and start fresh
160
+ /save, /s Save current conversation
161
+ /history Show saved conversations
162
+ /resume [id] Resume a previous conversation
163
+ /rename <name> Rename current session
164
+ /export [file] Export conversation to file
165
+ /compact [focus] Reduce context size (keep last 20 messages)
166
+ /exit, /q Save and quit
167
+
168
+ Configuration
169
+ ─────────────────────────────────────────────────────────────────
170
+ /config Show current configuration
171
+ /model [name] Show or change the AI model
172
+ /stream Toggle streaming mode
173
+ /permissions View permission settings
174
+
175
+ Status & Info
176
+ ─────────────────────────────────────────────────────────────────
177
+ /status Show session status and info
178
+ /context Visualize context usage
179
+ /cost Show token usage and estimated cost
180
+ /usage Show usage statistics
181
+ /doctor Run diagnostics check
182
+ /version Show version
183
+
184
+ ✓ 25+ slash commands available!
185
+ ```
186
+
187
+ ### /model Command
188
+
189
+ Beautiful model selection with Grok 4.1 reasoning and fast variants:
190
+
191
+ ```
192
+ ╭──────────────────────────────────────────────────────────────────────╮
193
+ │ 🤖 Model Selection │
194
+ ╰──────────────────────────────────────────────────────────────────────╯
195
+
196
+ Current Model: grok-4-0709
197
+
198
+ ⭐ Grok 4.1 (Latest)
199
+ ─────────────────────────────────────────────────────────────────
200
+ 🧠 grok-4-1-fast-reasoning [REASONING]
201
+ ⚡ grok-4-1-fast-non-reasoning [FAST]
202
+
203
+ 🚀 Grok 4
204
+ ─────────────────────────────────────────────────────────────────
205
+ • grok-4-0709 ← current (recommended)
206
+ 🧠 grok-4-fast-reasoning [REASONING]
207
+ ⚡ grok-4-fast-non-reasoning [FAST]
208
+
209
+ 📦 Grok 3
210
+ ─────────────────────────────────────────────────────────────────
211
+ • grok-3
212
+ • grok-3-mini
213
+
214
+ 📷 Grok 2 (Vision/Image)
215
+ ─────────────────────────────────────────────────────────────────
216
+ • grok-2-image-1212
217
+ • grok-2-vision-1212
218
+
219
+ 🔧 Specialized
220
+ ─────────────────────────────────────────────────────────────────
221
+ • grok-code-fast-1
222
+
223
+ 10 models available • Use /model <name> to switch
224
+ 🧠 = Reasoning (best for complex tasks) • ⚡ = Fast (quick responses)
225
+ ```
226
+
227
+ ### /doctor Command
228
+
229
+ Comprehensive diagnostics to ensure everything is working:
230
+
231
+ ```
232
+ ╭──────────────────────────────────────────────────────────────────────╮
233
+ │ 🩺 Grok Code CLI - Diagnostics │
234
+ ╰──────────────────────────────────────────────────────────────────────╯
235
+
236
+ ✓ API Key Configured
237
+ ✓ Node.js v18.19.1 (>=18 required)
238
+ ✓ Working Dir Read/write access OK
239
+ ✓ Config Dir /home/user/.config/grokcodecli
240
+ ✓ Git Available
241
+ ✓ API Connection Connected (10 models)
242
+
243
+ All checks passed! Grok Code is ready to use.
244
+ ```
245
+
246
+ ### Authentication Flow
247
+
248
+ Beautiful browser-based OAuth-like authentication:
249
+
250
+ ```
251
+ ╭──────────────────────────────────────────────────────────────────────╮
252
+ │ 🔐 Grok Code CLI - Authentication │
253
+ ╰──────────────────────────────────────────────────────────────────────╯
254
+
255
+ Welcome to Grok Code!
256
+
257
+ To use Grok Code, you need an API key from xAI.
258
+ We'll open your browser to the xAI console where you can:
259
+
260
+ 1. Sign in or create an account
261
+ 2. Go to API Keys section
262
+ 3. Create a new API key
263
+ 4. Copy the key and paste it here
264
+
265
+ ❯ Open xAI Console in browser? [Y/n]: Y
266
+
267
+ ⏳ Opening browser...
268
+ ✓ Browser opened!
269
+
270
+ ─────────────────────────────────────────────────────────────────
271
+ Follow these steps in the browser:
272
+ 1. Sign in to your xAI account
273
+ 2. Click on "API Keys" in the sidebar
274
+ 3. Click "Create API Key"
275
+ 4. Copy the key (starts with "xai-")
276
+ ─────────────────────────────────────────────────────────────────
277
+
278
+ ❯ API Key: xai-••••••••••••••••••••
279
+
280
+ ⠋ Validating API key...
281
+ ✓ API key validated!
282
+
283
+ ╭──────────────────────────────────────────────────────────────────────╮
284
+ │ 🎉 Authentication Successful! │
285
+ │ │
286
+ │ API Key: ✓ Saved securely │
287
+ │ Models: 10 available │
288
+ │ Get started: grok │
289
+ ╰──────────────────────────────────────────────────────────────────────╯
290
+ ```
291
+
292
+ ### Tool Execution
293
+
294
+ Beautiful colored boxes show tool execution in real-time:
295
+
296
+ ```
297
+ ❯ Read the package.json file
298
+
299
+ ╭──────────────────────────────────────────────────────────────────────╮
300
+ │ 🤖 Grok │
301
+ ╰──────────────────────────────────────────────────────────────────────╯
302
+
303
+ I'll read the package.json file for you.
304
+
305
+ ┌─ 📖 Read ─────────────────────────────────────────────────────────────┐
306
+ │ Reading: package.json │
307
+ │ Lines: 1-35 │
308
+ │ Size: 1.2KB │
309
+ └────────────────────────────────────────────────────────────────────────┘
310
+
311
+ Here's your package.json:
312
+ ...
313
+ ```
314
+
315
+ ---
316
+
317
+ ## Quick Start
318
+
319
+ ### Installation
320
+
321
+ #### Option 1: Install from npm (Recommended)
322
+
323
+ ```bash
324
+ npm install -g grokcodecli
325
+ ```
326
+
327
+ #### Option 2: Install from Source
328
+
329
+ ```bash
330
+ git clone https://github.com/singhpratech/grokcodeclix.git
331
+ cd grokcodeclix
332
+ npm install
333
+ npm run build
334
+ npm link
335
+ ```
336
+
337
+ ### Setup
338
+
339
+ #### Quick Start (Recommended)
340
+
341
+ Just run the auth command - it will guide you through everything:
342
+
343
+ ```bash
344
+ grok auth
345
+ ```
346
+
347
+ This will:
348
+ 1. Open your browser to xAI Console
349
+ 2. Guide you through creating an API key
350
+ 3. Validate and save your key securely
351
+
352
+ ```
353
+ ╭──────────────────────────────────────────────────────────────────────╮
354
+ │ 🔐 Grok Code CLI - Authentication │
355
+ ╰──────────────────────────────────────────────────────────────────────╯
356
+
357
+ Welcome to Grok Code!
358
+
359
+ To use Grok Code, you need an API key from xAI.
360
+ We'll open your browser to the xAI console where you can:
361
+
362
+ 1. Sign in or create an account
363
+ 2. Go to API Keys section
364
+ 3. Create a new API key
365
+ 4. Copy the key and paste it here
366
+
367
+ ❯ Open xAI Console in browser? [Y/n]: Y
368
+
369
+ ⏳ Opening browser...
370
+ ✓ Browser opened!
371
+
372
+ ─────────────────────────────────────────────────────────────────
373
+ Follow these steps in the browser:
374
+ 1. Sign in to your xAI account
375
+ 2. Click on "API Keys" in the sidebar
376
+ 3. Click "Create API Key"
377
+ 4. Copy the key (starts with "xai-")
378
+ ─────────────────────────────────────────────────────────────────
379
+
380
+ ❯ API Key: xai-••••••••••••••••••••
381
+
382
+ ✓ API key validated!
383
+
384
+ ╭──────────────────────────────────────────────────────────────────────╮
385
+ │ 🎉 Authentication Successful! │
386
+ │ │
387
+ │ API Key: ✓ Saved securely │
388
+ │ Models: 10 available │
389
+ │ Get started: grok │
390
+ ╰──────────────────────────────────────────────────────────────────────╯
391
+ ```
392
+
393
+ #### Alternative: Environment Variable
394
+
395
+ ```bash
396
+ # Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
397
+ export XAI_API_KEY=your_api_key_here
398
+ ```
399
+
400
+ #### Start Coding
401
+
402
+ ```bash
403
+ grok
404
+ ```
405
+
406
+ That's it! You're ready to go.
407
+
408
+ ---
409
+
410
+ ## Features
411
+
412
+ ### Core Capabilities
413
+
414
+ | Feature | Description |
415
+ |---------|-------------|
416
+ | **Interactive AI Chat** | Real-time conversation with Grok AI for coding assistance, debugging, and learning |
417
+ | **Streaming Responses** | Token-by-token streaming for responsive, natural feedback |
418
+ | **8 Powerful Tools** | Read, Write, Edit, Bash, Glob, Grep, WebFetch, WebSearch - everything you need |
419
+ | **Permission System** | Color-coded risk levels with granular session-based approvals |
420
+ | **Dynamic Model Support** | Automatically fetches latest models from xAI API |
421
+
422
+ ### Session Management
423
+
424
+ | Feature | Description |
425
+ |---------|-------------|
426
+ | **Persistent History** | Auto-save conversations with full context preservation |
427
+ | **Resume Sessions** | Pick up exactly where you left off with `/resume` |
428
+ | **Export Conversations** | Save chats to markdown for documentation |
429
+ | **Context Visualization** | Track token usage with visual progress bars |
430
+
431
+ ### Security Hardened
432
+
433
+ | Protection | What It Does |
434
+ |------------|--------------|
435
+ | **Path Traversal Prevention** | Blocks access to `/etc/`, `/proc/`, `/sys/`, `/dev/` and `../` attacks |
436
+ | **Command Injection Protection** | Validates and blocks dangerous command patterns |
437
+ | **SSRF Prevention** | Blocks localhost, internal IPs, and non-HTTP protocols |
438
+ | **Sensitive File Detection** | Warns when accessing `.env`, credentials, and secrets |
439
+
440
+ ### Developer Experience
441
+
442
+ | Feature | Description |
443
+ |---------|-------------|
444
+ | **25+ Slash Commands** | Comprehensive command set for every workflow |
445
+ | **Custom Commands** | Create your own commands in `.grok/commands/` |
446
+ | **Syntax Highlighting** | Beautiful code output with language detection |
447
+ | **Diagnostic Tools** | `/doctor` command validates your entire setup |
448
+ | **Smart Model Matching** | Type `grok4` or `grok 3` - we'll figure it out |
449
+
450
+ ---
451
+
452
+ ## Dynamic Model Support
453
+
454
+ Grok Code **automatically fetches the latest models** from the xAI API. When xAI releases new models, they appear instantly in your CLI without any updates needed.
455
+
456
+ ### Current Models (Auto-Updated)
457
+
458
+ ```
459
+ ╭──────────────────────────────────────────────────────────────────────╮
460
+ │ 🤖 Model Selection │
461
+ ╰──────────────────────────────────────────────────────────────────────╯
462
+
463
+ Current Model: grok-4-0709
464
+
465
+ ⭐ Grok 4.1 (Latest)
466
+ ─────────────────────────────────────────────────────────────────
467
+ 🧠 grok-4-1-fast-reasoning [REASONING]
468
+ ⚡ grok-4-1-fast-non-reasoning [FAST]
469
+
470
+ 🚀 Grok 4
471
+ ─────────────────────────────────────────────────────────────────
472
+ • grok-4-0709 ← current (recommended)
473
+ 🧠 grok-4-fast-reasoning [REASONING]
474
+ ⚡ grok-4-fast-non-reasoning [FAST]
475
+
476
+ 📦 Grok 3
477
+ ─────────────────────────────────────────────────────────────────
478
+ • grok-3
479
+ • grok-3-mini
480
+
481
+ 📷 Grok 2 (Vision/Image)
482
+ ─────────────────────────────────────────────────────────────────
483
+ • grok-2-image-1212
484
+ • grok-2-vision-1212
485
+
486
+ 🔧 Specialized
487
+ ─────────────────────────────────────────────────────────────────
488
+ • grok-code-fast-1
489
+
490
+ 10 models available • Use /model <name> to switch
491
+ 🧠 = Reasoning (best for complex tasks) • ⚡ = Fast (quick responses)
492
+ ```
493
+
494
+ > **🧠 Reasoning Models:** Recommended for complex coding tasks - they provide step-by-step thinking for better accuracy.
495
+ >
496
+ > **⚡ Fast Models:** Great for quick responses and simpler tasks where speed matters more than deep analysis.
497
+
498
+ ### Smart Model Matching
499
+
500
+ You don't need to type exact model names. Grok Code uses intelligent matching:
501
+
502
+ | You Type | Matches |
503
+ |----------|---------|
504
+ | `grok41` | grok-4-1-fast-non-reasoning |
505
+ | `grok 4 1` | grok-4-1-fast-non-reasoning |
506
+ | `grok4` | grok-4-0709 |
507
+ | `4.1` | grok-4-1-fast-non-reasoning |
508
+ | `reasoning` | grok-4-1-fast-reasoning |
509
+ | `vision` | grok-2-vision-1212 |
510
+ | `code` | grok-code-fast-1 |
511
+ | `mini` | grok-3-mini |
512
+
513
+ ```bash
514
+ # All of these work:
515
+ /model grok41 # → grok-4-1-fast-non-reasoning
516
+ /model grok4 # → grok-4-0709
517
+ /model reasoning # → grok-4-1-fast-reasoning
518
+ /model vision # → grok-2-vision-1212
519
+ /model code # → grok-code-fast-1
520
+ ```
521
+
522
+ ---
523
+
524
+ ## Slash Commands
525
+
526
+ Grok Code includes **25+ built-in commands** for every workflow:
527
+
528
+ ### Session Management
529
+
530
+ | Command | Alias | Description |
531
+ |---------|-------|-------------|
532
+ | `/clear` | `/c` | Clear conversation and start fresh |
533
+ | `/save` | `/s` | Save current conversation |
534
+ | `/history` | | Show saved conversations with timestamps |
535
+ | `/resume [id]` | | Resume a previous conversation |
536
+ | `/rename <name>` | | Rename current session |
537
+ | `/export [file]` | | Export conversation to markdown file |
538
+ | `/compact [focus]` | | Reduce context size (keep last 20 messages) |
539
+ | `/exit` | `/q` | Save and quit |
540
+
541
+ ### Configuration
542
+
543
+ | Command | Description |
544
+ |---------|-------------|
545
+ | `/config` | Show current configuration settings |
546
+ | `/model [name]` | Show available models or switch to a different model |
547
+ | `/stream` | Toggle streaming mode on/off |
548
+ | `/permissions` | View permission settings and risk levels |
549
+
550
+ ### Status & Diagnostics
551
+
552
+ | Command | Description |
553
+ |---------|-------------|
554
+ | `/status` | Show session status, model, uptime, and message count |
555
+ | `/context` | Visualize context usage with progress bar |
556
+ | `/cost` | Show token usage and estimated cost |
557
+ | `/usage` | Show detailed usage statistics |
558
+ | `/doctor` | Run comprehensive diagnostics check |
559
+ | `/version` | Show Grok Code version |
560
+
561
+ ### Project Setup
562
+
563
+ | Command | Description |
564
+ |---------|-------------|
565
+ | `/init` | Initialize project with GROK.md configuration file |
566
+ | `/review [focus]` | Request AI code review with optional focus area |
567
+ | `/terminal-setup` | Show terminal configuration tips |
568
+
569
+ ### Working Directory
570
+
571
+ | Command | Description |
572
+ |---------|-------------|
573
+ | `/add-dir <path>` | Add a working directory to the session |
574
+ | `/pwd` | Show current working directories |
575
+
576
+ ### Quick Reference
577
+
578
+ | Alias | Full Command | Description |
579
+ |-------|--------------|-------------|
580
+ | `/h` | `/help` | Show help |
581
+ | `/c` | `/clear` | Clear conversation |
582
+ | `/s` | `/save` | Save conversation |
583
+ | `/q` | `/exit` | Quit |
584
+ | `exit` | `/exit` | Quit (natural language) |
585
+ | `quit` | `/exit` | Quit (natural language) |
586
+
587
+ ---
588
+
589
+ ## Available Tools
590
+
591
+ Grok Code has access to **8 powerful tools** that enable it to interact with your codebase and the web:
592
+
593
+ ### 📖 Read Tool (Low Risk)
594
+
595
+ Read file contents with line numbers and intelligent handling.
596
+
597
+ ```
598
+ Capabilities:
599
+ ✓ Supports offset/limit for large files
600
+ ✓ Detects and rejects binary files
601
+ ✓ Line number formatting (like cat -n)
602
+ ✓ Truncates very long lines (>2000 chars)
603
+
604
+ Limits:
605
+ → Maximum file size: 10MB
606
+ → Maximum lines returned: 2000
607
+ ```
608
+
609
+ **Example Usage:**
610
+ ```
611
+ You: Read the first 50 lines of src/index.ts
612
+ Grok: [Uses Read tool with limit: 50]
613
+
614
+ You: Show me lines 100-150 of the config file
615
+ Grok: [Uses Read tool with offset: 100, limit: 50]
616
+ ```
617
+
618
+ ---
619
+
620
+ ### ✏️ Write Tool (Medium Risk)
621
+
622
+ Create or overwrite files with full content.
623
+
624
+ ```
625
+ Capabilities:
626
+ ✓ Auto-creates parent directories
627
+ ✓ Shows size diff from previous version
628
+ ✓ Reports line count and file size
629
+
630
+ Limits:
631
+ → Maximum content size: 50MB
632
+
633
+ Security:
634
+ ⚠️ Warns when writing to sensitive paths
635
+ ⚠️ Blocked from system directories
636
+ ```
637
+
638
+ **Example Usage:**
639
+ ```
640
+ You: Create a new React component called Button
641
+ Grok: [Uses Write tool to create src/components/Button.tsx]
642
+ ✓ File written: src/components/Button.tsx
643
+ Lines: 45
644
+ Size: 1.2KB
645
+ ```
646
+
647
+ ---
648
+
649
+ ### 🔧 Edit Tool (Medium Risk)
650
+
651
+ Edit files by exact string replacement.
652
+
653
+ ```
654
+ Capabilities:
655
+ ✓ Precise string matching
656
+ ✓ Prevents accidental multiple replacements
657
+ ✓ Supports replace_all mode for bulk changes
658
+
659
+ Safety:
660
+ → Requires exact string match
661
+ → Fails if string appears multiple times (unless replace_all)
662
+ → Shows before/after context
663
+ ```
664
+
665
+ **Example Usage:**
666
+ ```
667
+ You: Change the API endpoint from /api/v1 to /api/v2
668
+ Grok: [Uses Edit tool with old_string: "/api/v1", new_string: "/api/v2"]
669
+ ✓ Edited src/config.ts
670
+ Replaced 1 occurrence
671
+ ```
672
+
673
+ ---
674
+
675
+ ### ⚡ Bash Tool (High Risk)
676
+
677
+ Execute shell commands with security validation.
678
+
679
+ ```
680
+ Capabilities:
681
+ ✓ Full bash shell access
682
+ ✓ Captures stdout and stderr
683
+ ✓ Configurable timeout (default: 2 minutes)
684
+ ✓ Working directory support
685
+
686
+ Security:
687
+ 🛡️ Blocks dangerous patterns (rm -rf /, curl | sh, etc.)
688
+ 🛡️ Prevents privilege escalation
689
+ 🛡️ Validates commands before execution
690
+
691
+ Limits:
692
+ → Maximum output: 1MB
693
+ → Default timeout: 120 seconds
694
+ → Maximum timeout: 10 minutes
695
+ ```
696
+
697
+ **Blocked Patterns:**
698
+ ```
699
+ ✗ rm -rf / # Catastrophic deletion
700
+ ✗ curl ... | sh # Remote code execution
701
+ ✗ wget ... | bash # Remote code execution
702
+ ✗ chmod 777 # Dangerous permissions
703
+ ✗ > /dev/sda # Device destruction
704
+ ✗ :(){:|:&};: # Fork bombs
705
+ ```
706
+
707
+ ---
708
+
709
+ ### 🔍 Glob Tool (Low Risk)
710
+
711
+ Find files matching patterns.
712
+
713
+ ```
714
+ Capabilities:
715
+ ✓ Full glob pattern support (*, **, ?, [])
716
+ ✓ Recursive directory searching
717
+ ✓ Sorted by modification time
718
+
719
+ Auto-Ignored:
720
+ → node_modules/
721
+ → .git/
722
+ → dist/
723
+ → build/
724
+ → coverage/
725
+
726
+ Limits:
727
+ → Maximum 100 results
728
+ ```
729
+
730
+ **Example Patterns:**
731
+ ```
732
+ **/*.ts # All TypeScript files
733
+ src/**/*.test.js # All test files in src
734
+ *.{js,ts} # All JS and TS files in current dir
735
+ ```
736
+
737
+ ---
738
+
739
+ ### 🔎 Grep Tool (Low Risk)
740
+
741
+ Search file contents with regex.
742
+
743
+ ```
744
+ Capabilities:
745
+ ✓ Full regex support (extended syntax)
746
+ ✓ Case-sensitive and case-insensitive modes
747
+ ✓ Context lines (before/after matches)
748
+ ✓ 30+ file type filters
749
+
750
+ Limits:
751
+ → Maximum 50 results
752
+ → Respects .gitignore
753
+ ```
754
+
755
+ **Example Searches:**
756
+ ```
757
+ /TODO|FIXME/ # Find all TODOs
758
+ /function\s+\w+/ # Find function declarations
759
+ /import.*from/ # Find all imports
760
+ ```
761
+
762
+ ---
763
+
764
+ ### 🌐 WebFetch Tool (Low Risk)
765
+
766
+ Fetch content from URLs.
767
+
768
+ ```
769
+ Capabilities:
770
+ ✓ HTML to readable text conversion
771
+ ✓ JSON pretty printing
772
+ ✓ Automatic content type detection
773
+ ✓ Redirect following
774
+
775
+ Security:
776
+ 🛡️ SSRF protection (blocks localhost, internal IPs)
777
+ 🛡️ Only HTTP/HTTPS protocols allowed
778
+ 🛡️ Request timeout: 30 seconds
779
+
780
+ Limits:
781
+ → Maximum response: 5MB
782
+ ```
783
+
784
+ **Blocked URLs:**
785
+ ```
786
+ ✗ http://localhost:* # Local services
787
+ ✗ http://127.0.0.1:* # Loopback
788
+ ✗ http://192.168.*.* # Private networks
789
+ ✗ http://10.*.*.* # Private networks
790
+ ✗ file:///etc/passwd # Local files
791
+ ```
792
+
793
+ ---
794
+
795
+ ### 🔍 WebSearch Tool (Low Risk)
796
+
797
+ Search the web for information, documentation, tutorials, and more.
798
+
799
+ ```
800
+ Capabilities:
801
+ ✓ Real-time web search
802
+ ✓ Returns titles, URLs, and snippets
803
+ ✓ No API key required (uses DuckDuckGo)
804
+ ✓ Sources section for citations
805
+
806
+ Limits:
807
+ → Maximum 20 results
808
+ → Query length: 500 characters
809
+ ```
810
+
811
+ **Example Usage:**
812
+ ```
813
+ You: Search for React hooks best practices
814
+ Grok: [Uses WebSearch tool]
815
+
816
+ 🔍 Search Results for: "React hooks best practices"
817
+ Found 10 results
818
+
819
+ 1. React Hooks Best Practices - Official Docs
820
+ https://react.dev/reference/react
821
+ Complete guide to React Hooks...
822
+
823
+ 2. 10 React Hooks Best Practices
824
+ https://blog.example.com/react-hooks
825
+ Learn the most important patterns...
826
+
827
+ Sources:
828
+ • [React Hooks Best Practices](https://react.dev/reference/react)
829
+ • [10 React Hooks Best Practices](https://blog.example.com/react-hooks)
830
+ ```
831
+
832
+ ---
833
+
834
+ ## Permission System
835
+
836
+ Grok Code uses a **granular permission system** to keep you in control:
837
+
838
+ ### Permission Prompt
839
+
840
+ When Grok wants to use a tool, you'll see a beautifully formatted prompt:
841
+
842
+ ```
843
+ ╭─────────────────────────────────────────────────────────────────╮
844
+ │ ⚡ Permission Request: Bash │
845
+ ├─────────────────────────────────────────────────────────────────┤
846
+ │ Execute command: npm install express │
847
+ ├─────────────────────────────────────────────────────────────────┤
848
+ │ command: npm install express │
849
+ │ timeout: 120000 │
850
+ ╰─────────────────────────────────────────────────────────────────╯
851
+
852
+ [y] Yes, allow once
853
+ [a] Allow for this session
854
+ [n] No, deny
855
+ [!] Deny and block for session
856
+ ```
857
+
858
+ ### Risk Levels
859
+
860
+ | Level | Icon | Color | Tools | Description |
861
+ |-------|------|-------|-------|-------------|
862
+ | **Read** | 📖 | Green | Read, Glob, Grep, WebFetch, WebSearch | Safe operations that only read data |
863
+ | **Write** | ✏️ | Yellow | Write, Edit | Modifies files but reversible |
864
+ | **Execute** | ⚡ | Red | Bash | Runs commands with system access |
865
+
866
+ ### Permission Responses
867
+
868
+ | Key | Action | Scope |
869
+ |-----|--------|-------|
870
+ | `y` | Allow | This request only |
871
+ | `a` | Allow | All similar requests this session |
872
+ | `n` | Deny | This request only |
873
+ | `!` | Block | All similar requests this session |
874
+
875
+ ### Auto-Approve Configuration
876
+
877
+ For trusted operations, you can configure auto-approval in your config:
878
+
879
+ ```json
880
+ {
881
+ "autoApprove": ["Read", "Glob", "Grep"]
882
+ }
883
+ ```
884
+
885
+ ---
886
+
887
+ ## Custom Commands
888
+
889
+ Create your own slash commands as markdown files:
890
+
891
+ ### Project Commands (Shared with Team)
892
+
893
+ Create commands in `.grok/commands/` in your project:
894
+
895
+ ```bash
896
+ mkdir -p .grok/commands
897
+ ```
898
+
899
+ **`.grok/commands/security.md`**
900
+ ```markdown
901
+ ---
902
+ description: Review code for security vulnerabilities
903
+ ---
904
+
905
+ Review this code for security issues including:
906
+ - SQL injection
907
+ - XSS vulnerabilities
908
+ - Authentication bypasses
909
+ - Sensitive data exposure
910
+
911
+ Focus on the most critical issues first.
912
+ ```
913
+
914
+ Usage: `/security`
915
+
916
+ ### User Commands (Personal, All Projects)
917
+
918
+ Create commands in `~/.grok/commands/`:
919
+
920
+ ```bash
921
+ mkdir -p ~/.grok/commands
922
+ ```
923
+
924
+ **`~/.grok/commands/explain.md`**
925
+ ```markdown
926
+ ---
927
+ description: Explain code in detail
928
+ ---
929
+
930
+ Explain this code in detail:
931
+ - What does each part do?
932
+ - Why was it written this way?
933
+ - Are there any potential issues?
934
+ ```
935
+
936
+ Usage: `/explain`
937
+
938
+ ### Commands with Arguments
939
+
940
+ ```markdown
941
+ ---
942
+ description: Fix a specific GitHub issue
943
+ argument-hint: <issue-number>
944
+ ---
945
+
946
+ Fix GitHub issue #$ARGUMENTS following these guidelines:
947
+ 1. Read the issue description
948
+ 2. Understand the root cause
949
+ 3. Implement the fix
950
+ 4. Add tests if applicable
951
+ 5. Update documentation if needed
952
+ ```
953
+
954
+ Usage: `/fix-issue 123`
955
+
956
+ ### Command Priority
957
+
958
+ 1. **Project commands** (`.grok/commands/`) - highest priority
959
+ 2. **User commands** (`~/.grok/commands/`) - fallback
960
+
961
+ ---
962
+
963
+ ## Security Features
964
+
965
+ Grok Code includes **enterprise-grade security hardening**:
966
+
967
+ ### Path Protection
968
+
969
+ ```
970
+ Blocked Directories:
971
+ ✗ /etc/ # System configuration
972
+ ✗ /proc/ # Process information
973
+ ✗ /sys/ # Kernel parameters
974
+ ✗ /dev/ # Device files
975
+ ✗ /boot/ # Boot files
976
+ ✗ /root/ # Root home directory
977
+
978
+ Attack Prevention:
979
+ ✗ ../../../etc/passwd # Path traversal
980
+ ✗ /home/user/../../../ # Directory escape
981
+ ```
982
+
983
+ ### Sensitive File Detection
984
+
985
+ ```
986
+ Warning Files (allowed with warning):
987
+ ⚠️ .env # Environment variables
988
+ ⚠️ .env.local # Local environment
989
+ ⚠️ credentials.json # API credentials
990
+ ⚠️ secrets.yaml # Secret configuration
991
+ ⚠️ id_rsa # SSH private keys
992
+ ⚠️ *.pem # Certificates
993
+ ```
994
+
995
+ ### Command Protection
996
+
997
+ ```
998
+ Blocked Patterns:
999
+ ✗ rm -rf / # Mass deletion
1000
+ ✗ rm -rf ~ # Home deletion
1001
+ ✗ rm -rf . # Current dir deletion
1002
+ ✗ mkfs.* # Filesystem formatting
1003
+ ✗ dd if=.* of=/dev/ # Device overwriting
1004
+ ✗ curl|sh, wget|bash # Remote code execution
1005
+ ✗ chmod 777 # Dangerous permissions
1006
+ ✗ chown root # Privilege escalation
1007
+ ✗ sudo su # Root access
1008
+ ```
1009
+
1010
+ ### Network Protection (SSRF Prevention)
1011
+
1012
+ ```
1013
+ Blocked Hosts:
1014
+ ✗ localhost # Local services
1015
+ ✗ 127.0.0.1 # Loopback IPv4
1016
+ ✗ ::1 # Loopback IPv6
1017
+ ✗ 0.0.0.0 # All interfaces
1018
+ ✗ 192.168.*.* # Private Class C
1019
+ ✗ 10.*.*.* # Private Class A
1020
+ ✗ 172.16-31.*.* # Private Class B
1021
+ ✗ 169.254.*.* # Link-local
1022
+
1023
+ Blocked Protocols:
1024
+ ✗ file:// # Local files
1025
+ ✗ ftp:// # FTP
1026
+ ✗ gopher:// # Gopher
1027
+ ✗ data:// # Data URLs
1028
+ ```
1029
+
1030
+ ---
1031
+
1032
+ ## Configuration
1033
+
1034
+ ### Config File Location
1035
+
1036
+ ```
1037
+ ~/.config/grokcodecli/config.json
1038
+ ```
1039
+
1040
+ ### Configuration Options
1041
+
1042
+ | Option | Type | Default | Description |
1043
+ |--------|------|---------|-------------|
1044
+ | `apiKey` | string | - | Your xAI API key |
1045
+ | `model` | string | `grok-4-0709` | Default Grok model (reasoning recommended) |
1046
+ | `temperature` | number | `0.7` | Response creativity (0.0 - 1.0) |
1047
+ | `maxTokens` | number | `16384` | Maximum response tokens |
1048
+ | `streaming` | boolean | `true` | Enable token streaming |
1049
+ | `autoApprove` | string[] | `[]` | Tools to auto-approve |
1050
+
1051
+ ### Example Configuration
1052
+
1053
+ ```json
1054
+ {
1055
+ "apiKey": "xai-your-api-key-here",
1056
+ "model": "grok-4-0709",
1057
+ "temperature": 0.7,
1058
+ "maxTokens": 16384,
1059
+ "streaming": true,
1060
+ "autoApprove": ["Read", "Glob", "Grep"]
1061
+ }
1062
+ ```
1063
+
1064
+ ### Environment Variables
1065
+
1066
+ | Variable | Description |
1067
+ |----------|-------------|
1068
+ | `XAI_API_KEY` | Your xAI API key (overrides config) |
1069
+ | `GROK_MODEL` | Default model (overrides config) |
1070
+
1071
+ ---
1072
+
1073
+ ## Session History
1074
+
1075
+ ### Storage Location
1076
+
1077
+ ```
1078
+ ~/.config/grokcodecli/history/
1079
+ ```
1080
+
1081
+ ### What's Saved
1082
+
1083
+ Each session stores:
1084
+ - Full conversation messages
1085
+ - Tool call history
1086
+ - Working directory
1087
+ - Creation timestamp
1088
+ - Last update timestamp
1089
+ - Auto-generated title
1090
+
1091
+ ### Resume Commands
1092
+
1093
+ ```bash
1094
+ # Resume the most recent session
1095
+ grok --resume
1096
+
1097
+ # Resume a specific session by ID
1098
+ grok --resume abc123def
1099
+
1100
+ # List all saved sessions
1101
+ grok
1102
+ /history
1103
+ ```
1104
+
1105
+ ### Session Lifecycle
1106
+
1107
+ ```
1108
+ ┌─────────────────┐
1109
+ │ grok start │
1110
+ └────────┬────────┘
1111
+
1112
+
1113
+ ┌─────────────────┐
1114
+ │ New Session │───────┐
1115
+ │ Created │ │
1116
+ └────────┬────────┘ │
1117
+ │ │
1118
+ ▼ │
1119
+ ┌─────────────────┐ │
1120
+ │ Conversation │◄──────┘
1121
+ │ (auto-saved) │
1122
+ └────────┬────────┘
1123
+
1124
+ ┌────┴────┐
1125
+ │ │
1126
+ ▼ ▼
1127
+ ┌───────┐ ┌───────┐
1128
+ │/save │ │/exit │
1129
+ │ │ │ │
1130
+ └───┬───┘ └───┬───┘
1131
+ │ │
1132
+ ▼ ▼
1133
+ ┌─────────────────┐
1134
+ │ Session Saved │
1135
+ │ ~/.config/... │
1136
+ └─────────────────┘
1137
+
1138
+
1139
+ ┌─────────────────┐
1140
+ │ /resume or │
1141
+ │ grok --resume │
1142
+ └─────────────────┘
1143
+ ```
1144
+
1145
+ ---
1146
+
1147
+ ## Diagnostics
1148
+
1149
+ Run `/doctor` to validate your setup:
1150
+
1151
+ ```
1152
+ 🩺 Running diagnostics...
1153
+
1154
+ ✓ API Key API key is configured
1155
+ ✓ Node.js v18.19.1 (>=18 required)
1156
+ ✓ Working Dir Read/write access confirmed
1157
+ ✓ Config Dir /home/user/.config/grokcodecli
1158
+ ✓ Git Git is available
1159
+ ✓ API Connection Connected to xAI API
1160
+
1161
+ All checks passed! Grok Code is ready.
1162
+ ```
1163
+
1164
+ ### Diagnostic Checks
1165
+
1166
+ | Check | What It Validates |
1167
+ |-------|-------------------|
1168
+ | API Key | Key is configured and has correct format |
1169
+ | Node.js | Version 18.0.0 or higher |
1170
+ | Working Dir | Read/write access to current directory |
1171
+ | Config Dir | Config directory exists and is writable |
1172
+ | Git | Git is installed and accessible |
1173
+ | API Connection | Can reach xAI API and authenticate |
1174
+
1175
+ ---
1176
+
1177
+ ## CLI Options
1178
+
1179
+ ```bash
1180
+ grok [options]
1181
+
1182
+ Options:
1183
+ -V, --version Show version number
1184
+ -r, --resume [id] Resume a previous session
1185
+ -m, --model <model> Use a specific model
1186
+ -p, --prompt <text> Start with an initial prompt
1187
+ -h, --help Show help
1188
+
1189
+ Subcommands:
1190
+ grok auth Configure API key
1191
+ grok config Show configuration
1192
+ grok doctor Run diagnostics
1193
+ ```
1194
+
1195
+ ### Examples
1196
+
1197
+ ```bash
1198
+ # Start a new session
1199
+ grok
1200
+
1201
+ # Resume last session
1202
+ grok --resume
1203
+
1204
+ # Start with a specific model
1205
+ grok --model grok-4-0709
1206
+
1207
+ # Start with a prompt
1208
+ grok --prompt "Help me refactor this function"
1209
+
1210
+ # Run diagnostics
1211
+ grok doctor
1212
+ ```
1213
+
1214
+ ---
1215
+
1216
+ ## Development
1217
+
1218
+ ### Building from Source
1219
+
1220
+ ```bash
1221
+ # Install dependencies
1222
+ npm install
1223
+
1224
+ # Build TypeScript
1225
+ npm run build
1226
+
1227
+ # Development mode (watch)
1228
+ npm run dev
1229
+
1230
+ # Link for local testing
1231
+ npm link
1232
+ ```
1233
+
1234
+ ### Project Structure
1235
+
1236
+ ```
1237
+ grokcodeclix/
1238
+ ├── src/
1239
+ │ ├── cli.ts # CLI entry point & argument parsing
1240
+ │ ├── index.ts # Public API exports
1241
+ │ │
1242
+ │ ├── grok/
1243
+ │ │ └── client.ts # xAI Grok API client
1244
+ │ │
1245
+ │ ├── conversation/
1246
+ │ │ ├── chat.ts # Main interactive loop (900+ lines)
1247
+ │ │ └── history.ts # Session persistence
1248
+ │ │
1249
+ │ ├── config/
1250
+ │ │ └── manager.ts # Configuration management
1251
+ │ │
1252
+ │ ├── permissions/
1253
+ │ │ └── manager.ts # Permission system
1254
+ │ │
1255
+ │ ├── tools/
1256
+ │ │ ├── registry.ts # Tool registration & execution
1257
+ │ │ ├── read.ts # File reading
1258
+ │ │ ├── write.ts # File writing
1259
+ │ │ ├── edit.ts # File editing
1260
+ │ │ ├── bash.ts # Command execution
1261
+ │ │ ├── glob.ts # File pattern matching
1262
+ │ │ ├── grep.ts # Content search
1263
+ │ │ └── webfetch.ts # HTTP requests
1264
+ │ │
1265
+ │ ├── utils/
1266
+ │ │ ├── security.ts # Security validation
1267
+ │ │ └── ui.ts # UI components
1268
+ │ │
1269
+ │ └── commands/
1270
+ │ └── loader.ts # Custom command loader
1271
+
1272
+ ├── dist/ # Compiled JavaScript
1273
+ ├── package.json
1274
+ ├── tsconfig.json
1275
+ └── README.md
1276
+ ```
1277
+
1278
+ ### Code Statistics
1279
+
1280
+ | Metric | Value |
1281
+ |--------|-------|
1282
+ | Total Lines | ~4,000 |
1283
+ | TypeScript Files | 16 |
1284
+ | Tools | 8 |
1285
+ | Slash Commands | 25+ |
1286
+ | Test Coverage | Growing |
1287
+
1288
+ ---
1289
+
1290
+ ## Troubleshooting
1291
+
1292
+ ### Common Issues
1293
+
1294
+ #### "API key not configured"
1295
+
1296
+ ```bash
1297
+ # Set via environment variable
1298
+ export XAI_API_KEY=your_key_here
1299
+
1300
+ # Or use auth command
1301
+ grok auth
1302
+ ```
1303
+
1304
+ #### "Connection refused"
1305
+
1306
+ Check your network connection and ensure you can reach `api.x.ai`:
1307
+ ```bash
1308
+ curl https://api.x.ai/v1/models -H "Authorization: Bearer $XAI_API_KEY"
1309
+ ```
1310
+
1311
+ #### "Permission denied"
1312
+
1313
+ ```bash
1314
+ # Ensure config directory is writable
1315
+ chmod 755 ~/.config/grokcodecli
1316
+ ```
1317
+
1318
+ #### "Command not found: grok"
1319
+
1320
+ ```bash
1321
+ # If installed from source, link it
1322
+ npm link
1323
+
1324
+ # Or add to PATH
1325
+ export PATH="$PATH:$(npm prefix -g)/bin"
1326
+ ```
1327
+
1328
+ ---
1329
+
1330
+ ## Comparison with Claude Code
1331
+
1332
+ | Feature | Grok Code | Claude Code |
1333
+ |---------|-----------|-------------|
1334
+ | AI Model | xAI Grok | Anthropic Claude |
1335
+ | Slash Commands | 25+ | 35+ |
1336
+ | Tools | 7 | 10+ |
1337
+ | Custom Commands | ✓ | ✓ |
1338
+ | Permission System | ✓ | ✓ |
1339
+ | Session Persistence | ✓ | ✓ |
1340
+ | Streaming | ✓ | ✓ |
1341
+ | Security Hardening | ✓ | ✓ |
1342
+ | MCP Support | Planned | ✓ |
1343
+ | IDE Integration | Planned | ✓ |
1344
+ | Cost | xAI pricing | Anthropic pricing |
1345
+
1346
+ ---
1347
+
1348
+ ## Contributing
1349
+
1350
+ We welcome contributions! Here's how to get started:
1351
+
1352
+ ### Development Setup
1353
+
1354
+ ```bash
1355
+ # Fork and clone
1356
+ git clone https://github.com/YOUR_USERNAME/grokcodeclix.git
1357
+ cd grokcodeclix
1358
+
1359
+ # Install dependencies
1360
+ npm install
1361
+
1362
+ # Create a branch
1363
+ git checkout -b feature/your-feature
1364
+
1365
+ # Make changes and test
1366
+ npm run build
1367
+ npm link
1368
+ grok # Test your changes
1369
+
1370
+ # Submit a PR
1371
+ git push origin feature/your-feature
1372
+ ```
1373
+
1374
+ ### Contribution Guidelines
1375
+
1376
+ 1. **Fork** the repository
1377
+ 2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)
1378
+ 3. **Commit** your changes (`git commit -m 'Add amazing feature'`)
1379
+ 4. **Push** to the branch (`git push origin feature/amazing-feature`)
1380
+ 5. **Open** a Pull Request
1381
+
1382
+ ### Code Style
1383
+
1384
+ - Use TypeScript strict mode
1385
+ - Follow existing patterns
1386
+ - Add comments for complex logic
1387
+ - Update documentation for new features
1388
+
1389
+ ---
1390
+
1391
+ ## Roadmap
1392
+
1393
+ - [ ] MCP (Model Context Protocol) support
1394
+ - [ ] IDE integrations (VS Code, JetBrains)
1395
+ - [ ] Multi-file editing mode
1396
+ - [ ] Git integration commands
1397
+ - [ ] Image/vision support with Grok vision models
1398
+ - [ ] Plugin system
1399
+ - [ ] Team collaboration features
1400
+
1401
+ ---
1402
+
1403
+ ## License
1404
+
1405
+ MIT License - see [LICENSE](LICENSE) for details.
1406
+
1407
+ ```
1408
+ MIT License
1409
+
1410
+ Copyright (c) 2024 Grok Code CLI Contributors
1411
+
1412
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1413
+ of this software and associated documentation files (the "Software"), to deal
1414
+ in the Software without restriction, including without limitation the rights
1415
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1416
+ copies of the Software, and to permit persons to whom the Software is
1417
+ furnished to do so, subject to the following conditions:
1418
+
1419
+ The above copyright notice and this permission notice shall be included in all
1420
+ copies or substantial portions of the Software.
1421
+
1422
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1423
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1424
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1425
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1426
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1427
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1428
+ SOFTWARE.
1429
+ ```
1430
+
1431
+ ---
1432
+
1433
+ ## Credits
1434
+
1435
+ Built with these amazing technologies:
1436
+
1437
+ | Technology | Purpose |
1438
+ |------------|---------|
1439
+ | [xAI Grok API](https://x.ai/) | AI models powering the assistant |
1440
+ | [TypeScript](https://www.typescriptlang.org/) | Type-safe development |
1441
+ | [Node.js](https://nodejs.org/) | Runtime environment |
1442
+ | [Chalk](https://github.com/chalk/chalk) | Beautiful terminal styling |
1443
+ | [Commander.js](https://github.com/tj/commander.js) | CLI framework |
1444
+ | [Glob](https://github.com/isaacs/node-glob) | File pattern matching |
1445
+
1446
+ ---
1447
+
1448
+ ## Support
1449
+
1450
+ - **Issues**: [GitHub Issues](https://github.com/singhpratech/grokcodeclix/issues)
1451
+ - **Discussions**: [GitHub Discussions](https://github.com/singhpratech/grokcodeclix/discussions)
1452
+ - **Email**: [Contact maintainers](mailto:support@example.com)
1453
+
1454
+ ---
1455
+
1456
+ <div align="center">
1457
+
1458
+ ### Built with Grok AI
1459
+
1460
+ **[Get Started](#-quick-start)** · **[Documentation](#features)** · **[Contribute](#-contributing)**
1461
+
1462
+ Made with determination by the Grok Code community
1463
+
1464
+ </div>