Learning resourcesReviewed · xAI

Grok CLI Headless & Scripting

Grok CLI Headless & Scripting is a guide for developers automating Grok or integrating it with editor tools, but it assumes an available CLI and leaves installation and costs unspecified. It covers single-prompt commands, resumable sessions, structured output and ACP communication over standard input and output.

Researched 23 Nov 2026

In short.

This Grok CLI guide helps developers connect Grok to scripts, bots and editor tools, but it leaves installation, costs and production reliability unspecified. It documents session controls, three output formats and update suppression for automation. Its JavaScript ACP example shows authentication, session creation and streamed assistant text, with an important distinction between completion metadata and text updates. No commands or example code were executed; runtime behavior and performance are not assessed.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete documentation page at [https://docs.x.ai/build/cli/headless-scripting.md], including its flag table, command examples, session-storage note, update-suppression instructions and JavaScript ACP example. Linked pages and other Grok documentation are excluded. No license notice appears in the supplied page. No commands or code were executed; installation, authentication success, actual outputs, compatibility, reliability, performance and costs remain unverified.

The overview

Identity

Headless & Scripting is a page in xAI's Grok CLI documentation at [https://docs.x.ai/build/cli/headless-scripting.md]. It explains how to invoke the grok executable from scripts and how to connect another application through ACP.

The resource is a technical guide containing command examples, a flag reference and a JavaScript integration sample. It does not identify a specific Grok CLI release.

Assessment

The guide is useful for developers who already have Grok available and need concrete automation syntax. Its strongest practical detail is explaining that ACP assistant text arrives through session/update notifications, while session/prompt returns completion metadata.

The page supports planning an integration and adapting its examples. It supplies no measured evidence of answer quality, latency, reliability or behavior under concurrent workloads.

Users

The intended users include developers building scripts, bots, automated jobs and IDE integrations. Headless mode lets a program send a prompt without using an interactive terminal interface.

Beginners can start with the single-command examples. Adapting the ACP sample requires familiarity with JavaScript promises, child processes, JSON messages and asynchronous events.

Capabilities

The documented flags support sending one prompt, choosing a model, setting a working directory, creating or resuming a named headless session, resuming an existing session and continuing the most recent session in the current directory. Headless sessions are stored in ~/.grok/sessions.

Output can be human-readable text, one final JSON object or incremental newline-delimited JSON events. Other options run the CLI inline, automatically approve tool executions or suppress background update checks. ACP provides a separate interface for IDE and tool integration.

Using it

Requirements

The commands assume the grok executable is available. The ACP example assumes an existing local login or an XAI_API_KEY environment variable. Its JavaScript code uses Node.js built-in modules for child processes, line reading and process access.

The page gives no installation procedure, supported operating-system list, minimum Node.js version, required CLI version or available model identifiers. Account eligibility and network requirements are unspecified.

Mechanism

Headless mode accepts a prompt through -p. The selected output format determines whether the receiving program gets text, a final JSON object or a sequence of JSON events. The page does not define the headless JSON schemas.

ACP starts with grok agent stdio and exchanges JSON-RPC messages through the process's standard input and output streams. The sample initializes the connection, selects an advertised authentication method, authenticates, creates a session and submits a prompt. It matches responses by request ID and accumulates text from agent_message_chunk updates.

Setup

Once the CLI is available, the documented starting command is grok -p "Your prompt here". For the ACP example, authenticate locally with grok login or supply XAI_API_KEY; the client chooses between xai.api_key and cached_token according to the methods the agent advertises.

For automated headless or ACP use, the page recommends --no-auto-update to suppress background update checks. Persistent suppression uses auto_update = false under the [cli] section of ~/.grok/config.toml. Installation and credential provisioning are not explained.

Example

The documented command grok -p "List TODO comments" --output-format json requests one final JSON object. The architecture example uses grok -p "Explain the architecture" --output-format streaming-json to request incremental events. These illustrate invocation syntax; the page includes no resulting output.

The ACP sample spawns grok agent stdio, creates a session in the current working directory and requests a short greeting. It collects assistant text separately from the prompt response, prints the collected text and closes the child process in a finally block. These examples were not executed.

Assessment & evidence

Limitations

The page does not describe exit codes, headless event schemas, rate limits or default tool-approval behavior. The --always-approve option explicitly approves tool executions automatically, but its permission boundaries are not explained.

The ACP sample uses a 30-second timeout for requests and waits for text length to remain unchanged across two checks spaced 150 milliseconds apart. That settling heuristic does not establish a protocol-level guarantee that every text update has arrived.

The displayed sample does not show reconnection, malformed-JSON handling or explicit handling of unexpected child-process exit. It advertises client file and terminal capabilities without showing handlers for those operations. These are observations about the code; their runtime impact was not assessed.

Reasoning

The documented interfaces suggest that headless mode suits applications that mainly need to submit a prompt and consume a result. ACP suits applications needing an explicit session and a stream of protocol messages. These are fit judgments based on the examples.

The clearest integration requirement is to treat ACP completion metadata and assistant text as separate channels. A client that reads only the session/prompt result would miss the text delivered through session/update notifications in the documented sample.

Alternatives

Within this guide, plain output is the human-readable choice, json provides one final object and streaming-json provides incremental events. ACP is the documented option for IDE or tool integration.

The page does not compare competing products, direct API access or other integration protocols. Relative cost, output quality and operational complexity are not assessed.

Evidence

The supporting source is the complete Headless & Scripting documentation page at [https://docs.x.ai/build/cli/headless-scripting.md]. Its evidence consists of explanatory text, a flag table, shell examples, session-storage and update-control notes, and a JavaScript ACP client.

The page provides no execution transcript, benchmark, sample headless JSON output or independent comparison. The findings describe documented behavior and visible code, with operational outcomes unassessed.

Access & freshness

Costs

The page states no subscription price, API rate, included allowance, usage limit or billing rule. An API-key authentication option does not establish what any invocation costs.

Costs for headless prompts, resumed sessions and ACP use remain unknown. No cost estimate or comparison is supported by this page.

Rights

The page contains no license or redistribution permission for its documentation or JavaScript example. Permission to redistribute those materials is unknown from this evidence.

Service terms, ownership of generated output, prompt retention and use of submitted data for training are also unspecified.

Freshness

The documentation was captured on 23 November 2026 at 02:11:00.915 UTC. The page itself supplies no publication date, update date or supported CLI release.

The sample requests protocolVersion 1 during initialization; that value does not identify a Grok CLI software version. Compatibility with a particular installed release is unknown.

Actions

Choose the interface according to what the receiving application needs: readable text, a final structured result, incremental events or an ACP session. Before adopting it, confirm CLI installation requirements, supported model identifiers, authentication, pricing and data-handling terms.

For unattended use, review approval behavior before enabling --always-approve and apply the documented update-suppression setting where appropriate. When adapting the ACP sample, address process failures, client capability handlers and a reliable completion condition. Validate those behaviors in the intended environment; this page does not establish them.

Evidence for this report

selected-page.txtselected · checked 2026-11-23