Let higher-level skills rely on grok-cli's JSON output, error codes, and recovery flow instead of scattering auth, state, and capability logic across multiple scripts.
The repository includes skills/grok-cli/SKILL.md as the recommended user entrypoint. That skill runs the user's requested command directly when possible, installs or repairs grok-cli only when needed, handles OAuth after real auth failures, and retries the user's original Grok task after recovery.
- Prefer
--json. - Do not rely on the default streaming behavior for automation.
- Treat standard output as machine-consumable by default.
- Use standard error for logs and debug details only.
- Do not assume the CLI is already installed when running through a skill.
- Do not run
status, login checks, refresh checks, entitlement checks, or capability probes before routine user tasks. - Run the user's real command first; recover only from actual shell or JSON errors.
- Preserve the user's prompt, query, text, file paths, URLs, and requested output format exactly when building the command. Only quote, escape, choose flags, or resolve paths as mechanically required.
Notes:
chatandsearchstream readable text by default for humans.- Skills, scripts, and automation should use
--jsonconsistently. - Use
--raw-streamonly when the caller can handle normalized stream events.
- Build the user's original command, for example
search --json --query "...". - Run it directly.
- If it succeeds, render the result.
- If it fails, recover from the actual error and retry the original command once.
- Enter this flow only if the shell cannot find
grok-clior the required subcommand is missing. - Install or repair it.
- Verify
--versionand--help. - Retry the original Grok task.
- If that task reports auth trouble, enter auth recovery.
- Prefer
error.recovery_actionwhen the JSON error includes it. This field is the CLI's single recovery decision and should override ad hoc interpretation ofcode,message,relogin_required, orentitlement_denied. refresh_then_retry: runrefresh --json, then retry the original command once.login_then_retry: runlogin, then retry the original command once.wait_then_retry: wait forerror.retry_after_seconds, then retry the original command once.fix_args_then_retry: correct a clear command-shape issue, then retry once.stop_billing,stop_quota,stop_rate_limit, andstop_entitlementmean the caller should stop and surface the blocker. Do not reinstall, refresh, or relogin for these blockers.- For old binaries without
recovery_action, use fallback matching: credential-validation failures refresh, relogin-required failures login, pure billing/quota/rate-limit/entitlement blockers stop. - Invalid arguments should be corrected in the command shape rather than surfaced to the user as CLI confusion.
The skill should default to lossless human-readable rendering: parse the JSON envelope, extract command-specific primary fields, and display their values exactly as returned. Mention any recovery work such as installation, login, or refresh in a separate short note after the result.
- For
chat --json, returndata.output_textexactly. - For
search --json, returndata.answerexactly and preservedata.citations/data.inline_citationswhen exposing citations. - For
stt --json, returndata.transcriptexactly. - For media commands, return exact paths, URLs, request ids, media tags, or handles from the JSON fields.
- Do not summarize, paraphrase, translate, reorder, trim, markdown-polish, or reformat Grok text unless the user explicitly asks for that transformation.
- If the user asks for raw CLI output or raw JSON, return the complete stdout/stderr payload unchanged except for the minimal fencing needed to display it safely.