Coding agent snapshot
Laptop recipe: install the CLI, bind a token to your local agent, and have a coding agent snapshot the database before Hibernate auto-DDL or a migration changes it.
Role: Developer laptop + coding agent · CLI: quemsi snapshot (--wait is the default)
This is not CI. Pipelines use Snapshot before deploy. Clicks in the console: Snapshot before a schema change. Any coding agent can run the same CLI. Cursor and Claude Code are the two examples below.
Before you start
- A local Quemsi agent is ONLINE and this database is a data item on Data.
- You know the data name and the local agent name.
- If that data has more than one forward (backup) flow on the agent, you must pass
--flow(the flow name). One flow: omit it.
Steps
Install the CLI
Full install steps (Linux, Windows, JAR, token, env): Install and configure the quemsi CLI.
Short version — download from /cli-releases/latest/ and put the binary on PATH. On Windows the file is quemsi.exe; the command is still quemsi.
Linux:
curl -fsSL -o quemsi https://quemsi.com/cli-releases/latest/quemsi && chmod +x quemsi && sudo mv quemsi /usr/local/bin/quemsi
Windows: download quemsi.exe and add it to PATH.
JAR (Java 21), either OS:
curl -fsSL -o quemsi.jar https://quemsi.com/cli-releases/latest/quemsi.jar
java -jar quemsi.jar snapshot --data … --agent …
Create a laptop token
Open Company Setup → API tokens. Name it something like cursor-local. Bind it to your local agent. Scopes: snapshot and read only — not restore. See Create API tokens.
Store the secret for your whole login session, not only one terminal. Create the directory, then write ~/.config/environment.d/quemsi.conf (no export, and do not commit this file):
mkdir -p ~/.config/environment.d
QUEMSI_TOKEN=qsk_...
QUEMSI_AGENT=your-local-agent-name
QUEMSI_AGENT is the agent name on your machine. The rule reads it from the environment so the rule file has no agent placeholder to copy. QUEMSI_URL is optional and defaults to https://quemsi.com. Log out and back in so every new terminal and app sees the file, then restart Cursor or start a new Claude Code session.
Check the snapshot command
--wait is the default. Do not start the app, tests, or a migrate command until this exits 0. While it waits, the CLI prints a console link (…/app/flows/execution/{id}) so you can open progress and logs. Sign in as a person to view that page.
A finished command names this change. Restore keeps the latest snapshot for each tag combination, so a unique change tag is what makes this snapshot its own card. Reusing only purpose=pre-schema hides the previous one.
quemsi snapshot --data job-listings --agent "$QUEMSI_AGENT" \
--tag purpose=pre-schema --tag change=job-listing-country \
--descript "before V2 add job_listing.country"
Add a Cursor rule in the app repo
This file is what makes Cursor snapshot before it changes schema. Save it in the application you are coding, not in Quemsi. Path: .cursor/rules/quemsi-snapshot.mdc. Put your real data name on the config line once. Leave the agent name to QUEMSI_AGENT. Widen the globs if your entities do not match those paths.
The rule tells Cursor to build the command for the task in front of it. It must not paste a sample from this page.
---
description: Snapshot the local database before schema changes
globs: "**/*Entity.java,**/entity/**/*.java,**/entities/**/*.java,**/db/migration/**,**/db/changelog/**"
alwaysApply: false
---
Before you change a matching file, or before you start the app when Hibernate will apply schema changes, run quemsi snapshot and wait until it exits 0.
Quemsi data name: REPLACE_WITH_DATA_NAME
Build the command for this change. Do not copy a sample and do not leave placeholders.
- --data is the Quemsi data name above. If it still says REPLACE_WITH_DATA_NAME, stop and ask for the real name.
- --agent is the QUEMSI_AGENT environment variable. If it is unset, stop. Do not invent an agent name.
- Always pass --tag purpose=pre-schema.
- Add --tag change=<slug>. Slug is kebab-case from this task (table and column, or migration id), such as job-listing-country.
- Pass --descript as one sentence that names the migration file or entity and the column, such as "before V2 add job_listing.country".
- If this data has more than one forward flow, pass --flow with the flow name.
- Do not restore unless the person asks.
- If quemsi is missing or QUEMSI_TOKEN is unset, stop.
- Do not commit the token.
Reload Cursor after saving the file. Ask Cursor to add the column or migration; it should propose a command like the example in step 3, with a change tag and description taken from that edit. In Ask mode it can only print the command. In Agent mode it can run it. Typing the change yourself does not trigger the rule.
Or add a Claude Code rule in the app repo
Same instruction, different file. Save it in the application you are coding. Path: .claude/rules/quemsi-snapshot.md. paths is Claude Code’s equivalent of Cursor’s globs: the rule loads when Claude opens a matching file. Put your real data name on the config line once. Reuse the same QUEMSI_TOKEN and QUEMSI_AGENT from step 2.
---
paths:
- "**/*Entity.java"
- "**/entity/**/*.java"
- "**/entities/**/*.java"
- "**/db/migration/**"
- "**/db/changelog/**"
---
Before you change a matching file, or before you start the app when Hibernate will apply schema changes, run quemsi snapshot and wait until it exits 0.
Quemsi data name: REPLACE_WITH_DATA_NAME
Build the command for this change. Do not copy a sample and do not leave placeholders.
- --data is the Quemsi data name above. If it still says REPLACE_WITH_DATA_NAME, stop and ask for the real name.
- --agent is the QUEMSI_AGENT environment variable. If it is unset, stop. Do not invent an agent name.
- Always pass --tag purpose=pre-schema.
- Add --tag change=<slug>. Slug is kebab-case from this task (table and column, or migration id), such as job-listing-country.
- Pass --descript as one sentence that names the migration file or entity and the column, such as "before V2 add job_listing.country".
- If this data has more than one forward flow, pass --flow with the flow name.
- Do not restore unless the person asks.
- If quemsi is missing or QUEMSI_TOKEN is unset, stop.
- Do not commit the token.
Start a new Claude Code session after saving the file. Run /context and check memory files to confirm the rule loaded. Ask Claude to add the column or migration; it should build the same kind of command as step 3. Editing the file yourself does not trigger the rule.
When to snapshot
Quemsi does not run your migration. Snapshot at the moment before the database schema changes. That moment depends on how you apply DDL.
Hibernate ddl-auto=update
There is no migrate CLI. Hibernate applies schema on the next app start (spring-boot:run, bootRun, tests that boot JPA, or Run/Debug in the IDE).
Snapshot after the entity or mapping changes, before that boot. The rule above includes entity files for this reason.
Flyway, Liquibase, or SQL
Snapshot before the migrate command. Gate that command so it does not run if quemsi snapshot fails.
What you should see
Open the app and ask the coding agent to add a column or a migration. With the Cursor rule or the Claude Code rule in that repo, it should run quemsi snapshot (or propose that command) before it edits. On stderr you will see a watch link:
you can watch progress at https://quemsi.com/app/flows/execution/123
waiting for snapshot execution 123
You only need the rule for the tool you use. Both files can live in the repo if the team uses both tools. Do not auto-restore.
Restore is a person
If the schema change goes wrong, overwrite back from the UI: Restore a tagged snapshot, filter to work=baseline. Or run an explicit quemsi restore yourself. Do not auto-restore from the coding agent. Restore overwrites the target database.
Gaps
- The rule applies when the coding agent is the one changing the file. If you type the column yourself, run
quemsi snapshot(or ask the agent to) before the next app start. - If the rule never appears, check that the file path matches Cursor
globsor Claude Codepaths. Reload Cursor, or start a new Claude Code session and run/context.quemsimust be onPATH, andQUEMSI_TOKENandQUEMSI_AGENTmust be in the login environment from step 2. - If the token is missing or the agent is offline, the snapshot command fails. Do not start the app until it exits 0.
ambiguous-flow— pass--flowwith the forward flow name.no-forward-flow— create a backup flow in the UI first.
A project hook can run the same command without asking. Most teams do not need that. The rule is the setup this page recommends.
Not this page
- Clicks on Take Snapshot — Snapshot before a schema change.
- CI snapshot before a release — Snapshot before deploy.
- CI restore before tests — Restore before tests.
Rule in the app repo
Install quemsi, bind a laptop token, then save a Cursor rule or a Claude Code rule so the agent snapshots before it changes schema.