The afterFileEdit Cursor hook and Prisma
{
"version": 1,
"hooks": {
"afterFileEdit": [
{
"command": "bun run hooks/after-file-edit-prisma.ts"
}
]
}
}Hooks are here in Cursor so let’s go over how to implement and test our own afterFileEdit hook that runs after a Prisma schema file is edited in our project directory.
Hooks are mechanisms for deterministically running custom logic at key events in our agentic loop. Cursor exposes a few of these events that we can hook into, including one that fires whenever the agent edits a file.
Even with frontier models as of Nov 2025, there’s no guarantee that any explicit guidelines in an AGENTS.md or .cursor/rules will be followed. Hooks can help close this gap when possible by programmatically enforcing those rules.
An important note: afterFileEdit will not block the execution of the Agent and is more of a fire-and-forget execution; we can’t reach for this to run something like tsc --noEmit and expect the Agent to halt upon any TypeScript compile errors.
Updating the Prisma client after an Agent edits prisma.schema
Let’s set up something that will regenerate the Prisma client after an Agent has edited a Prisma database schema file.
For context, Prisma requires that it’s client is regenerated any time a change is made to the database schema file. Without this, any updated types referencing the schema might result in compiler errors, so it’s a hurdle worth resolving as it will tighten up the Agentic loop.
1. First, let’s setup a hook in your local ~/.cursor dir:
├── hooks.json
└── hooks/
└── after-file-edit-prisma.ts{
"version": 1,
"hooks": {
"afterFileEdit": [
{
"command": "bun run hooks/after-file-edit-prisma.ts"
}
]
}
}2. Next, let’s setup and use Bun as a node replacement that we can use to run our hook:
curl -fsSL https://bun.com/install | bash3. Install the cursor-hooks package
cd ~/.cursor
bun init
bun install cursor-hooks4. Edit hooks/after-file-edit-prisma.ts ensuring that we run 'prisma generate' whenever the prisma.schema file is edited by the Agent.
import type { AfterFileEditPayload } from "cursor-hooks";
import { $, stdin } from "bun";
async function run(): Promise<void> {
const input: AfterFileEditPayload = await stdin.json();
const filePath = input.file_path;
const [workspaceRoot] = input.workspace_roots;
if (!workspaceRoot) return;
/*
Return if the file is not schema.prisma
*/
if (!(filePath.endsWith("schema.prisma"))) {
console.error("Not a schema.prisma file");
return;
}
/*
Return if there's no pnpx prisma
*/
const prismaAvailable = (await $`cd ${workspaceRoot} && command -v pnpx prisma`.quiet()).exitCode === 0;
if (!prismaAvailable) {
console.error("Prisma not available");
return;
}
/*
Generate the prisma schema
*/
const output = await $`cd ${workspaceRoot} && pnpx prisma generate`.text();
console.log(JSON.stringify(output));
}
await run();5. Confirm that this new hook is listed in the "Cursor Settings -> Hooks" section of cursor:
6. Finally, we can simulate editing the prisma.schema file and confirm that the Prisma client is re-generated automatically.
First, send a test payload to our hook simulating an edit to the prisma.schema file. Add in a fake conversation_id and generation_id, but add the actual workspace_root and file_path to your project that’s configured with Prisma.
bun /Users/gereth/.cursor/hooks/after-file-edit-prisma.ts <<'JSON'
{
"conversation_id": "fb4398d5-0346-4feb-92a0-1b88f0689de7",
"generation_id": "bc07ef02-2830-419a-b49c-e61bcc318736",
"workspace_roots": ["/full/path/to/project"],
"file_path": "/full/path/to/project/prisma/schema.prisma",
"edits": ["A fake edit to trigger the hook"]
}
JSONIf successful, you should see output similar to the following indicating that the Prisma client was re-generated:
"Prisma schema loaded from prisma/schema.prisma\n\n✔ Generated Prisma Client (v6.19.0)....Now, any time an Agent edits the prisma.schema file, the Prisma client will be automatically re-generated ensuring that your types are always up to date! Let’s test this out by having an Agent modify the schema and see the hook in action.
7. Test this out in the wild with the Agent
In Cursor within your target project, instruct the Agent to add a one-word comment to the prisma.schema file. After the Agent has stopped, validate that the file was indeed edited and check the hooks output in Cursor settings to confirm that the hook ran successfully.
Check the "Cursor Settings -> Hooks" execution section and expand the latest "afterFileEdit" entry to see the output of the hook: