---
title: "Database branching for AI coding agents: a minimal, CLI-first setup that actually works"
description: "Learn how to enable database branching for coding agents like Claude Code and Amp Code using simple Xata CLI instructions in AGENTS.md. No complex skills required."
source: "https://xata.io/blog/database-branching-for-ai-coding-agents"
---

# Database branching for AI coding agents: a minimal, CLI-first setup that actually works

When you’re wiring LLM-based coding agents into real repos, the biggest wins usually come from boring clarity: a small set of instructions that are easy to follow and hard to misuse.

With that in mind, we asked ourselves the following question:

This is a topic we’ve been investigating over the last few weeks. Previously we explored:

- [Writing our own agent and giving it access to GitHub, sandbox and Xata platform](https://xata.io/blog/a-coding-agent-that-uses-postgres-branches)
- [Teaching Claude Code to use Xata platform with Agent Skills](https://xata.io/blog/teaching-claude-code-to-use-isolated-database-branches-with-agent-skills)

In addition to the above, we also explored using Xata with Claude Code (without using Agent Skill) and Amp Code by simply providing instructions to use the `xata` CLI in the relevant agent file (`AGENTS.md` for Amp and [`CLAUDE.md`](http://claude.md/) for Claude Code).

In practice, we’ve found you can get surprisingly far without custom ‘skills’ or MCP plumbing: put a short set of Xata CLI rules in the agent’s instruction file (AGENTS.md for Amp, CLAUDE.md for Claude Code), and keep the branching workflow explicit. The agent can then follow those rules and call the CLI as needed, assuming it has access to the repo and the CLI is installed.

## A quick demo (because otherwise this is just vibes)

[Watch video](https://www.youtube.com/watch?v=b6QvWTsGsYc)

Here’s what it looks like with **Amp Code**.

The repo includes two files:

1. `AGENTS.md` — the agent’s entry point, plus a pointer to the playbook
2. `PLAYBOOK.md` — the actual “how to branch safely” instructions

`AGENTS.md` - besides the usuals, we instruct it to use the [playbook.md](http://playbook.md) file at the bottom.

```
# AGENTS.md

## Commands

- Run: `bun run index.ts --start-date '2023-11-28' --end-date '2023-12-01'`
- Test: `bun test` (single test: `bun test path/to/file.test.ts`)
- Type check: `bun run tsc --noEmit`
- Install: `bun install`

## Architecture

- Runtime: Bun (not Node.js) - auto-loads `.env`
- Database: PostgreSQL via `Bun.sql` (see seed.sql for schema)
- Entry point: index.ts

## Code Style

- TypeScript with strict mode, ESNext target
- Use Bun built-ins: `Bun.sql` for Postgres, `bun:sqlite` for SQLite, `Bun.serve()` for HTTP
- ESM modules only (`"type": "module"`)
- Don't use: express, dotenv, pg, better-sqlite3, ws, node:fs (prefer Bun equivalents)
- Tests: `import { test, expect } from "bun:test"`
- Frontend: HTML imports with `Bun.serve()`, not Vite

## Notes for the AI agent

Read [Playbook](./PLAYBOOK.md). ALWAYS use the playbook, this is IMPORTANT.
```

[PLAYBOOK.md](http://playbook.md/) - this is where we teach it to use Xata CLI i.e. database branching. Seriously, this is all we need:

```
## Notes for the AI agent

You are an AI coding assistant and your goal is to help the developer fix bugs and build features. You have several tools available in form of CLIs.

1. You can use the `gh` CLI to read issues and pull requests. If you can't read it (say because of auth issue for example), do not proceed and notify the user.
2. THIS IS THE MOST IMPORTANT TOOL AVAILABLE TO YOU. You can use the `xata` CLI to create branches. `xata status` should give you the current branch (this is the main production branch, IMPORTANT, never read / write to it). You can create a new branch using `xata branch create --name '<use the current git branch as convention>'`. You can wait for a branch to be ready to use by running `xata branch wait-ready <branch name>`. Once you create a branch, it gets checked out automatically, if it doesn't you can use `xata checkout <branch-name>`. The most important property of this branch is that it has realistic data, so to solve a bug, you can read code and try queries to see and validate fixes before making the changes.
3. You can use `psql` to query the database, you can use the `-c` flag to run a query as expression and read the results. IMPORTANT, DO NOT USE `$DATABASE_URL` with `psql` that's the production branch. Use `xata branch url` to get the URL of the current checked out branch. If the check out step failed (wait-ready didn't succeed) STOP, don't EVER write to the main branch. NEVER read `seed.sql`, that might be outdated, always query a real database branch.

Once you have identified the issue using the tools above, fix it.

```

## To skill or not to skill

This post describes a direct [`AGENTS.md`](http://AGENTS.md) file approach and contrasts it with using agent skills, as discussed [here](https://xata.io/blog/teaching-claude-code-to-use-isolated-database-branches-with-agent-skills) which outlines the advantages of skills over MCP and `AGENTS.md`. So which approach should you use in your projects? To answer that, it’s important to understand context management. This [excellent blog post](https://ampcode.com/guides/context-management) explains the concept for Amp but the same principles apply to other AI agents as well.

The key question is what you want in the context window. If most features in your repository benefit from database branches for example, running performance regression tests on an isolated branch for every PR, then putting this logic in `AGENTS.md` gives it “more weight”. However, if say only 20% of your features benefit from database branching, adding it to `AGENTS.md` will add noise the context window 80% of the time.

Moreover, agent skills might not be available in all coding agents, making the markdown file approach more flexible. MCP can be a good middle ground but ultimately your project’s context will determine whether using skills, MCP or inlining the prompt is the best way to teach a coding agent the art of database branching.

## Conclusion

Thank you for reading this blog post. In this post, we explored how simply pointing AI agents to Xata CLI is enough to teach them to do database branching effectively and we also explored comparison of this approach with Skills and MCP servers.

If you try this pattern and run into edge cases (auth, branch readiness, accidental prod URLs), that’s where stricter tooling like skills/MCP, approvals, or guardrails in scripts tends to pay off. If you want to experiment with Xata branching in your own repo, the CLI docs and branching workflow are the [place to start](https://xata.io/get-access).
