Control AI Code Changes with Goose and GitHub CLI
Job to be done: Prevent AI agents from making unwanted code changes by enforcing commit discipline.
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Entrepreneur
As a solo tech founder, use an AI agent to quickly add new features to your startup's MVP, knowing you can instantly revert any AI-introduced bugs or unwanted code to keep your product stable.
- Student
As a computer science student, use an AI agent to build a new feature for your final year project, ensuring every AI-generated code change is a separate, reviewable commit you can easily undo if it breaks your app.
- 9-5 employee
As a software developer, use an AI agent to refactor a complex module at work, ensuring each AI-suggested change is committed separately for easy review by your team lead and quick rollback if issues arise.
What you’ll get
A simple discipline that stops an AI coding agent from quietly making a mess of your project. By making the agent save a separate, clearly labelled “commit” (a saved snapshot in Git) after every change, your version history becomes a reliable undo button: if the AI does something you dislike, you roll back to the last good snapshot in seconds. This is intermediate: you use Git and a terminal, but the setup is short.
Tools you need
- Goose (free): an open-source AI agent (by Block) that can read and edit your codebase. You give it the commit rule below.
- GitHub CLI (free): the
ghcommand-line tool for working with GitHub and Git from your terminal.
Steps
-
Set up version control: install the GitHub CLI (
gh) and make sure your project is a Git repository. Goose works smoothly with Git. (The GitHub MCP Server is a good alternative if you prefer it.) -
Always start on a new branch: before letting the AI touch anything, create a fresh “feature branch” (a separate line of work) so experiments stay isolated. Never let the agent commit straight to your
mainbranch. -
Write the rule into a context file: create a file named
.goosehints(orAGENTS.md) in your project. This file is the standing instruction the agent reads. The key line:Every time you make a change, make a commit with a clear message.This makes the agent checkpoint its own work automatically, turning each change into a reviewable snapshot.
-
Prompt the agent: now you can let Goose build, fix, or refactor with confidence:
Build the user authentication module based on the provided requirements.As it works, it should commit each change with a clear message, exactly as the rule instructs.
-
Review, and roll back if needed: check the history with
git logto see each AI change as its own commit. To undo one specific bad change safely (this makes a new commit that reverses it):git revert <commit-hash>To throw away everything and return to a known-good snapshot (this discards later work, so be sure):
git reset --hard <commit-hash>Replace
<commit-hash>with the ID shown ingit log.
Original source
Based on a DEV Community post by blackgirlbytes describing how to keep AI agents in check by combining them with ordinary good practice: early, frequent, clearly-labelled commits.
Notes & variations
- Free-tier viability: Goose is free and open-source and the GitHub CLI is free, so this costs nothing.
- Common pitfall: letting the agent commit directly to
main. Always work on a separate feature branch so a bad change never touches your stable code. - Tip for better results: keep the instruction in
.goosehints(orAGENTS.md) short and unambiguous. Clear rules produce clear, frequent commits, which is what makes the undo button reliable.