---
title: "AI Agents - Xata"
description: "Use Xata branches and anonymized Postgres data safely with AI coding agents."
source: "https://xata.io/docs/ai-agents/overview"
---

Skip to main content

# ​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.

[Get started](/quickstart)[Explore branching](/core-concepts/branching)

## ​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.

## Claude Code

Terminal-first workflows for branch-scoped migrations, tests, and database inspection.

## Codex

Sandbox-friendly workflows for running tests and edits against a dedicated Xata branch.

## Cursor

IDE and background-agent setup with `.env.local` connection strings and reviewable schema changes.

## OpenCode

Provider-agnostic terminal agent workflows using standard Postgres and the Xata CLI.

## GitHub Copilot

VS Code and GitHub workflows for per-PR branches and CI-backed database checks.

## Windsurf

Cascade and Flow patterns for repeatable branch creation, migration testing, and cleanup.

## Cline

Approval-based VS Code workflows with safe terminal commands and branch-scoped credentials.

## Devin

Long-running cloud-agent tasks with isolated branches, scoped credentials, and explicit cleanup.

## ​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?

## Isolated branches

Give every agent, pull request, or experiment its own Postgres branch without copying the full database.

## Anonymized production clones

Let agents test against realistic data while masking sensitive values before the branch is used.

## Schema safety

Ask agents to generate or test migrations against a branch before applying changes to production.

## Postgres compatibility

Use normal Postgres drivers, ORMs, extensions, and connection strings with agent-generated code.

## Scale to zero

Keep temporary agent branches inexpensive when they are idle.

## Automation ready

Create branch-per-PR and branch cleanup workflows for teams using coding agents in CI.

## ​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.

```
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)

## Claude Code

Use Claude Code with isolated Xata branches and branch-scoped Postgres connection strings.

## Codex

Use Codex with Xata branches for sandboxed coding sessions and database-aware tests.

## Cursor

Use Cursor with Xata branch connection strings for IDE and background-agent workflows.

## OpenCode

Use OpenCode with standard Postgres URLs and Xata CLI workflows.

## GitHub Copilot

Use GitHub Copilot with Xata per-PR branches and CI-backed database workflows.

## Windsurf

Use Windsurf Cascade and Flows with repeatable Xata branch workflows.

## Cline

Use Cline with approval-based Xata branch workflows in VS Code.

## Devin

Use Devin with temporary Xata branches, scoped credentials, and explicit cleanup.

Was this page helpful?
