QA Interview Hub · Knowledge base · Quizzes · Українська

Product Engineering › Context, rules, skills

Instruction files, skills and the context budget

An agent gets project knowledge from instruction files (CLAUDE.md, AGENTS.md, Cursor rules) because a session starts with an empty context. The file is kept short. It is advice, not enforcement, so a rule that must not be broken becomes a hook or a permission deny. Procedures go into a skill, context is cleared between tasks, and after repeated failed corrections a new session is started.

Product Engineering · Agent context

You are fixing the same agent mistake for the third time. Is it time to open a new session?

The agent again runs the tests with the wrong command, and for the third time you explain which one is right. It does not seem to look at the rules in the instruction file, and the conversation already drags old attempts, logs and rejected options. This lesson is about where an agent gets its knowledge of the project, why an instruction file must be short, what belongs in a skill, and how to manage the finite context window.

How it works and why. Every new agent session starts with an empty context. Lasting knowledge about the project comes from instruction files: CLAUDE.md, AGENTS.md (an open format supported by different tools), Cursor rules. They are loaded at the start of the session. Claude Code reads AGENTS.md itself when the repository has no CLAUDE.md. When both files are needed, or a tool reads only CLAUDE.md, a thin CLAUDE.md imports AGENTS.md (@AGENTS.md), so that two copies are not maintained. Everything that gets into the context costs: space in the window, the model's attention and money for tokens.

What the context window consists of

System instructions and toolsalways there, you do not write themInstruction filesloaded at the start of the sessionSkill descriptionsthe full text only when neededThe conversationfiles, logs, attempts: only grows
Figure 1. What is permanent takes space in every session. The conversation displaces the important over time, so it is limited too.

This is context, not enforcement. The model reads the file and tries to follow it, but there is no guarantee, especially for vague or contradictory rules. A rule that must not be broken is built as a hook or a deny rule in permissions (see the lesson on controlling an agent).

Why the file must stay short. It takes up context in every session, and a file that is too long lowers rule adherence: what matters drowns among the minor. The Claude Code documentation advises keeping such a file concise (on the order of two hundred lines). Contradicting rules may be interpreted arbitrarily. The file holds what is needed almost always and cannot be seen from the code: build and test commands, conventions, limits. It does not hold: what a linter already checks, long procedures, secrets.

Example: what a useful file looks like.

# Project
An online shop: React, Fastify, Playwright tests.

## Commands
- Unit tests: npm test
- E2E: npm run e2e
- Lint and types: npm run lint && npm run typecheck

## Conventions
- Create test data through API fixtures, not through the UI.
- Locators: getByRole or getByTestId.

## Limits
- Do not touch the legacy/ folder.
- Change the database schema only with migrations (npm run db:migrate).

The same project in two instruction files

Wrong

"Write quality code and follow best practices" + 300 lines

Vague wishes, rules a linter already catches, a long release procedure and a token in an example. What matters drowns.

Right

Commands, conventions, limits

What cannot be seen from the code. Every line can be checked or executed. The file reads in a minute.

Figure 2. An instruction file is not project documentation but the minimum without which the agent makes mistakes.

Nested files. By the AGENTS.md format convention the file nearest to the edited one wins, so in a monorepo the rules of a subproject sit next to it. This is no guarantee: Claude Code, for example, puts instruction files together into context instead of overriding them and may pick either one when they conflict. So a local file says directly what exactly it replaces.

Skill or permanent rule. By default a skill description is always in context, while its full text is loaded only when the skill is needed. In Claude Code a skill with side effects, such as a release, can be limited to starting by a person, and then its description is not in context. So a multi-step procedure (cutting a release, writing test cases from a template) lives better in a skill, while a short fact needed every time goes into the instruction file. If a section of the file has become a procedure, it is a signal to move it to a skill:

---
name: release-notes
description: Prepares release notes from a list of merged PRs. Use
  when asked for release notes.
disable-model-invocation: true
---
1. Take the PRs merged since the last tag.
2. Group by type: features, fixes, internal changes.
3. For every line: what changed for the user, in one sentence.
4. Put breaking changes in a separate section.

Memory across sessions. There are two schemes: notes you write and notes the agent saves itself after corrections. Both are loaded at the start and can go stale, so before relying on a note about a file or a command, check it in the code.

The context budget. The window is finite: every file read, log and rejected attempt stays in it until the tool compacts the history into a summary, and details can get lost there. Context is cleared between unrelated tasks. If the same mistake was corrected twice and keeps coming back, a new session with a better prompt usually gives more than a third correction: the old session already holds rejected attempts that confuse the agent.

Handoff to a new chat. The state is written down briefly in a file instead of being retold from scratch. Five fields are useful: the goal, the decisions made, what is done, what is next, known pitfalls:

# Handoff to a new chat
Goal: add saved filters to the catalogue.
Decisions: a limit of 20 filters per user, stored on the server.
Done: the POST /filters endpoint, a migration, 6 tests.
Next: the save-dialog UI, an e2e test for the limit.
Pitfalls: the limit test fails if the DB is not cleaned before a run.

Limits and alternatives. An instruction file does not replace tests and CI: it lowers the number of mistakes but guarantees nothing. Different tools read different files, and loading behaviour changes between versions, so check it in your tool's documentation. Automatic memory is useful but can save a wrong conclusion. A very long context is more expensive and slower, and compaction of history can lose details: critical decisions are better put in a file. And if a rule is needed once a month, it belongs in a skill, not in the permanent file.

Common mistakes.

  • Bloating the instruction file with vague wishes: important rules drown.
  • Relying on the file for a critical rule: it is advice, not a boundary.
  • Keeping a procedure of several dozen steps in the file instead of a skill.
  • Putting secrets and tokens in the instruction file or in the context.
  • Trusting a memory note without checking it in the code: it may be stale.
  • Correcting the same mistake in the same session a third time instead of a new session with a better prompt.

Check yourself

CLAUDE.md says "never commit without lint and tests passing", yet the agent committed without them. Why, and what do you do?

Answer

An instruction file is context, not enforcement: the model tries to follow the rule but there is no guarantee. A rule that must not be broken is built as a hook before the tool call (a blocking code stops the commit) or a deny rule in permissions. The instruction stays as an explanation of why.

In the instruction file a section "How to cut a release" has grown to forty steps and takes half the file. What do you do?

Answer

Move it to a skill: the description is always in context, the full text is loaded only when needed. For a release with side effects the skill can be left to be started by a person only. The file keeps one line saying that such a skill exists.

In an interview. Junior: An agent starts a session with an empty context and takes project knowledge from instruction files such as CLAUDE.md or AGENTS.md. They are short: commands, conventions, limits. It is advice, not a guarantee. Middle/Senior: I manage the context window: the file is concise, multi-step procedures live in skills, and I clear the context between unrelated tasks. If a mistake repeats after two corrections, I open a new session with a better prompt. State between chats goes in a file with the goal, decisions, what is done, next steps and pitfalls. Rules that must not be broken go into hooks and permissions. I do not trust memory notes without checking them in the code.

More articles in this chapter