Features

Workflows

View as Markdown

A workflow is a JavaScript module that starts subagents in the background and returns one result. Your session stays free while it runs, and the result appears in the conversation when the run finishes. Workflows are on by default.

If the work splits into many independent pieces and should end in one clear report, ask for a workflow. Describe the task in plain language, and Grok plans it as a small script, runs it across parallel agents, and reports back:

Text

use a workflow to review each feature in this PR
audit every route handler for missing auth checks, and verify each finding

This page covers Grok Build 2.0 and later. When you start a Rhai workflow (.rhai) from an earlier version by name, Grok converts it to a .js file beside it, leaves the .rhai file as it is, and starts the new one. If the start sets an agent budget under 1,024, Grok only converts it; run the command again to start it.

Write a workflow

A workflow is one .js file named after the workflow: .grok/workflows/<name>.js at the root of a repository you trust, or ~/.grok/workflows/<name>.js for every project.

For example, save this as .grok/workflows/survey.js:

JavaScript

/**
 * ---
 * name: survey
 * description: Survey a topic with two agents that read and one that merges
 * phase: Explore -- Two agents read the code, one angle each
 * phase: Report -- One agent merges their notes
 * ---
 */

export default async function survey(args) {
  const topic = args?.query ?? "how this project is built and tested";
  const angles = ["where it lives in the code", "how it is tested"];
  const notes = await Promise.all(
    angles.map((angle, i) => {
      const prompt =
        `Read the files in this repository that matter for: ${topic}. ` +
        `Report ${angle}, with file paths.`;
      return host
        .agent(prompt, { label: `Explore/angle-${i + 1}`, readonly: true })
        .wait();
    }),
  );
  const found = notes
    .filter((note) => note.status === "completed")
    .map((note) => note.text);
  const merge =
    "Merge these notes into one short report that keeps the file paths:";
  const report = await host
    .agent(`${merge}\n\n${found.join("\n\n---\n\n")}`, {
      label: "Report/merge",
      readonly: true,
    })
    .wait();
  return report.text;
}

To have Grok write the file instead, run /create-workflow followed by what the workflow should do.

Front matter

The file opens with the comment shown above. Only blank lines and a #! line may come before it; an import or "use strict"; above it stops the file from loading.

KeyRequiredValue
nameYesLowercase letters and digits joined by single hyphens. It must match the file name without .js.
descriptionYesWhat the workflow does. It is also the run's objective when you start the workflow with no arguments.
when_to_useNoWhen the workflow is the right one.
phaseNo<title> -- <detail>; the detail is optional. Repeat the key once per phase, in order, with a different title each time.

Any other key, or a key other than phase given twice, stops the file from loading, and /<name> answers with the reason, such as unknown front-matter key: model.

The default export

The default export is an async function that receives the run's arguments and returns the run's result. The arguments are null when you pass none, a JSON object when you pass one, and { query, objective } holding your text otherwise.

host.agent(prompt, options) starts one agent, and .wait() resolves to its outcome: status ("completed", "failed", or "cancelled") and text, the agent's answer.

OptionEffect
labelThe agent's name in the run view. "Phase/name" lists the agent under the phase with that title.
readonlyWith true, the agent reads and searches files but writes nothing and runs no command, git included. Leave it out for an agent that must run a command or edit files; that agent asks you for approval.
schemaA JSON Schema the agent's answer must match. The outcome's structured holds the parsed answer.
modelThe model ID for this agent. Without it, the agent uses the session's model.

Run a workflow

Type the workflow's name as a slash command, followed by plain text or a JSON object:

Text

/survey how errors are reported
/workflow survey {"query":"how errors are reported"}
CommandWhat it does
/workflow <name> [args]Same as /<name>; required when the name is also a Grok command, such as doctor
/workflowsBrowse the workflows Grok found; Enter opens the selected file
/workflow listList every workflow, and each file Grok skipped and why
/workflow runsList this session's runs, running and finished
/workflow stop <run>Stop a run
/workflow resume <run>With --agent-budget N and a higher N, continue a run that paused at its agent budget
/deep-research <query>Start the built-in research workflow

Grok rescans both folders when you open /workflows, so open it after you add a file if /<name> isn't offered yet.

Watch and stop a run

While a run is going, the dock above the prompt lists it under Workflows. Press Tab until the dock has focus, ↓ to select the run's row, then Enter, to open the run view. /workflow runs lists the session's runs, finished ones included, and Enter opens one. The run view lists the phases from the front matter, with each agent under the phase its label names. Without the dock, the same rows are in the tasks pane (Ctrl+G), under Workflows, with the same keys.

The Workflow Runs view for a survey run with the Explore phase selected: angle-1 and angle-2 finished, and the Report phase running

To stop a run, press x in the run view or on its dock row. A stopped run can't be resumed, you can't pause a run, and Grok can't stop one for you. Quitting Grok stops every unfinished run, so the first quit press warns you.

Scripts Grok writes for you

When you ask for a workflow in plain language, Grok writes a script and runs it without saving a file. Its actions follow your permission mode and rules, and Grok asks before it starts one in the background. The run shows in the conversation as an Execute row and in the dock under Tasks, where x stops it; /workflow runs leaves it out. To run it again later, ask Grok to save it as a workflow.

Learn from your sessions

/learn reads your past sessions on this computer and proposes changes to your setup: a skill for a prompt you keep typing, a fix for a skill instruction you keep correcting, and removal of skills, plugins, and MCP servers you never use. It runs as a background workflow with many agents, so before it starts Grok shows an estimated cost and asks how far back to read. It changes nothing before you've seen its report, and by default applies only the changes you pick.

Limits

  • Workflows start only in agent mode.
  • When two workflows share a name, a built-in such as deep-research wins, then the project's, then yours.

A run starts as many agents as its code asks for. To cap it, pass --agent-budget N (1 to 1,024) before the arguments:

Text

/survey --agent-budget 8 how errors are reported

A run that needs more agents pauses until you resume it with a higher budget.

To turn workflows off, set enabled = false under [workflows] in ~/.grok/config.toml, or set GROK_WORKFLOWS=0.


Last updated: November 30, 2026