Prompting Your Prompt's Prompt
The second derivative of code agents: a meta prompt to make them document themselves.
Aug 22, 2025
People keep asking if a code agent can draft your AGENTS.md
. Yes—but doing it right feels like taking the second derivative of prompting. Agents already turn prompts into code; an AGENTS.md
becomes the next prompt they read. This post is the prompt you feed the agent so it can write that AGENTS.md
—a prompt for your prompt's prompt. After sharing how I document agents and musing on Turborepo as the collaboration app, here's the exact setup.
1Your task is to create an AGENTS.md to help improve our future tasks. Perform a rigorous investigation and put your learnings into a new AGENTS.md (as we don't have one yet).
2
3I'd like the agents.md file to be 250 lines of code, maximum. It should be dense and condense the core philosophies needed to create a successful PR in this repo.
4
5In order to do that, I first want you to make AGENTS.md files for each package and app. Each of those should also be max 250 LOC. And they should contain the core information needed to make and merge a successful PR in that app/package. Then, summarize the key stuff for the main repo AGENTS.md
6
7In order to do all of this successfully you'll likely need to open nearly (>90%) every piece of code in the repo.
8
9The primary consumer of the AGENTS.md files will be _YOU_ thus the contents should be a cheatsheet for _YOU_. As, because you're an LLM code agent, you'll lose all context between each new task. These agent files allow you to save time, energy, and increase your rate of success by saving nuggets of non-obvious knowledge about the codebase.
10
11Please don't take this lightly and do a good job step by step. Remember to think hard at every chance. This task will make all future tasks succeed or fail, so ensure to be smart about this.
Hand this to an LLM and it will draft per-package docs, distill them, and leave a tight AGENTS.md
trail.
- Why 250 lines? Most agents comfortably read ~250 lines at once, keeping each file digestible in a single command.
- Why sub‑AGENTS first? Per-package files capture local quirks; the root
AGENTS.md
merely summarizes their highlights.
- Why scan ~90% of the repo? A near-complete crawl surfaces surprises and prevents blind spots.
Once the agent spits out drafts, I send a second message to tighten the screws:
1Good, re-read what you wrote so far. You'll see a short, but good overview of how the Turborepo is structured.
2
3But you'll also notice a problem, in that, for example, when working within the Next.js app we might accidentally create UI components there INSTEAD of the UI package as the agent might not have seen the AGENTS.md file there yet. We must provide basic instructions and awareness of where things should go (decision wise) in the various agents.md files.
4
5Further, I want the main agents.md to be aware of tooling setup in case it needs it.
6
7Last: I want specifics about how to code things. i.e., not only is it strict TypeScript, or that there should be 'no any', but I don't want to cast types if we can avoid it, as it means something is bad and wrong. We should either parse it via a validator or infer it properly. Ideally, infer.
8
9Also there should be a single source of truth and flow of types, and it's super important to me that if we change a type everything that could break should break. So redefining and redeclaring them is bad.
10
11Typically I see this as follows: Drizzle ORM Zod schemas --> imported to validators and then fixed up a bit (extending the Zod to properly capture a JSONB field, for example), and then everything else can pull from validators. The reason this is important is if the DB changes I want tRPC, UI, and apps to break immediately at typecheck time instead of later during a Zod parse.
Use this nudge to connect the dots across folders and enforce a shared type system.
- Cross-package awareness. Docs should remind agents to pull UI pieces from shared libraries instead of reinventing them.
- Tooling recall. The root
AGENTS.md
needs lint, typecheck, and build hints so new sessions can bootstrap quickly.
- Validator-first types. Drizzle → Zod → validators ensures a single source of truth that breaks loudly when the DB shifts.
- Prompt the prompter. Encode a reusable prompt so future agents start with context.
- Outsource the archaeology. Let the agent crawl >90% of your files so future bots aren’t blind.
- Avoid silos. Explicit package instructions keep UI components in
/ui
instead of /app
's random corner.
- Type safety first. AGENTS docs enforce a single flow of types—if the DB shifts, TypeScript screams everywhere.
This second-derivative prompt turns AGENTS.md
into living guardrails. Pair it with best-of‑N sampling from The Disposable Intelligence Era and you’ve got agents documenting the repo while you sip coffee. Yes, an agent can write your docs—this is how. Try it, tweak it, and share your own snippets.