Guide
Use a single Margarita template to generate perfectly tailored agent instructions for Claude, Gemini, etc.
Cut the parts that cause a model to underperform, without maintaining multiple files or copying and pasting updates across them.
Each model has its own tool names, quirks, and preferred patterns. Maintaining separate files means they inevitably drift — and your agents start making subtly different mistakes.
Shared rules live in two files. One gets updated, the other doesn't. Your models quietly receive contradictory instructions.
Every PR touching agent instructions means checking two files for consistency. Easy to miss, painful to catch in production.
Add a third model and you're maintaining three files. The problem compounds with every new assistant you adopt.
agents.mg file. Shared project rules go in the main body. Use
Margarita's if blocks to add model-specific sections that are only rendered
when that model is targeted.
# agents.mg
# Shared rules — always rendered for every model
<< # Margarita – Agent Guide >>
<<
## Project Overview
This repo contains three packages: Margarita (templating),
and Margarita (agentic workflows).
All packages live under `packages/`.
>>
<<
## Repository Layout
```
packages/
margarita/ core templating engine (Python)
margarita/ agentic .mgx runner
docs/ shared documentation source
```
>>
<<
## Running Tests
```bash
pip install -e packages/margarita[dev]
pytest packages/
```
>>
# Model-specific sections — only one block is ever rendered
if model == "claude":
<<
## Claude Code – Tools & Workflow
### File Operations
Use the purpose-built tools for every file operation — never shell
out for things the tools handle directly:
- **Read** before touching any file. No exceptions.
- **Edit** for targeted changes; **Write** only for new files.
- **Glob** / **Grep** to locate files — never `find` via Bash.
- **Bash** for test runs, git commands, and build steps only.
### Task Management
For any task with more than two steps, start with **TodoWrite**.
Mark each item `in_progress` before starting and `completed` when
done. Keep the list current throughout the session.
### Guardrails
- Make the smallest change that solves the problem. Do not clean up
surrounding code that wasn't part of the request.
- Never commit unless explicitly asked. Never use `--no-verify`.
- If a pre-commit hook fails, fix the root cause — don't bypass it.
- After touching `margarita/`, run `pytest packages/margarita` and
confirm the suite passes before calling the task done.
>>
if model == "gemini":
<<
## Gemini – Grounding & Response Style
### Search Before You Assume
Before using any third-party library, API endpoint, or version
number, call `@google_search` to verify it is current. Do not
rely on training-data knowledge for fast-moving dependencies.
If search returns conflicting results, surface them — don't pick one.
### Response Format
- Lead with code, not explanation. Put prose after the block.
- Every code snippet must have an explicit language tag on the fence.
- If the task is ambiguous, ask one focused clarifying question
rather than making assumptions and proceeding.
- Keep answers short. If detail is needed, offer to expand.
### Citations
When referencing a doc page, RFC, or external resource, include
the URL inline so the team can verify. Prefer official documentation
over blog posts or Stack Overflow. Flag anything that may be stale.
>>
# Shared code style — always rendered for every model
<<
## Code Style
- Python 3.11+, type hints on all public functions.
- Black formatter, line length 88.
- Every public function needs a docstring.
>>
model variable via the --context flag and pipe the output straight into
the right file. Drop this into a Makefile or CI step and your agent
instructions stay fresh on every commit.
# Render instructions for Claude Code
margarita render agents.mg \
--context '{"model": "claude"}' \
> CLAUDE.md
# Render instructions for Gemini
margarita render agents.mg \
--context '{"model": "gemini"}' \
> AGENTS.md
Rendered with model = "claude". The Gemini section is omitted entirely — Claude only sees what's relevant to it.
# Margarita – Agent Guide
## Project Overview
This repo contains three packages: Margarita (templating),
and Margarita (agentic workflows).
All packages live under `packages/`.
## Repository Layout
```
packages/
margarita/ core templating engine (Python)
margarita/ agentic .mgx runner
docs/ shared documentation source
```
## Running Tests
```bash
pip install -e packages/margarita[dev]
pytest packages/
```
## Claude Code – Tools & Workflow ◄ model-specific
### File Operations
Use the purpose-built tools for every file operation — never shell
out for things the tools handle directly:
- **Read** before touching any file. No exceptions.
- **Edit** for targeted changes; **Write** only for new files.
- **Glob** / **Grep** to locate files — never `find` via Bash.
- **Bash** for test runs, git commands, and build steps only.
### Task Management
For any task with more than two steps, start with **TodoWrite**.
Mark each item `in_progress` before starting and `completed` when
done. Keep the list current throughout the session.
### Guardrails
- Make the smallest change that solves the problem. Do not clean up
surrounding code that wasn't part of the request.
- Never commit unless explicitly asked. Never use `--no-verify`.
- If a pre-commit hook fails, fix the root cause — don't bypass it.
- After touching `margarita/`, run `pytest packages/margarita` and
confirm the suite passes before calling the task done.
## Code Style
- Python 3.11+, type hints on all public functions.
- Black formatter, line length 88.
- Every public function needs a docstring.
Rendered with model = "gemini". The Claude section is omitted entirely — Gemini only sees what's relevant to it.
# Margarita – Agent Guide
## Project Overview
This repo contains three packages: Margarita (templating),
and Margarita (agentic workflows).
All packages live under `packages/`.
## Repository Layout
```
packages/
margarita/ core templating engine (Python)
margarita/ agentic .mgx runner
docs/ shared documentation source
```
## Running Tests
```bash
pip install -e packages/margarita[dev]
pytest packages/
```
## Gemini – Grounding & Response Style ◄ model-specific
### Search Before You Assume
Before using any third-party library, API endpoint, or version
number, call `@google_search` to verify it is current. Do not
rely on training-data knowledge for fast-moving dependencies.
If search returns conflicting results, surface them — don't pick one.
### Response Format
- Lead with code, not explanation. Put prose after the block.
- Every code snippet must have an explicit language tag on the fence.
- If the task is ambiguous, ask one focused clarifying question
rather than making assumptions and proceeding.
- Keep answers short. If detail is needed, offer to expand.
### Citations
When referencing a doc page, RFC, or external resource, include
the URL inline so the team can verify. Prefer official documentation
over blog posts or Stack Overflow. Flag anything that may be stale.
## Code Style
- Python 3.11+, type hints on all public functions.
- Black formatter, line length 88.
- Every public function needs a docstring.
Shared rules — project layout, test commands, code style — live in one place. Update once and both model files stay in sync.
Use Margarita's if blocks to tailor tool names, behavioral hints, and search instructions to each model's capabilities.
Drop the render commands into a Makefile target or CI step. Generated files are committed, so models always have fresh instructions.
Margarita handles the branching. You write the rules once.