When to use it: Use when setting up or building in Cursor or via Koen's build agent to enforce hard repo guardrails (blocking .env reads, migration edits, force-pushes, and pushes to main) and deterministic lint/test checks before review.
Coding Agent Guardrails (Cursor & Repo Build Agents)
Apply deterministic guardrails to repositories built in Cursor or by automated dev-process agents so secrets, schema migrations, and protected branches are blocked mechanically—and repeat bugs are caught by tools instead of paying an AI to rediscover them.
1. Cursor repo guardrails (.cursorignore + .cursor/rules/guardrails.mdc)
Add a .cursorignore at the repo root so secrets stay out of model context:
.env
.env.*
**/.env
**/.env.*
*.pem
*.key
Add .cursor/rules/guardrails.mdc (alwaysApply: true) with hard engineering guardrails:
- Never read or print
.env*files, keys, or tokens into context, PRs, or logs. - Never edit
migrations/**without explicit owner approval. - Never run
git push --force,git push -f,git reset --hard, or push directly tomain/master. - Run lint, typecheck, and automated tests before asking a human or QA agent to review.
- When a bug class happens twice, add a deterministic lint rule, schema check, or test so it fails automatically from then on.
2. Automated build-agent permissions (.claude/settings.json, when used by a build worker)
For repos built by a Claude Code dev-process worker, merge explicit permissions.allow and permissions.deny rules into .claude/settings.json:
{
"permissions": {
"allow": [
"Bash(npm test *)",
"Bash(npm run lint *)",
"Bash(npm run typecheck *)",
"Bash(git status)",
"Bash(git diff *)",
"Bash(git log *)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(**/.env)",
"Read(**/.env.*)",
"Edit(./migrations/**)",
"Edit(**/migrations/**)",
"Bash(git push --force *)",
"Bash(git push -f *)",
"Bash(git push origin main *)",
"Bash(git push origin master *)",
"Bash(git reset --hard *)"
]
}
}
Adjust test/lint commands to match the repo's package manager (pnpm, yarn, pytest, cargo test, etc.).
3. Deterministic checks before LLM or QA review
Before handing off a PR, build, or preview:
- Run the repo's formatter, linter, typechecker, and test suite first.
- Trim failing logs to the exact failing test or error line rather than dumping thousands of lines into context.
- Convert every repeat bug into a permanent lint rule, CI check, or unit test so it stops costing tokens forever.