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

# AI Agents

> Use Xata branches and anonymized Postgres data safely with AI coding agents.

# Postgres for AI coding agents

AI coding agents work best when they can run commands, inspect schema, apply migrations, and test against realistic data. Xata gives each agent an isolated Postgres branch, so agent work can happen against real database state without writing to production.

<div className="not-prose mb-8 mt-6 flex flex-col gap-3 sm:flex-row">
  <a href="/docs/quickstart" className="inline-flex items-center justify-center rounded-lg bg-primary px-5 py-3 text-sm font-semibold text-white transition hover:bg-primary/90">
    Get started
  </a>

  <a href="/docs/core-concepts/branching" className="inline-flex items-center justify-center rounded-lg border border-gray-200 px-5 py-3 text-sm font-semibold text-gray-900 transition hover:border-primary hover:text-primary dark:border-gray-800 dark:text-gray-100 dark:hover:border-primary-light dark:hover:text-primary-light">
    Explore branching
  </a>
</div>

## Agent directory

Use the guide for your coding agent to create an isolated branch, pass the branch connection string to the agent, and keep schema or data changes scoped to that branch until you review them.

<CardGroup cols={2}>
  <Card title="Claude Code" icon="terminal" href="/docs/ai-agents/claude-code">
    Terminal-first workflows for branch-scoped migrations, tests, and database inspection.
  </Card>

  <Card title="Codex" icon="code" href="/docs/ai-agents/codex">
    Sandbox-friendly workflows for running tests and edits against a dedicated Xata branch.
  </Card>

  <Card title="Cursor" icon="arrow-pointer" href="/docs/ai-agents/cursor">
    IDE and background-agent setup with `.env.local` connection strings and reviewable schema changes.
  </Card>

  <Card title="OpenCode" icon="terminal" href="/docs/ai-agents/opencode">
    Provider-agnostic terminal agent workflows using standard Postgres and the Xata CLI.
  </Card>

  <Card title="GitHub Copilot" icon="github" href="/docs/ai-agents/github-copilot">
    VS Code and GitHub workflows for per-PR branches and CI-backed database checks.
  </Card>

  <Card title="Windsurf" icon="wind" href="/docs/ai-agents/windsurf">
    Cascade and Flow patterns for repeatable branch creation, migration testing, and cleanup.
  </Card>

  <Card title="Cline" icon="check-double" href="/docs/ai-agents/cline">
    Approval-based VS Code workflows with safe terminal commands and branch-scoped credentials.
  </Card>

  <Card title="Devin" icon="cloud" href="/docs/ai-agents/devin">
    Long-running cloud-agent tasks with isolated branches, scoped credentials, and explicit cleanup.
  </Card>
</CardGroup>

## Compare agents

| Agent          | Best for                                        | Interface         | Uses terminal | Recommended Xata workflow                                                           |
| -------------- | ----------------------------------------------- | ----------------- | ------------- | ----------------------------------------------------------------------------------- |
| Claude Code    | Terminal-based implementation and debugging     | Terminal          | Yes           | Create one branch per task, run migrations and tests, then review diffs             |
| Codex          | Sandboxed coding sessions and repo-wide edits   | Terminal          | Yes           | Give Codex a branch connection string and ask it to keep all database writes scoped |
| Cursor         | IDE-assisted feature work and background agents | IDE               | Yes           | Store the branch URL in `.env.local` and review schema changes before merging       |
| OpenCode       | Open-source, provider-agnostic agent loops      | Terminal          | Yes           | Use standard Postgres URLs and Xata CLI commands from a local shell                 |
| GitHub Copilot | VS Code edits and GitHub pull request workflows | IDE               | Optional      | Pair Copilot with per-PR Xata branches in GitHub Actions                            |
| Windsurf       | Multi-step IDE flows with Cascade               | IDE               | Yes           | Create a Flow for branch creation, migration testing, and cleanup                   |
| Cline          | Human-approved autonomous changes               | VS Code extension | Yes           | Approve each Xata command and inspect generated SQL before applying                 |
| Devin          | Long-running cloud implementation tasks         | Cloud agent       | Yes           | Provision a temporary branch and scoped key for the task, then delete both          |

## Why Xata for agents?

<CardGroup cols={2}>
  <Card title="Isolated branches" icon="code-branch" href="/docs/core-concepts/branching">
    Give every agent, pull request, or experiment its own Postgres branch without copying the full database.
  </Card>

  <Card title="Anonymized production clones" icon="user-shield" href="/docs/core-concepts/anonymization">
    Let agents test against realistic data while masking sensitive values before the branch is used.
  </Card>

  <Card title="Schema safety" icon="code-merge" href="/docs/core-concepts/schema-changes">
    Ask agents to generate or test migrations against a branch before applying changes to production.
  </Card>

  <Card title="Postgres compatibility" icon="database" href="/docs/platform/extensions">
    Use normal Postgres drivers, ORMs, extensions, and connection strings with agent-generated code.
  </Card>

  <Card title="Scale to zero" icon="power-off" href="/docs/core-concepts/scale-to-zero">
    Keep temporary agent branches inexpensive when they are idle.
  </Card>

  <Card title="Automation ready" icon="gears" href="/docs/automations/ga-pr">
    Create branch-per-PR and branch cleanup workflows for teams using coding agents in CI.
  </Card>
</CardGroup>

## Recommended baseline

1. Create or choose a parent branch with the schema and data the agent should use.
2. Create a dedicated branch for the agent task.
3. Give the agent only the branch connection string or a scoped API key.
4. Ask the agent to run migrations, tests, and data changes only against that branch.
5. Review code, SQL, schema diffs, and Xata branch state before merging.
6. Delete the temporary branch when the task is done.

```bash theme={null}
xata branch create --name agent-task --parent-branch `xata branch get id`
xata branch url agent-task
```

## Related docs

* [Quickstart](/docs/quickstart)
* [Instant Branching](/docs/core-concepts/branching)
* [Data Anonymization](/docs/core-concepts/anonymization)
* [Schema Changes](/docs/core-concepts/schema-changes)
* [API Keys](/docs/platform/api-key)
* [Create a branch per pull request](/docs/automations/ga-pr)
