Sub topic 13
Choosing the right mechanism
This chapter assumes you have read the earlier chapters. You should know what a context window is and how persistent project instructions, prompt files, custom agents, and skills are laid out on disk. File names and frontmatter fields differ between products, so check your tool's documentation for exact details.
Four mechanisms, four jobs
Each mechanism answers a different question.
| Mechanism | Who starts it | What it changes | Context cost |
|---|---|---|---|
| Persistent instructions (for example AGENTS.md) | Loaded automatically | Baseline rules for every task | Always paid |
| Prompt file | You, by name | One fixed task and output format | Paid when you run it |
| Custom agent | You, by choosing it | Role, instructions, and tool access | Paid for the whole session |
| Skill | The agent, by matching the description | A capability with optional extra files | Description always, body when needed |
Questions to ask
Work through these questions in order. Stop at the first match.
- Does every task need this rule? Build commands, code style, and directory layout belong in persistent instructions. Keep them short, because you pay for them every time.
- Do you want to trigger it yourself, with a predictable result? Use a prompt file. A staged-changes review with a fixed output format is a good fit.
- Does the work need a different role or tighter permissions? Use a custom agent. A reviewer that can only read files is a good example, because the restriction is the point.
- Should the agent decide when it applies, and does it need bundled files or scripts? Use a skill. A changelog writer that reads a format reference only when asked is a good example.
Worked examples
- Review staged changes before each commit. You start it, the steps are fixed, and no editing is allowed. Use a prompt file.
- A reviewer that must never write files. Prompt text can ask the model not to edit, but it cannot enforce that. Use a custom agent with only read tools.
- Writing changelog entries in the project's format. You want the agent to pick this up when you mention release notes, and the format rules are long. Use a skill. The rules stay in a reference file until they are needed.
- "Always run the linter before finishing." Every task needs it. Use persistent instructions.
Common errors
- Putting everything in persistent instructions. The file grows, uses context on every task, and unrelated rules compete for attention.
- Using a skill for a task you always start by hand. A prompt file is simpler and has no description to get wrong.
- Using a prompt file to enforce safety. Text asks. Tool scoping in a custom agent enforces.
- Vague skill descriptions. If the description does not say when to use the skill, the agent will not select it.
Combining mechanisms
The mechanisms work together. A custom agent can have a restricted tool list and rely on a skill for a specialized format. A prompt file can start a task that a custom agent then runs. Start with the simplest mechanism that does the job, and move up only when you hit a limit.
Exercise
Your team wants an assistant that audits dependency files and must be unable to modify any file, and it should be started explicitly by a developer. Which mechanism fits best, and why is a prompt file not enough?
Show answer
A custom agent with a read-only tool list. A prompt file can only ask the model not to edit files, and that request is not enforced. Tool scoping in a custom agent restricts what the agent can actually do.
Exercise
You have a long set of rules for writing database migrations. You only need them when someone asks for a migration, and you do not want them in context otherwise. Which mechanism fits?
Show answer
A skill. Only its short name and description are loaded up front. The full instructions and any reference files load when a migration task matches the description.