Skip to content

AI & Agents

AI Instruction Files

Every assistant wants its rules in a different file. Claude Code reads CLAUDE.md, Cursor reads .cursorrules, Windsurf reads .windsurfrules, Copilot reads .github/copilot-instructions.md, and the cross-vendor convention is AGENTS.md. Maintaining the same guidance in five files is how four of them end up stale.

rebase init writes all five — as pointers to a single file you actually edit:

your-project/
├── ai-instructions.md ← the real content
├── CLAUDE.md ← pointer
├── AGENTS.md ← pointer
├── .cursorrules ← pointer
├── .windsurfrules ← pointer
└── .github/
└── copilot-instructions.md ← pointer

Each pointer file names the real one, says where the skills live, and carries the five rules an assistant must not break even if it never opens anything else:

# Corabase AI Rules
Please refer to and follow the instructions defined in [ai-instructions.md](./ai-instructions.md).
The Corabase skills for this assistant live in `.claude/skills/`. If they are not there yet, install them, with the Corabase MCP server: `rebase skills install --agent claude --mcp`.
## Before you write any code
These hold before you have opened ai-instructions.md, and in every session:
- **A table is a file in `backend/schema/`.** Declare it with `defineTable` from `@rebasepro/server/schema` — columns, relations and a required `rls` — export it from `backend/schema/index.ts`, and `pnpm dev` creates it. How it looks in the admin panel is a separate, optional file: `frontend/src/cms/<table>.tsx` with `customizeTable`, which imports the table as a type only. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never SQL as the database owner against an application table: `rebase.sql()` skips row-level security, validation and hooks, so keep it for server work that needs every row and for reading a column marked `.private()`. When the SDK cannot express a query, run it as the caller with `getSql(c)` — the same row-level security as the SDK, read-only unless `{ write: true }`, every value in `params`. A table that already exists gets its file from `pnpm schema:introspect`. With no `backend/schema/` (a headless project) the database is the schema instead: ai-instructions.md says how to serve a table.
- **Data goes through the SDK:** `rebase.dataAsAdmin.<table>` in functions and crons, `getDriver(c)` to act as the caller.
- **A route in `backend/functions/` is public until you guard it** with `requireAuth` or `requireAdmin` from `@rebasepro/server/functions`.
- **Never deploy, never edit generated files** (`backend/src/schema.generated.ts`, `rebase.resources.json`). In `.env`, change only a local setting the task needs (`AUTH_MAGIC_LINK`, `FRONTEND_URL`, `REBASE_FUNCTIONS_TIMEOUT_MS` and the like), one line at a time, and say which; never rewrite, print or rotate its secrets (`DATABASE_URL`, `JWT_SECRET`, `REBASE_SERVICE_KEY`).
- **An admin, back-office or internal tool is built in the Corabase admin, never as a new app.** A dashboard, a review queue, a staff screen or a settings page is a custom view, the home page, a record tab or an action in `frontend/` (ai-instructions.md, "Admin UI", says how). A separate app is only for what the project's own users see. The admin derived from the tables is a draft: before calling an admin done, give every table it shows a `customizeTable` pass (a title, its columns, ids and raw JSON hidden, labels; ai-instructions.md, "Admin UI", has the checklist).
- **When Corabase cannot do what the task needs, tell the human** what is missing instead of working around it.

The others differ only in the agent’s skills directory and its --agent value — --agent cursor, --agent windsurf, --agent codex, --agent copilot — and in the relative path, which is ../ai-instructions.md in .github/copilot-instructions.md and ai-instructions.md in AGENTS.md. The third line is conditional because rebase init --agent may already have installed the skills before the assistant ever reads it.

This happens on every rebase init, for every preset including --headless. There is no flag and no prompt.

rebase init also writes .mcp.json, which points Claude Code, Cursor and any other MCP client at the Corabase MCP server — the project’s own copy, a devDependency pinned with the CLI (npx --no rebase-mcp in an npm project):

{
"mcpServers": {
"rebase": {
"command": "pnpm",
"args": ["exec", "rebase-mcp"],
"env": {
"REBASE_PROJECT_DIR": "."
}
}
}
}

REBASE_PROJECT_DIR is ".", not an absolute path: the client spawns the server at the project root, and an absolute path is the one line of that file that cannot be committed. It is there because ~/.rebase/projects.json is machine-wide — a project that names no directory of its own falls through to whatever the last project on that machine persisted. See the precedence.

The pointer files hold almost nothing. A file that names the real one keeps the conventions in one place, and it has properties a copy does not:

  • One file to edit. Rules cannot drift between assistants, because there is only one set of rules.
  • One diff to review. A change to project conventions is a change to one file, not five identical ones a reviewer must compare.
  • Adding an assistant is one small file. A new tool with a new filename gets a pointer, not a sixth copy of your conventions.

The one exception is the Before you write any code block. An assistant does not reliably follow a link: one that is busy with a task writes the code first, and one started at the root of a repository whose Corabase project sits in a subfolder never loads these files at all. So the five rules whose breaking does the most damage (a table made in SQL instead of in backend/schema, data read and written around the SDK, an unguarded route, a deploy, an edited generated file) are written into every pointer, identically. A check in CI keeps the five copies the same.

The pattern is worth keeping if you fork the scaffold, and worth adopting in repos that are not Corabase projects at all.

The scaffolded file is deliberately short — it points at rebase skills install for depth, then states the rules that assistants get wrong often enough to be worth repeating at the top of every session:

  1. Schema as code. A table is a defineTable in backend/schema/<table>.ts, exported from backend/schema/index.ts — only what the index exports is served — with a required rls. Never hand-edit the generated Drizzle schema or the Postgres tables — see Schema as Code.
  2. Applying a schema change depends on the database. While pnpm dev is running, saving a file in backend/schema/ is the whole step: it regenerates the Drizzle schema and the SDK types, and boot creates the missing tables and columns. pnpm db:push is only for what boot deliberately leaves alone — a renamed column, a narrowed type, a removed column — on the managed development database as on your own PostgreSQL. Production is pnpm db:generate then pnpm db:migrate.
  3. Use the SDK. Go through rebase.dataAsAdmin.<table> for work done as the service identity, or getDriver(c) inside a function when the read should run as the caller. The server client has no plain data accessor. Raw SQL and direct Drizzle calls bypass validation, hooks and RLS.
  4. Guard every custom route. Routes in backend/functions/ are mounted without authentication. Use requireAuth / requireAdmin from @rebasepro/server/functions in the route’s own middleware slot — reading c.get("user") is not a guard, and neither is app.use() after the route.

That last one is the one to keep. It is the difference between a middleware that runs and one that does not, and an assistant that has not been told will reliably write the version that does not — see Custom Functions.

requireAdmin admits the admin role only. When a narrower role or an API key should be able to call a route, the guard to add is requireScope, with a scope the app declares — see Roles and scopes.

After the rules come two sections that apply only in some projects. Backend runtime lists what the managed runtime on Corabase Cloud allows: packages, memory and module-level state, timeouts, outbound ports, configuration and storage for generated files. It links to Managed backend runtime, so an assistant plans a backend feature against real limits instead of guessing. Admin UI holds the @rebasepro/ui rules, and the checklist for the customizeTable pass every table needs before an admin is done: a title, the columns it lists, ids, foreign keys and raw JSON hidden, labels, a summary for JSON columns, and a look at the running admin. The rules apply to views inside the admin panel, not to a public site or static app the project serves.

ai-instructions.md is your file. Nothing regenerates or overwrites it — unlike installed skills, which are replaced on every rebase skills install. Project-specific conventions belong here.

One exception, for a file nobody has touched: a headless project’s ai-instructions.md says the database is the schema and that there is no backend/schema/, and rebase schema introspect writes exactly that directory. When the file is still byte for byte the one the scaffold wrote, introspection replaces it with the backend-only schema-in-code rules; once you have edited it, it is left as it is and the command says which of its rules no longer hold.

What earns its place is what an assistant cannot infer from the code: which tables are legacy, which service owns which table, the naming convention that is not enforced anywhere, the migration that must not be re-run. Keep it short — instructions loaded into every request compete with the actual task for attention, and a long file is one an assistant skims.

And keep the boundary in mind: this file shapes what an assistant writes. It has no bearing on what an agent connected to your database may do — that is decided by the credential it carries, and nothing in Markdown changes it. See the MCP server’s credential model.