* feat: improve model configuration and settings management - Refactor model configuration system with unified settings approach - Add support for user-level default models and project-level current models - Implement automatic saving of API key and base URL from command line arguments - Remove model descriptions for cleaner UI and easier extensibility - Fix commander.js subcommand argument parsing with fallback mechanism - Improve configuration file structure and priority handling - Add comprehensive model configuration utilities in src/utils/model-config.ts Configuration priority: project current model > user default model > system default Both main command and git subcommand now save credentials automatically * refactor: unify settings management - Add SettingsManager singleton for user/project settings - Eliminate duplicate settings code across files - Clear separation: user settings vs project settings * docs: improve README clarity and organization - Simplify setup section with quick start approach - Consolidate configuration info into unified section - Add clear explanation of user vs project settings - Document OpenAI-compatible API support - Remove duplicate model configuration sections * bump sdk --------- Co-authored-by: Ismail Pelaseyed <homanp@gmail.com>
Grok CLI
A conversational AI CLI tool powered by Grok with intelligent text editor capabilities and tool usage.
Features
- 🤖 Conversational AI: Natural language interface powered by Grok-3
- 📝 Smart File Operations: AI automatically uses tools to view, create, and edit files
- ⚡ Bash Integration: Execute shell commands through natural conversation
- 🔧 Automatic Tool Selection: AI intelligently chooses the right tools for your requests
- 🔌 MCP Tools: Extend capabilities with Model Context Protocol servers (Linear, GitHub, etc.)
- 💬 Interactive UI: Beautiful terminal interface built with Ink
- 🌍 Global Installation: Install and use anywhere with
npm i -g @vibe-kit/grok-cli
Installation
Prerequisites
- Node.js 16+
- Grok API key from X.AI
Global Installation (Recommended)
npm install -g @vibe-kit/grok-cli
Local Development
git clone <repository>
cd grok-cli
npm install
npm run build
npm link
Setup
-
Get your Grok API key from X.AI
-
Set up your API key (choose one method):
Method 1: Environment Variable
export GROK_API_KEY=your_api_key_here
Method 2: .env File
cp .env.example .env
# Edit .env and add your API key
Method 3: Command Line Flag
grok --api-key your_api_key_here
Method 4: User Settings File
Create ~/.grok/user-settings.json:
{
"apiKey": "your_api_key_here"
}
Custom Base URL (Optional)
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):
Method 1: Environment Variable
export GROK_BASE_URL=https://your-custom-endpoint.com/v1
Method 2: Command Line Flag
grok --api-key your_api_key_here --base-url https://your-custom-endpoint.com/v1
Method 3: User Settings File
Add to ~/.grok/user-settings.json:
{
"apiKey": "your_api_key_here",
"baseURL": "https://your-custom-endpoint.com/v1"
}
Configuration Files
Grok CLI uses two types of configuration files to manage settings:
User-Level Settings (~/.grok/user-settings.json)
This file stores global settings that apply across all projects. These settings rarely change and include:
- API Key: Your Grok API key
- Base URL: Custom API endpoint (if needed)
- Default Model: Your preferred model (e.g.,
grok-4-latest) - Available Models: List of models you can use
Example:
{
"apiKey": "your_api_key_here",
"baseURL": "https://api.x.ai/v1",
"defaultModel": "grok-4-latest",
"models": [
"grok-4-latest",
"grok-3-latest",
"grok-3-fast",
"grok-3-mini-fast"
]
}
Project-Level Settings (.grok/settings.json)
This file stores project-specific settings in your current working directory. It includes:
- Current Model: The model currently in use for this project
- MCP Servers: Model Context Protocol server configurations
Example:
{
"model": "grok-3-fast",
"mcpServers": {
"linear": {
"name": "linear",
"transport": "stdio",
"command": "npx",
"args": ["@linear/mcp-server"]
}
}
}
How It Works
- Global Defaults: User-level settings provide your default preferences
- Project Override: Project-level settings override defaults for specific projects
- Directory-Specific: When you change directories, project settings are loaded automatically
- Fallback Logic: Project model → User default model → System default (
grok-4-latest)
This means you can have different models for different projects while maintaining consistent global settings like your API key.
Using Other API Providers
Important: Grok CLI uses OpenAI-compatible APIs. You can use any provider that implements the OpenAI chat completions standard.
Popular Providers:
- X.AI (Grok):
https://api.x.ai/v1(default) - OpenAI:
https://api.openai.com/v1 - OpenRouter:
https://openrouter.ai/api/v1 - Groq:
https://api.groq.com/openai/v1
Example with OpenRouter:
{
"apiKey": "your_openrouter_key",
"baseURL": "https://openrouter.ai/api/v1",
"defaultModel": "anthropic/claude-3.5-sonnet",
"models": [
"anthropic/claude-3.5-sonnet",
"openai/gpt-4o",
"meta-llama/llama-3.1-70b-instruct"
]
}
Usage
Interactive Mode
Start the conversational AI assistant:
grok
Or specify a working directory:
grok -d /path/to/project
Headless Mode
Process a single prompt and exit (useful for scripting and automation):
grok --prompt "show me the package.json file"
grok -p "create a new file called example.js with a hello world function"
grok --prompt "run npm test and show me the results" --directory /path/to/project
This mode is particularly useful for:
- CI/CD pipelines: Automate code analysis and file operations
- Scripting: Integrate AI assistance into shell scripts
- Terminal benchmarks: Perfect for tools like Terminal Bench that need non-interactive execution
- Batch processing: Process multiple prompts programmatically
Model Selection
You can specify which AI model to use with the --model parameter or GROK_MODEL environment variable:
Method 1: Command Line Flag
# Use Grok models
grok --model grok-4-latest
grok --model grok-3-latest
grok --model grok-3-fast
# Use other models (with appropriate API endpoint)
grok --model gemini-2.5-pro --base-url https://api-endpoint.com/v1
grok --model claude-sonnet-4-20250514 --base-url https://api-endpoint.com/v1
Method 2: Environment Variable
export GROK_MODEL=grok-4-latest
grok
Method 3: User Settings File
Add to ~/.grok/user-settings.json:
{
"apiKey": "your_api_key_here",
"defaultModel": "grok-4-latest"
}
Model Priority: --model flag > GROK_MODEL environment variable > user default model > system default (grok-4-latest)
Command Line Options
grok [options]
Options:
-V, --version output the version number
-d, --directory <dir> set working directory
-k, --api-key <key> Grok API key (or set GROK_API_KEY env var)
-u, --base-url <url> Grok API base URL (or set GROK_BASE_URL env var)
-m, --model <model> AI model to use (e.g., grok-4-latest, grok-3-latest) (or set GROK_MODEL env var)
-p, --prompt <prompt> process a single prompt and exit (headless mode)
-h, --help display help for command
Custom Instructions
You can provide custom instructions to tailor Grok's behavior to your project by creating a .grok/GROK.md file in your project directory:
mkdir .grok
Create .grok/GROK.md with your custom instructions:
# Custom Instructions for Grok CLI
Always use TypeScript for any new code files.
When creating React components, use functional components with hooks.
Prefer const assertions and explicit typing over inference where it improves clarity.
Always add JSDoc comments for public functions and interfaces.
Follow the existing code style and patterns in this project.
Grok will automatically load and follow these instructions when working in your project directory. The custom instructions are added to Grok's system prompt and take priority over default behavior.
MCP Tools
Grok CLI supports MCP (Model Context Protocol) servers, allowing you to extend the AI assistant with additional tools and capabilities.
Adding MCP Tools
Add a custom MCP server:
# Add an stdio-based MCP server
grok mcp add my-server --transport stdio --command "node" --args server.js
# Add an HTTP-based MCP server
grok mcp add my-server --transport http --url "http://localhost:3000"
# Add with environment variables
grok mcp add my-server --transport stdio --command "python" --args "-m" "my_mcp_server" --env "API_KEY=your_key"
Add from JSON configuration:
grok mcp add-json my-server '{"command": "node", "args": ["server.js"], "env": {"API_KEY": "your_key"}}'
Linear Integration Example
To add Linear MCP tools for project management:
# Add Linear MCP server
grok mcp add linear --transport sse --url "https://mcp.linear.app/sse"
This enables Linear tools like:
- Create and manage Linear issues
- Search and filter issues
- Update issue status and assignees
- Access team and project information
Managing MCP Servers
# List all configured servers
grok mcp list
# Test server connection
grok mcp test server-name
# Remove a server
grok mcp remove server-name
Available Transport Types
- stdio: Run MCP server as a subprocess (most common)
- http: Connect to HTTP-based MCP server
- sse: Connect via Server-Sent Events
Development
# Install dependencies
npm install
# Development mode
npm run dev
# Build project
npm run build
# Run linter
npm run lint
# Type check
npm run typecheck
Architecture
- Agent: Core command processing and execution logic
- Tools: Text editor and bash tool implementations
- UI: Ink-based terminal interface components
- Types: TypeScript definitions for the entire system
License
MIT