Sub topic 1
Why Packaging Instructions Matters: The Context Window
This chapter explains the constraint behind everything else in this tutorial: an AI coding agent can only act on what is in its context window. Prompt files, custom agents, and skills are three ways to control what goes into that window, and when.
Prerequisites
This chapter assumes you have:
- Used an AI coding assistant or agent in an editor or terminal.
- Basic familiarity with Markdown and simple YAML.
- Basic Git and repository layout knowledge.
- A general idea of what a prompt is.
You do not need to have written any prompt files, agents, or skills yet.
The context window is the agent's working memory
A language model does not remember your project between requests. Each time it responds, it reads one block of text and produces a continuation. That block is the context window. It is measured in tokens, which are chunks of text roughly the size of a short word or word fragment. Every model has a maximum number of tokens it can read at once.
The window holds everything the model can use:
- The tool's built-in system prompt.
- Project instructions the tool loads automatically.
- Descriptions of the tools the agent may call.
- Your messages and the agent's earlier replies.
- Results of tool calls, such as file contents and command output.
- Any prompt file, agent role, or skill text that has been loaded.
If something is not in the window, the agent cannot use it. If it is in the window, it costs space and competes for the model's attention.
Two limits: size and attention
The window limits you in two ways.
Hard size limit. When the total exceeds the model's maximum, something must go. Tools handle this differently. Some summarize or drop older messages. Others stop with an error. Instructions that you typed early in a long session are often the first to be compressed away.
Soft attention limit. Even below the maximum, a longer window is not free. Models tend to follow a short, relevant set of instructions better than a long one that mixes many topics. Rules that do not apply to the current task add noise, and they can conflict with rules that do apply. Treat the space you spend on instructions as an instruction budget: a limited amount that you should spend where it helps the most.
The exact numbers vary by model and tool, so check your tool's documentation. The design consequence stays the same: you cannot put everything in the window all the time.
Three ways to get instructions wrong
Without any packaging, teams usually fall into one of three patterns.
- Retyping. You paste the same review checklist into every session. This wastes effort, and the wording drifts from one session to the next, so results vary.
- Overstuffing. You put every rule, command, and convention into one large always-loaded file. The agent receives all of it on every request, including the parts that have nothing to do with the task. The budget runs out early and the important rules get diluted.
- Understuffing. You keep instructions short, but the agent lacks the knowledge it needs. It guesses at your changelog format, your test layout, or your release steps.
Packaging is the way out. You write the instructions once, give them a name and a location, and control when they enter the window.
Three mechanisms, three loading behaviors
The mechanisms in this tutorial differ mainly in when their text reaches the context window and who decides.
| Mechanism | Typical form | Enters the window when | Who triggers it |
|---|---|---|---|
| Persistent project instructions | A file such as AGENTS.md | At the start of every session | The tool, automatically |
| Reusable prompt file | A Markdown file you invoke by name | You run it | You |
| Custom agent | A Markdown or JSON definition with a role and tool list | You select it, or another agent delegates to it | You or the main agent |
| Agent skill | A folder with a SKILL.md file | A short description loads at start. The body loads when relevant | The agent, based on the task |
File locations, command names, and frontmatter fields differ between products. The examples in this tutorial are illustrative, so confirm the details in your tool's documentation.
Always loaded: persistent instructions
Persistent project instructions, such as an AGENTS.md file, are the baseline. They load every time, which makes them the right home for facts that apply to nearly every task: how to build the project, how to run tests, and the main conventions. Because they are always paid for, they should stay short. The next chapter covers this in more detail.
Loaded on request: prompt files and agents
A prompt file costs nothing until you invoke it. Then its full text enters the conversation as your request. A custom agent works differently: it gives a session or a delegated task its own role, instructions, and tool set. This keeps the specialist's setup out of your main session until it is needed.
Loaded on demand: skills
A skill is designed around the budget problem. At startup, the agent sees only a name and a short description for each skill. The full instructions and any supporting files are read only if the agent decides the skill applies to the task. This idea is called progressive disclosure, and a later chapter covers it in depth.
A worked budget example
Suppose a repository has five workflows: code review, changelog entries, database migrations, release notes, and incident write-ups. Each needs about 800 tokens of instructions. The numbers below are made up to show the pattern.
| Approach | Instruction tokens loaded for a task that needs only the changelog |
|---|---|
| Everything in one always-loaded file | 4,000 |
| Five prompt files, only one invoked | 800 |
| Five skills, only one selected | About 800, plus a small description for each of the other four |
The always-loaded file spends five times as much as the task requires, and four-fifths of that text is irrelevant. The prompt-file approach is cheap but depends on you remembering which file to call. The skills approach spends a little on descriptions so the agent can pick the right workflow itself.
Tokens are not the only cost. Irrelevant instructions can steer the agent wrongly. A migration rule such as "never edit applied migration files" has no bearing on a changelog task, but it still sits in the window and may bias the output.
Failure modes to watch for
- Silent truncation. A long session pushes early instructions out of the window, and the agent starts ignoring a rule it followed an hour ago. Packaged instructions that are re-loaded for each task avoid this problem.
- Conflicting instructions. A global rule says "always add tests" while a specific workflow says "do not edit any files". Decide which one wins, and write the exception into the narrower file.
- Vague triggers. A skill whose description is too general loads when it should not. One whose description is too narrow never loads. Chapter 10 returns to this.
- Stale packaged text. Instructions that mention a renamed command or removed folder mislead the agent with confidence. Keep them in the repository so they change with the code.
What comes next
The remaining chapters build on this idea. You will start with the always-loaded baseline, then add prompt files, custom agents, and skills. After that you will compare them, test them, share them, and review them for security risks.
Exercise
A repository has a 6,000-token always-loaded instruction file that covers build commands, a changelog format, and database migration rules. A developer asks the agent to fix a typo in a README. Name two problems that the large file causes for this task, and describe one way to repackage the changelog and migration material.
Show answer
First, the agent spends thousands of tokens on rules that have nothing to do with a README typo, which uses up budget that could hold useful context. Second, irrelevant rules add noise and can steer the agent, for example toward editing a changelog that does not need to change. A fix is to keep only short, universally relevant facts, such as build and test commands, in the always-loaded file. Move the changelog format and the migration rules into separate packaged units, either skills that load when the task matches or prompt files that a developer invokes by name.
Exercise
Why can a long session cause an agent to stop following a rule you gave it at the start, even though the window was never "full" in an obvious way?
Show answer
Tools often summarize or drop older content as the window fills, so an early instruction may be compressed or lost. Even before that point, a long window dilutes attention, and the model may weight a short early instruction less than recent content. Packaging the instruction in a file that loads again for each task keeps it fresh.