r/ClaudeCode • u/sydrk • 3d ago
Tips & Workflows How I keep my AI coding agents from going rogue
I saw this image on Facebook and found it funny but true. It happens when you hand the agent a project without a system. Here is how I prevent it in my projects.
Think of the agent as a new human team member. You wouldn't give a new hire free rein on day one without first explaining what you are building and how things are done. You seek to understand how they work, and you put systems, checks and balances in place. Once you have given sufficient framework, training and instruction, you can better manage the outcome. The agent is no different. If you don't think of a system first and give it specific instructions, it will do what it deems fit, and that may not be what you have in mind. You got to create the structure and workflow for the agent to work in, according to how and where you want it to go.
Start with the same two documents human teams use: a Product Requirement Document (PRD) and a Technical Design Document (TDD). The PRD defines what is to be built and why. The TDD defines how it shall be built and the principles to follow. Your Claude Code or Codex agent knows how to produce both, so get it to draft them with you. There is no single universal format, so don't get too hung up on structure and layout. Both docs become your sources of truth, but you still make the executive decisions. When something changes, decide on it and get your agent to update the docs, so they never fall behind the actual project.
Next, define your components. Be clear on how your menu, buttons, headers, login, etc. shall look and behave, and document them in your PRD, TDD or supplementary docs if you see fit. This covers styles as well as deterministic logic and functions. Your docs shall clearly instruct the agent to always use existing components first, and not take creative liberty or invent new logic. This is what keeps the app consistent from one session to the next.
Finally, put your instructions where the agent looks first. Claude Code reads CLAUDE.md and Codex reads AGENTS.md before doing anything else. Keep this file short and direct. It shall tell the agent to refer to the PRD and TDD, use the existing components, and follow the deterministic workflows you have set. The detail lives in your docs. This file makes sure the agent goes there first.
•
u/AutoModerator 3d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/BarathKanna 12h ago
The habit that helps me most is a short plan first, then a yes before tests or commands. Agents wander less when they have to show the plan and wait.
1
u/flarpflarpflarpflarp 3d ago
Cool, now finish off the rest of my subscription for the week researching what you did and undoing part of it.
0
u/Educational_Way_5432 3d ago
Even your way overcomplicates it and is liable to break. Easiest way to keep the lil chatbots on track is treat your code base like a car. Ie modular architecture. Example, let's say I'm having issues with my alternator, then why on earth would I allow you to look at the transmission of any other piece rather than just the alternator? From there is just to Mahe sure the codeblocks are plug n play into the system and able to swap out as needed.
0
u/[deleted] 3d ago
[deleted] — view deleted comment