> grok cli
xAI's Grok models in a terminal agent — conversational file editing, bash execution, MCP tools, and headless mode, keyed by your xAI API key
// getting started
5 commands// api keys and auth
4 commands// interactive session
6 commands// headless and scripting
4 commandsRun a single prompt and exit
$ grok -p "show me the package.json file"Limit how many tool rounds Grok runs
$ grok --max-tool-rounds 10 -p "show me the current directory"Generate a commit message and push with AI
$ grok git commit-and-pushAutomate Grok inside a CI pipeline
$ grok -p "review the staged diff and flag risky changes" -d . --max-tool-rounds 25// models and endpoints
5 commandsChoose which model a run uses
$ grok -m grok-4-latestSet your default model
$ ~/.grok/user-settings.jsonOverride the API base URL
$ grok --base-url https://api.x.ai/v1Point Grok at an OpenAI-compatible provider
$ ~/.grok/user-settings.jsonRun a non-Grok model like Claude or Gemini
$ grok --model gemini-2.5-pro --base-url https://your-endpoint.example.com/v1// configuration
6 commandsSet global preferences in user-settings.json
$ ~/.grok/user-settings.jsonConfigure a single project with settings.json
$ .grok/settings.jsonGive Grok project-specific instructions
$ .grok/GROK.mdApply the same instructions across all projects
$ ~/.grok/GROK.mdEnable Morph Fast Apply for faster edits
$ export MORPH_API_KEY=your-morph-keyControl which edit tool Grok uses
$ grok -p "refactor this function to use async/await and add error handling"// mcp tools
6 commandsAdd a local stdio MCP server
$ grok mcp add my-server --transport stdio --command "bun" --args server.jsAdd a remote HTTP MCP server
$ grok mcp add my-server --transport http --url "http://localhost:3000"Add an SSE MCP server
$ grok mcp add linear --transport sse --url "https://mcp.linear.app/sse"Add an MCP server from JSON
$ grok mcp add-json my-server '{"command": "bun", "args": ["server.js"], "env": {"API_KEY": "your-key"}}'List, test, and remove MCP servers
$ grok mcp listDefine MCP servers in project settings
$ .grok/settings.json