← 返回命令列表

Linux command

grok 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Start an interactive session

grok

Start in a specific directory

grok -d [path/to/project]

Run a one-off command

grok -p "[prompt]"

Specify a different model

grok -m [grok-4-latest]

Run with custom API key

grok -k [your_api_key]

Add an MCP server

grok mcp add [server-name] --transport stdio --command bun --args [server.js]

说明

Grok CLI is an open-source AI agent that brings xAI's Grok directly into the terminal. It provides a conversational interface for coding assistance, file operations, and shell command execution through natural language. The tool operates in two modes: interactive mode for extended sessions with ongoing dialogue, and headless mode (-p) for scripted automation and one-off commands. Grok can navigate codebases, view and edit files, run bash commands, and intelligently select appropriate tools for requested tasks.

参数

-V, --version
Display version information.
-d, --directory _path_
Set working directory for the session.
-k, --api-key _key_
Provide xAI Grok API credentials.
-u, --base-url _url_
Custom API endpoint (default: https://api.x.ai/v1).
-m, --model _model_
Specify AI model (grok-4-latest, grok-3-latest, grok-3-fast, grok-3-mini-fast, grok-code-fast-1).
-p, --prompt _text_
Execute single prompt in headless mode and exit.
--max-tool-rounds _n_
Limit the number of tool execution rounds.
-h, --help
Display help documentation.

FAQ

What is the grok command used for?

Grok CLI is an open-source AI agent that brings xAI's Grok directly into the terminal. It provides a conversational interface for coding assistance, file operations, and shell command execution through natural language. The tool operates in two modes: interactive mode for extended sessions with ongoing dialogue, and headless mode (-p) for scripted automation and one-off commands. Grok can navigate codebases, view and edit files, run bash commands, and intelligently select appropriate tools for requested tasks.

How do I run a basic grok example?

Run `grok` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -V, --version do in grok?

Display version information.