> ## Documentation Index
> Fetch the complete documentation index at: https://docs.struct.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Struct Build Agent

> Struct's built-in coding agent implements fixes in a sandbox and opens PRs that pass your CI

The Struct Build Agent is a built-in coding agent that can implement fixes directly from an investigation. It runs in a **sandboxed environment** that you configure with execution scripts, secrets, and custom prompts — so the PRs it creates are ready to merge and pass your CI.

<Tip>
  You can also [open investigations in Claude Code or Cursor](/open-in-agent) if you prefer to use your own coding agent.
</Tip>

***

## How It Works

<Steps>
  <Step title="Review the Investigation">
    Struct completes its investigation and presents root cause analysis and a suggested fix
  </Step>

  <Step title="Approve the Fix">
    Click **Approve** in the Slack thread, Linear comment, or the Struct web app
  </Step>

  <Step title="Sandbox Execution">
    Struct creates a branch, implements the fix in a sandboxed environment, and runs your configured build and test scripts
  </Step>

  <Step title="PR Created">
    A pull request is opened with descriptive commit messages and a link back to the investigation
  </Step>
</Steps>

<Warning>
  Always review the investigation and proposed fix before approving. Struct works best with human oversight.
</Warning>

### What Happens During Execution

1. Creates a branch from your default branch (e.g., `struct/fix-checkout-timeout`)
2. Runs your **pre-execution scripts** (dependency installation, environment setup)
3. Implements the proposed changes
4. Runs your **post-execution scripts** (tests, linting, formatting)
5. Commits with descriptive messages
6. Opens a pull request and posts the link back to the original thread

<Note>
  Requires [GitHub](/connections#github) to be connected with write access to the target repository.
</Note>

***

## Per-Repository Configuration

Configure how the Build Agent works with each of your repositories. Go to **Settings** → **Coding Agent** → **Struct** tab.

<Note>
  Requires [GitHub](/connections#github) to be connected.
</Note>

### Settings

| Setting            | Description                                                                                   |
| ------------------ | --------------------------------------------------------------------------------------------- |
| **Custom prompts** | Repository-specific instructions for the agent (e.g., coding conventions, architecture notes) |
| **Build commands** | How to build and test the project                                                             |
| **Branch naming**  | Prefix for branches created by Struct (e.g., `struct/`)                                       |

***

## Pre/Post Execution Scripts

Define scripts that run before and after the Build Agent makes changes. These ensure the sandbox matches your development environment and that every PR passes CI.

**Pre-execution** — Runs before implementing a fix (e.g., dependency installation, environment setup):

```bash theme={null}
npm install
cp .env.example .env
```

**Post-execution** — Runs after changes are made (e.g., tests, linting, formatting):

```bash theme={null}
npm run lint -- --fix
npm run format
npm test
```

<Tip>
  Configure post-execution scripts to match your CI pipeline. This way, the Build Agent catches issues before the PR is even opened.
</Tip>

<Warning>
  Scripts run in the context of your repository. Ensure they're idempotent and don't require interactive input.
</Warning>

***

## Secrets

Add environment variables that the Build Agent needs during execution (e.g., API keys for tests, registry tokens). Manage secrets from **Settings** → **Coding Agent** → **Struct** tab.

Secrets are stored securely and injected into the sandbox environment at runtime.

***

## Best Practices

<CardGroup cols={2}>
  <Card title="Match your CI" icon="circle-check">
    Set post-execution scripts to mirror your CI checks so PRs are ready to merge on first review.
  </Card>

  <Card title="Add custom prompts" icon="pen">
    Include coding conventions, architecture patterns, and preferred libraries so the agent writes code that fits your codebase.
  </Card>

  <Card title="Start with one repo" icon="flask">
    Configure and test the Build Agent on a single repository before rolling out to your full codebase.
  </Card>

  <Card title="Review before approving" icon="eye">
    Always review the investigation findings and proposed approach before approving a fix.
  </Card>
</CardGroup>
