r/OpenAIDev • • 24d ago

Prompt rules didn't stop our coding agent from doing things we'd never allow by hand. Exit codes did.

You've probably written the rules into the prompt or the instructions file: never force-push, never touch .github/, don't install anything outside the lockfile, ask before running a migration. And then one long session later the agent does it anyway. Not out of malice: it's deep in a task, the rule is somewhere far back in the context, and the shortcut is right there.

A prompt is advice. What we wanted was something that can't be talked out of, so in CCode, the coding agent we build, hooks are scripts that run at fixed points, and their exit code decides:

  • Before a tool call, like a shell command (PreToolUse): exit 2 and the call is blocked, with your message shown to the agent.

  • After a tool call (PostToolUse): non-zero output goes back to the model, so you can warn it ("that file is generated, don't edit it by hand").

  • Before your message is sent (UserPromptSubmit): exit 2 stops the message, useful for blocking secrets being pasted in.

  • When it thinks it's done (Stop): exit 2 sends it back to work, up to 3 times, so "done" has to survive your script first.

Since they're plain scripts, the rules are things like: grep the command for git push --force, refuse if it edits .github/workflows, run the type checker when it says a file is finished. They live in your own settings, so they follow you into every project you open, and the agent can't quietly skip them.

What commands would you never let an agent run without a human in the loop?

1 Upvotes

0 comments sorted by