Leanpub Header

Skip to main content

The Agents.md Cookbook

Rules Files for AI Coding Agents

The Agents.md Cookbook
This book is 100% completeLast updated on 2026-10-17

Your AI coding agent starts every session knowing nothing about your project, so it guesses - and the guess is sometimes expensive. The AGENTS.md Cookbook shows you how to write short, specific rules files, how to test them with a simple before-and-after method, and includes twelve ready-to-adapt recipes for real project types, labeled honestly about what has and has not been tested.

Minimum price

$7.99

$9.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
About

About

About the Book

You use an AI coding agent and it works, mostly - until a session reorganizes your folders, installs a package you did not ask for, or calls the task done while the build is broken. The cause is rarely the model being difficult. It is that the agent starts every session knowing nothing about how you want the work done. The practical fix is a rules file: a plain text file, usually named AGENTS.md, that sits in your project and states your commands, structure, boundaries, and definition of done.

This book teaches you to write that file well. Part I builds the foundation: what a rules file is and is not, the anatomy of a good one, how to word rules an agent can actually follow, and a simple before-and-after test method with a log template. Part II is a library of twelve recipes grouped by real project types: web apps, APIs and backend services, Flutter-style mobile apps, Python scripts and data projects, education and school tools, finance apps, database and migration safety, security guardrails, testing and review, git workflow, documentation and handover, and larger projects where rules are split across folders. Part III covers maintenance: a review rhythm, pruning, rule debt, versioning, and a diagnosis checklist for the sessions when the agent ignores your rules anyway.

Every recipe carries a status label, and the book is blunt about them: "Author-tested" only where a real test is documented, "Draft, untested. Test before relying on it." everywhere else. Untested labels are stated plainly rather than dressed up as experience, and each recipe includes a concrete test you can run in under an hour on your own project.

Two caveats are stated up front and repeated where they matter: a rules file reduces the risk of drift; it does not guarantee behavior, so confirmation steps and diff reviews stay in your workflow for anything destructive. The book is not legal or financial advice. Tool behavior changes between versions, so the book stays tool-neutral and points you to official documentation wherever a tool-specific question arises.

Author

About the Author

Kristian Reformis

Kristian Reformis is a dedicated IT educator and tech enthusiast with a mission to bridge the gap between complex technology and modern pedagogy. With years of experience in the classroom, he has seen firsthand the challenges teachers face in an increasingly digital world.

Known as "The Reformist Teacher," Kristian specializes in making advanced IT concepts—from coding to Artificial Intelligence—accessible and actionable for educators of all backgrounds. He believes that technology should not be a burden to teachers, but a powerful catalyst that allows them to focus on what truly matters: inspiring the next generation.

When he isn’t exploring the latest AI tools or developing digital solutions for schools, Kristian enjoys sharing his insights on educational reform and the future of work. The AI-Driven Educator is his latest contribution to empowering teachers worldwide to reclaim their time and transform their classrooms.

Contents

Table of Contents

Preface

  1. Who this is for
  2. What you will learn
  3. The honesty note
  4. The labels
  5. The running examples
  6. How to use this book
  7. What you need before starting
  8. Owning the file
  9. Series note
  10. One last thing

What a Rules File Is, and What It Is Not

  1. The problem it solves
  2. A small example
  3. How an agent uses it
  4. The three layers of instruction
  5. What a rules file is not
  6. What it can do
  7. What it cannot do
  8. Size and focus
  9. When you do not need one
  10. The name of the file
  11. One session, in slow motion
  12. Checklist

Anatomy of a Good Rules File

  1. Project overview
  2. Commands
  3. Structure
  4. Conventions
  5. Boundaries
  6. Testing
  7. Security
  8. Definition of done
  9. A complete skeleton with all eight blocks
  10. Why the order matters, in general terms
  11. Reading an existing file against this anatomy
  12. A summary of the eight blocks
  13. When the anatomy fights your project
  14. Checklist

Writing Rules an Agent Can Follow

  1. Specific beats vague
  2. Positive and negative rules
  3. Show, don’t tell
  4. Priorities, and how to make conflicts resolve safely
  5. Avoiding contradictions
  6. Keep it short
  7. Tone: imperative, present tense
  8. Writing for two readers at once
  9. An exercise: your first three rules
  10. Rewrite stress test
  11. The three-fate rule
  12. Checklist

Testing Your Rules

  1. The before-and-after method
  2. What to measure
  3. The log
  4. Reading results: the four verdicts
  5. When a rule should be removed
  6. How often to test
  7. The test, from start to finish
  8. When A and B are both bad
  9. What testing cannot promise
  10. What to record when you test
  11. Checklist

Web App Starter

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. How to test it
  6. Common mistakes and variations
  7. Growing the file after week one
  8. Checklist

API and Backend Services

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. How to test it
  6. Common mistakes and variations
  7. Reading an agent endpoint diff in sixty seconds
  8. Checklist

Mobile App Projects (Flutter Style)

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. The three decisions this file makes for you
  6. How to test it
  7. Common mistakes and variations
  8. Checklist

Python Scripts and Data Projects

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. How to test it
  6. Common mistakes and variations
  7. A worked example: the expenses summary
  8. Checklist

Education and School Tools

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. How to test it
  6. Common mistakes and variations
  7. Checklist

Finance and Data Apps

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. How to test it
  6. Common mistakes and variations
  7. Checklist

Database and Migration Safety

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. How to test it
  6. Common mistakes and variations
  7. Checklist

Security Guardrails

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. How to test it
  6. Common mistakes and variations
  7. Checklist

Testing and Review Rules

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. Why this recipe is short on purpose
  6. How to test it
  7. Common mistakes and variations
  8. Checklist

Git and Workflow Rules

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. How to test it
  6. Reading the commits, not just the diff
  7. Common mistakes and variations
  8. Checklist

Documentation and Handover Rules

  1. Goal and when to use it
  2. Ingredients
  3. The rules file
  4. Why each rule is there
  5. How to test it
  6. Common mistakes and variations
  7. A release note that works, in eight lines
  8. Checklist

Larger Projects and Teams

  1. Goal and when to use it
  2. Ingredients
  3. The rules file - root (shared/global only)
  4. The rules file - one package (local rules only)
  5. Why each rule is there
  6. Team rules, in brief
  7. How to test it
  8. Common mistakes and variations
  9. Checklist

Maintaining Your Rules File

  1. Why maintenance matters
  2. The two triggers for a review
  3. The review routine, twenty minutes
  4. The pruning list
  5. Rule debt
  6. Versioning the file cheaply
  7. Choosing to rewrite from scratch
  8. After tool and model changes
  9. What to expect when the file is healthy
  10. Expanding from rules: the file as team documentation
  11. The signals that a deep clean is due
  12. Checklist

When the Agent Ignores Your Rules

  1. What ignoring usually looks like
  2. The diagnosis checklist, in order
  3. Shorter, sharper, higher
  4. Repeat critical rules in the chat
  5. The rewrite loop: every miss becomes data
  6. When to start a fresh session
  7. Accept the ceiling, and gate the stakes
  8. A closing calibration
  9. What not to do
  10. Sixty-second triage
  11. When the whole file stops working
  12. Checklist

Appendix A: Starter Template

  1. How to fill it in
  2. What to do next

Appendix B: Rules Library by Topic

  1. Commands
  2. Structure
  3. Conventions
  4. Boundaries
  5. Testing
  6. Git
  7. Security (defensive only)
  8. Privacy and data
  9. Money and numbers
  10. Documentation
  11. Agent behavior
  12. How to use this appendix

Appendix C: Checklists

  1. New project checklist
  2. Before sharing a rules file
  3. Monthly review checklist

Appendix D: Tool Compatibility Notes

Glossary

About the Author

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub