Terminal Coding Agent · xAI

Grok Build
CLI Cheat Sheet

Grok Build là coding agent của xAI: interactive TUI, headless cho scripts/bot, hoặc điều khiển qua Agent Client Protocol (ACP). Plan Mode duyệt trước khi sửa, tối đa 8 subagent song song, sandbox & worktree tích hợp.

SuperGrok / X Premium+
Getting Started

Quick Start

1

Install

# macOS/Linux
curl -fsSL https://x.ai/cli/install.sh | bash

Windows (PowerShell): irm https://x.ai/cli/install.ps1 | iex

2

Login

cd your-project
grok
# mở browser đăng nhập

Headless/CI: export XAI_API_KEY="xai-..."

3

Start

grok

hoặc grok "Fix the login bug" · kiểm tra setup: grok inspect

Reference

CLI Commands & Flags

Basic Usage

grokMở interactive TUI
grok "prompt"Mở TUI kèm prompt đầu
-p, --single "…"Headless one-shot, in ra stdout
-c, --continueTiếp session gần nhất
-r, --resume [id]Mở lại session theo id/title
grok updateKiểm tra & cài bản mới

Auth & Inspect

grok loginĐăng nhập
grok logoutĐăng xuất
grok inspectConfig, skills, plugins, hooks, MCP
grok inspect --jsonDạng JSON để pipe
grok modelsModel khả dụng cho account
grok versionPhiên bản đang cài

Model & Reasoning

-m, --model <id>Chọn model
--effort <level>Mức reasoning effort
--max-turns <n>Giới hạn số lượt agent
--cwd <path>Đặt thư mục làm việc
--ref <ref>Branch/tag/commit gốc cho worktree

Permissions & Sandbox

--permission-mode <m>Hành vi xin quyền
--always-approve / --yoloAuto-approve mọi tool
--allow '<rule>'Thêm rule cho phép
--deny '<rule>'Thêm rule chặn
--sandbox <profile>off·workspace·read-only·strict·devbox

Output & Headless

--output-format plainText thường (mặc định)
--output-format jsonJSON kèm metadata
--output-format streaming-jsonJSON stream để pipe
--json-schema '…'Ràng buộc structured output
--no-auto-updateTắt check update (CI)
grok agent stdioChế độ ACP cho IDE

Management

grok mcp …Quản lý MCP server
grok plugin …Plugin & marketplace
grok sessions …List·search·delete session
grok worktree …Quản lý Git worktree
grok export / importXuất session · import Claude Code
grok memory clearXóa memory xuyên session
In-Session

Slash Commands

Navigation & Sessions

/helpTrợ giúp command & phím
/newSession mới
/resumeMở lại session cũ
/forkTạo session song song
/sessionsMở Agent Dashboard
/rename <title>Đổi tên session
/exportXuất session hiện tại

Context & Models

/contextXem mức dùng context
/compact [hint]Nén hội thoại
/model <name> · /mĐổi model
/effortĐổi reasoning effort
/personasQuản lý persona
/usage · /costAllowance & billing

Permissions & Modes

/plan [desc]Vào Plan Mode
/goal <objective>Goal-driven mode
/autoTự phân loại quyền
/always-approveBật/tắt auto-approve
/code-reviewChạy review tích hợp
/loop [interval] <p>Chạy prompt định kỳ

Extensions & Diagnostics

/skillsMở tab Skills
/pluginsMở tab Plugins
/mcpsMở tab MCP
/hooksMở tab Hooks
/tasksLệnh chạy nền
/terminal-setupKiểm tra tương thích terminal

Memory & Media

/remember <note>Lưu memory
/memory · /memDuyệt memory
/imagine <prompt>Tạo ảnh
/imagine-video <p>Tạo video
/btw <question>Hỏi phụ (side question)
/feedback [text]Gửi phản hồi tới xAI

Special Prefixes & Skills

@src/main.tsĐính kèm file vào prompt
@src/auth/Đính kèm cả folder
!git statusChạy shell command trực tiếp
/<skill-name>Skill tự tạo thành slash command
/local:commitNamespace tránh trùng tên
/settings · /themeCài đặt · đổi theme
Security

Sandbox Profiles

read-onlySafe

Chỉ đọc, không ghi. Tốt cho phân tích kiến trúc & rà soát bảo mật.

workspaceRecommended

Ghi trong phạm vi workspace. Hợp cho fix & chạy test tự động.

strictLocked

Cô lập chặt nhất, giới hạn tối đa side-effect ra ngoài.

devboxFull env

Môi trường dev container-like. off = tắt sandbox hoàn toàn.

Đặt bằng --sandbox <profile>. Kết hợp --permission-mode, --allow/--deny rule để kiểm soát tool. VD: --allow 'Bash(git *)' · --deny 'Edit(**/.env)' · --deny 'Bash(rm -rf *)'.

Setup

Configuration & Extensions

config.tomlSettings

Config chính: model mặc định, custom model, provider.

~/.grok/config.toml user
%USERPROFILE%\.grok\config.toml Windows
SkillsSlash

Skill tự tạo trở thành /<skill-name> trong TUI.

./.grok/skills/ project
~/.grok/skills/ user
~/.agents/skills/ shared
MCPTools

Kết nối external tool qua Model Context Protocol.

grok mcp add <name> -- <cmd>
grok mcp add --transport http <name> <url>
grok mcp list · grok mcp doctor
PluginsMarketplace

Cài & quản lý plugin từ marketplace.

grok plugin install <name>
grok plugin enable/disable <name>
grok plugin marketplace list

Custom model trong config.toml: khai báo [model.my-model] (model id, base_url, env_key) rồi set [models] default. Command surface thay đổi thường xuyên — luôn kiểm tra bằng /help hoặc grok inspect trước khi automate.

Workflow

Plan Mode

Với task phức tạp, mở /plan. Agent hiện file dự định sửa + các bước triển khai. Bạn duyệt như review PR — approve, comment từng bước, hoặc viết lại toàn bộ trước khi chạy. Khi đã approve, mọi thay đổi hiện dạng diff sạch.

1

Mô tả task

Viết yêu cầu bằng ngôn ngữ tự nhiên. /plan để bắt agent lập kế hoạch trước khi động vào file.

2

Duyệt kế hoạch

Xem file nào đụng & các bước. Approve, comment từng step, hoặc rewrite toàn bộ plan.

3

Chạy & xem diff

Sau approve, mọi thay đổi hiện dạng clean diff để review trước khi giữ.

4

Phân phối subagent

Task lớn tự trải ra tối đa 8 subagent song song để hoàn thành nhanh hơn.

Best Practices

Golden Rules

1

Plan trước, code sau

Dùng /plan cho task phức tạp. Duyệt kế hoạch & diff trước khi giữ thay đổi — bạn là người kiểm soát cuối.

2

@mention đúng phạm vi

Khoanh vùng với @file / @folder/ thay vì để agent quét cả repo — nhanh & đỡ tốn context.

@src/auth/login.ts Fix redirect sau khi đăng nhập
3

Sandbox cho task tự động

Chạy audit read-only với --sandbox read-only. Cho phép ghi thì dùng workspace + --allow/--deny rule cụ thể.

4

Worktree cho việc song song

grok -w tạo git worktree cô lập — chạy nhiều task cùng lúc không đụng nhánh chính. Dọn bằng grok worktree gc.

5

Compact khi context đầy

Cùng task mà context quá dài → /compact. Chuyển hẳn task mới → /new. Xem mức dùng bằng /context.

6

Staged rollout cho CI

Headless: bắt đầu scope hẹp + quyền repo giới hạn, chạy ổn rồi mới mở rộng. Cài bước review phía sau khi không có người giám sát.

Workflows

Quy trình thực tế

Mở project, mô tả task, review diff
$cd my-project && grok
# Mở project + bắt đầu session (auth qua browser lần đầu)
>Fix bug login redirect @src/auth/
# Mô tả task + @mention folder liên quan
⌘Review clean diff → giữ hoặc chỉnh hướng
# Luôn đọc diff trước khi giữ thay đổi
>!npm test
# Chạy test trực tiếp trong TUI (prefix !)
>/compact
# Nén context → tiếp task tiếp theo
Plan trước, duyệt, rồi thực thi
>/plan Refactor auth sang JWT thay cho session
# Vào Plan Mode — agent chỉ lập kế hoạch, chưa sửa
⌘Approve · comment từng step · hoặc rewrite plan
# Duyệt kế hoạch như review một PR
>Thực thi plan @src/auth/
# Sau approve, mọi thay đổi hiện dạng clean diff
>/code-review
# Chạy review tích hợp trước khi commit
>!git add -A && git commit -m "refactor: JWT auth"
# Commit sau mỗi milestone
One-shot, structured output, cho pipeline
# Auth headless
$export XAI_API_KEY="xai-..."
# Audit read-only, không side-effect
$grok --sandbox read-only -p "Analyze architecture & security" --output-format json
# CI review diff, trả JSON theo schema
$grok --no-auto-update --allow 'Read' --allow 'Bash(git *)' -p "Review current diff" --output-format json
# Fix & test tự động trong workspace
$grok --sandbox workspace --always-approve -p "Fix failing tests, run suite, summarize"
# ACP mode cho IDE integration
$grok agent stdio
Chạy song song, cô lập nhánh
$grok --worktree=feat-checkout --ref main
# Worktree mới từ main → task không đụng nhánh chính
$grok worktree list
# Xem các worktree đang có
$grok worktree show <id>
# Chi tiết một worktree
$grok worktree gc --max-age 7d
# Dọn worktree cũ hơn 7 ngày
Resources

Tài liệu & nguồn

Official DocsRead

Overview, install, config, MCP, ACP, headless.

docs.x.ai/build/overview
GitHubSource

xAI coding agent harness & TUI — issues, releases.

github.com/xai-org/grok-build
AnnouncementNews

Bài giới thiệu Grok Build từ xAI.

x.ai/news/grok-build-cli
Verify localCLI

Command surface đổi thường xuyên — check tại chỗ.

grok --help · grok inspect · /help

Yêu cầu subscription SuperGrok hoặc X Premium+. Tham khảo: Layer3 Labs guide, xAI Docs.