# BUILD: write, compile, and save

import { Steps } from "@astrojs/starlight/components"

**BUILD** turns a ready THINK plan into a saved Studio flow. Your coding agent writes one TypeScript file per flow, and
the Mindflow MCP server compiles it. The agent then saves the flow's latest version in the environment your plan names
and shares a link that opens it in Studio. Saving does not start a run.

## When to use

- THINK finished: the plan is ready and your design answers (environment, credentials, create or update) are filled.
- Prefer [THINK: discover and design](../think-discover-and-design/) when the brief or plan is missing or you need to
  change operations.
- Prefer [RUN: try, fix, and roll back](../run-the-automation/) when the flow is saved and you want to try it.
- Prefer [AI··Build](../../design-your-flow/ai-build-faster-flow-creation/) when you want to add steps on a canvas that
  already exists in Studio.

Before you begin, [connect your coding agent](../connect-your-coding-agent/) and finish THINK in a **prior** chat. Open a
**new** chat for BUILD so the interview is not replayed.

## Guide

### Start BUILD from the ready plan

BUILD reads `src/think/plan.json` and `src/think/selections.json` in your application folder. It copies operation ids
from the catalog; it does not invent connectors.

1. **Open a new chat.** Do not continue BUILD in the THINK chat.
2. **Ask to continue the build.** Ask the agent to continue the Mindflow build. When the plan is ready, the agent starts
   BUILD; otherwise it goes back to THINK.
3. **Check create or update.** The agent follows your design answers: it creates new flows, or updates only the flows
   you named.
4. **Let it load operation details.** The agent reads what each selected operation needs from the catalog, plus
   transforms and models when the plan uses them.

### Compile through the Mindflow MCP server

Compiling is a Mindflow service call, not a tool on your computer. If compile reports findings, the agent fixes the
TypeScript and compiles again. You never paste flow JSON by hand.

1. **Wait for compile.** The agent sends each TypeScript file to the Mindflow MCP server.
2. **Review findings.** If compile fails, the agent names the step and field to fix, fixes the TypeScript, and
   compiles again. If the plan needs something the flow format cannot express, the agent stops and tells you.
3. **Check the local files.** The TypeScript files stay under `src/`. Compile returns findings only; it does not write
   files.

### Save and open in Studio

Once compile succeeds, the agent saves each flow with the access you approved at sign-in. Each flow it builds has one
deployment in your plan's environment that follows the flow's **latest** version, so each save shows up there.

1. **Let the agent save a new flow.** For a new flow, the agent creates the flow and its deployment, saves the compiled
   flow, and binds the credentials your design answers named. It leaves other credentials for you to bind in Studio.
2. **Let the agent update an existing flow.** For an update, the agent first reads the latest version. If someone
   changed the flow in Studio since the last save, the agent refreshes its local file and tells you. Before its first
   overwrite in a session, it saves a checkpoint version named **Before AI Build: …** so you can roll back.
3. **Open the Studio link.** The agent shares a link to the flow. Open it to review the canvas and bind any remaining
   credentials.
4. **Try it.** When your design answers said every product can be called, the agent offers to try the flow in the same
   chat. See [RUN: try, fix, and roll back](../run-the-automation/).

## Example

The SOC analyst's plan for **Triage malicious webhook IPs** is ready (VirusTotal lookup, Slack post on a malicious
reputation, environment **Docs**). They start BUILD in a new Claude Code chat.

1. **Ask to continue.** They ask the agent to continue the Mindflow build.
2. **Compile.** The first compile succeeds. The TypeScript file is under `triage-malicious-webhook-ips/src/`.
3. **Open the Studio link.** The agent creates the flow, saves it to **Docs**, binds the VirusTotal and Slack
   credentials from the plan, and shares the link. Nothing has run yet. The agent offers to try it.

## Keep in mind

- Never put secrets in chat, TypeScript, or the agent's tool calls. Credentials bind the way your design answers said.
- Do not ask the agent to compile on your computer. Compile happens on the Mindflow MCP server only.
- If someone saves the flow in Studio while the agent works, the agent reads it again and re-applies its change. It
  never overwrites a newer save.
- Renaming a step in the TypeScript replaces that step in Studio. Its canvas position, run history, and credential
  binding are lost, and the agent warns you.
- BUILD never runs or deletes flows. Promoting to Live, pinning a version, and deleting stay in Studio. See
  [Manage version and deployments](../../../operate/manage-version-and-deployments/).

## Related

[THINK: discover and design](../think-discover-and-design/) · [RUN: try, fix, and roll back](../run-the-automation/) ·
[Manage version and deployments](../../../operate/manage-version-and-deployments/)
