Working with Agents
Give coding agents Rogen's rules, and check the files they change
Updated
A coding agent doesn't know that Rogen generates the Rojo project file, so Rojo and the editor can miss the files it adds unless a short block of rules in AGENTS.md tells it to check its changes.
Add the Rules
rogen init adds the block to AGENTS.md and imports it into the CLAUDE.md that Claude Code reads, unless you pass --no-agent-rules. In a project that already has a config, run rogen init --agent-rules. rogen write and rogen serve keep the block up to date with the Rogen you run; delete its marker lines to keep it as your own.
<!-- rogen -->
## Rogen
This repo uses Rogen: each `*.rogen.json` generates the `*.project.json` beside it from folder and file names.
- A file's path on disk is not its path in the game. Run `rogen where <path>` to see where it lands and how to require it.
- The outermost route wins, so `Shared/Server/Save.luau` ships to clients. Keep server-only code under a server route.
- After you add, move or delete files, run `rogen check <paths>` and fix what it prints.
- Edit the `*.rogen.json`, never the `*.project.json`. Packages go in its `tree`, and a change to `routes` goes in every `*.rogen.json` it concerns.
- To sync to Studio, use the repo's serve script, or run `rogen serve --json` in the background.
- For anything else, run `rogen doc <topic>` or `rogen help <command> --json`.
<!-- /rogen -->Check Changed Files Automatically
An agent can forget to run rogen check, so rogen init --agent-hook adds a hook that runs it on the files changed in git when the agent ends its turn, and sends each new warning or error back to the agent. It registers the hook with Claude Code, Codex, Gemini CLI, Cursor or Copilot, whichever the project uses, and rogen write keeps the script up to date; delete its first line to keep it as your own.
Put the script at .agents/hooks/rogen-check.mjs, and add its entry under the agent's event:
| Agent | Hook file | Event | Entry |
|---|---|---|---|
| Claude Code | .claude/settings.json | Stop | "command": "node", "args": ["${CLAUDE_PROJECT_DIR}/.agents/hooks/rogen-check.mjs"] |
| Codex | .codex/hooks.json | Stop | node "$(git rev-parse --show-toplevel)/.agents/hooks/rogen-check.mjs" |
| Gemini CLI | .gemini/settings.json | AfterAgent | node .agents/hooks/rogen-check.mjs |
| Cursor | .cursor/hooks.json | stop | node .agents/hooks/rogen-check.mjs cursor |
| Copilot | .github/hooks/rogen.json | agentStop | node "$(git rev-parse --show-toplevel)/.agents/hooks/rogen-check.mjs", as both bash and powershell |
Each entry works in PowerShell as well as bash, so the hook runs on Windows without Git Bash. Claude Code's runs node without a shell, which needs Claude Code 2.1.139 or later.
// Agent Stop hook: report new Rogen diagnostics about changed files before the agent ends its turn.
// Pass "cursor" as the first argument for Cursor, which replies with followup_message.
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
const git = (...args) => {
const run = spawnSync("git", args, { encoding: "utf8" });
return run.status === 0 ? run.stdout : "";
};
let payload = {};
try {
payload = JSON.parse(fs.readFileSync(0, "utf8"));
} catch {}
const session = String(
payload.session_id ??
payload.sessionId ??
payload.conversation_id ??
"agent",
).replace(/[^\w.-]/g, "_");
// The session's own folder comes first: in a worktree, CLAUDE_PROJECT_DIR can name the main checkout.
try {
process.chdir(payload.cwd || process.env.CLAUDE_PROJECT_DIR || ".");
} catch {
process.exit(0);
}
const start = process.cwd();
const top = git("rev-parse", "--show-toplevel").trim();
if (top) process.chdir(top);
const changed = [
...git(
"diff",
"-z",
"--name-only",
"--relative",
"--diff-filter=d",
"HEAD",
).split("\0"),
...git("ls-files", "-z", "--others", "--exclude-standard").split("\0"),
].filter(Boolean);
if (!changed.length) process.exit(0);
const seenFile = path.resolve(
git("rev-parse", "--git-dir").trim(),
`rogen-hook-${session}`,
);
const seen = fs.existsSync(seenFile)
? fs.readFileSync(seenFile, "utf8").split("\n")
: [];
const windows = process.platform === "win32";
const names = windows ? ["rogen.cmd", "rogen.exe"] : ["rogen"];
const locate = (dirs) =>
dirs
.flatMap((dir) => names.map((name) => path.join(dir, name)))
.find((file) => fs.existsSync(file));
const folders = [start];
for (let dir = start; dir !== process.cwd() && path.dirname(dir) !== dir; )
folders.push((dir = path.dirname(dir)));
// A new git worktree has no node_modules, so look in the main checkout's too.
const main = top
? path.dirname(path.resolve(git("rev-parse", "--git-common-dir").trim()))
: process.cwd();
if (main !== process.cwd())
folders.push(
...folders.map((dir) => path.join(main, path.relative(top, dir))),
);
const rogen = locate([
...folders.map((dir) => path.join(dir, "node_modules/.bin")),
...(process.env.PATH ?? "").split(path.delimiter).filter(Boolean),
]);
if (!rogen) {
const NONE = "# found no rogen";
if (!seen.includes(NONE)) {
console.error(
"Rogen's hook found no rogen; install it in the project or globally",
);
fs.appendFileSync(seenFile, `${NONE}\n`);
}
process.exit(0);
}
const run = (command, args) =>
windows && command.endsWith(".cmd")
? spawnSync([command, ...args].map((part) => `"${part}"`).join(" "), {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
shell: true,
})
: spawnSync(command, args, {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
});
const check = run(rogen, ["check", ...changed]);
const lines = (check.stdout ?? "").split(/\r?\n/).filter(Boolean);
const report = lines.filter((line) => !seen.includes(line));
// Keep only what the check still prints, so a problem fixed and made again is new again.
fs.writeFileSync(seenFile, lines.map((line) => `${line}\n`).join(""));
if (!report.length) process.exit(0);
const message = `Rogen reports these about files you changed. Fix each, or tell the user why it stays:\n${report.join("\n")}`;
console.log(
JSON.stringify(
process.argv[2] === "cursor"
? { followup_message: message }
: { decision: "block", reason: message },
),
);Install the Skill
The rules live in AGENTS.md because an agent loads a skill only when a task looks like it needs one, and adding a Luau file doesn't. The rogen skill is for setup instead: it sets a repo up through rogen init and can reorganise a Rojo layout into feature folders.
npx skills add LDGerrits/rogen