Skip to content

How to keep an agent skill’s context footprint and token cost predictable

Updated December 3, 202616 min read

A skill adds to an agent’s context at three points: its name and description in the list of skills when a session starts, the body of SKILL.md when the skill is invoked, and every file or command output the skill then asks for. This guide measures each point in Claude Code and restructures one skill three ways: everything in one SKILL.md, a short SKILL.md with a reference file that loads on demand (progressive disclosure), and a shorter SKILL.md that hands its validation to a script.

The worked example is Buyer Release Notes, the skill in the Buyer Release Notes sample ZIP file, which drafts release notes from a file of change records. On Nov 27, 2026, we ran each form three times on each of two input files in Claude Code 2.1.325 with claude-sonnet-5-5, measured startup in separate sessions, and recorded the token usage that the client reported for every session. With the skill installed, a one-request session came to 57 more total input tokens than without it when the same plugins loaded, the same for an 11,209-byte SKILL.md as for a 2,869-byte one. Moving the reference material out of SKILL.md cut a session on the sample input from 22,441 to 19,590 total input tokens. It also produced the only failed drafts in the benchmark: on an input that needed the reference file, Claude skipped the file in two of three runs and broke a rule that only that file stated. The run that read the file came to 34,932 total input tokens, against 22,692 to 35,680 for the inline form on that input. The script form never used the fewest tokens, and it was the only form whose drafts and number of requests stayed the same from run to run on both inputs. What the test covered gives the conditions and the limits.

Measure the context a skill loads at startup and on invocation

Run the skill without the interactive screen and save the event stream. Start in a project folder that holds the skill at .claude/skills/buyer-release-notes/SKILL.md and an input file, and use a new session for every run.

Shell
claude -p "Draft buyer-facing release notes from examples/release.json." \
  --model sonnet --effort medium --setting-sources project \
  --tools Read,Skill,Bash \
  --allowedTools "Bash(python3 \"$PWD/.claude/skills/buyer-release-notes/scripts/check_release.py\" *)" \
  --strict-mcp-config --no-session-persistence \
  --output-format stream-json --verbose > log.jsonl 2> log.stderr

Every recorded session ran this command without the inner quotes around the script’s path. Sessions on the second input file named examples/release-2.4.0.json instead, and the startup sessions below sent a different request. --tools limits the session to three tools, and --allowedTools approves one command, the script in Offload deterministic validation to a small script. The rule matches the command as SKILL.md writes it, so quote the path in both. Keep the command the same for every form you compare, so that every session carries the same tool definitions. Claude Code’s CLI reference (opens in a new tab) documents the flags, and the Claude Code programmatic usage guide (opens in a new tab) documents the event stream.

Each line of log.jsonl is one event. The first, a system event with the subtype init, lists the session’s skills in its skills array, so it shows whether yours loaded. It also gives the client version, the model that an alias resolved to, and the plugins that loaded. The last, the result event, holds a usage object that adds up every request the session made. With jq installed, these commands print what init loaded, the usage fields with their total, and the number of requests:

Shell
jq -c 'select(.type == "system" and .subtype == "init") | {claude_code_version, model, skills, plugins: [.plugins[].name]}' log.jsonl
jq -c 'select(.type == "result") | .usage | {input_tokens, cache_creation_input_tokens, cache_read_input_tokens, output_tokens, total_input_tokens: (.input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens)}' log.jsonl
jq -r 'select(.type == "assistant") | .message.id' log.jsonl | uniq | wc -l

usage reports the input in three fields that don’t overlap. input_tokens counts only what came after the last cache breakpoint, and the two cache fields count the rest, so Anthropic’s prompt caching documentation (opens in a new tab) adds all three to get the total input. Which field a token lands in depends on whether an earlier request had cached that text. The first session of the inline form reported 9,983 in cache_creation_input_tokens, the next two reported 0, and all three came to 22,441 total input tokens. This guide compares total input tokens, reports output_tokens separately, and lists every field of every session in Every recorded session.

To measure the startup cost, send a request that needs no tool, so that the session makes one request, and run it with and without the skill installed. We sent the request Reply with the single word ready. three times in a folder without the skill and three times each with the inline form and the script form, the largest and the smallest SKILL.md we tested:

Table 1 in How to keep an agent skill’s context footprint and token cost predictable
FolderSKILL.mdTotal input tokens
No skillNo file8,764-8,804
Inline form11,209 bytes8,821
Script form2,869 bytes8,821

Both forms came to 8,821 in every run, so the size of SKILL.md didn’t change the startup total. With the skill installed, the request came to 57 more tokens than the 8,764 without it. The event stream doesn’t show what those tokens were, so their source is an inference. Claude Code’s documentation says that a listing of skill names and descriptions is in context so that Claude knows what’s available, under Claude Code’s skill description limits (opens in a new tab), and that a skill’s full content loads only when it’s invoked, in Claude Code’s skill invocation controls (opens in a new tab). Apart from the skill, the folders differed only in a second input file that no startup session read, so we attribute the 57 tokens to the skill’s entry in that listing. In an interactive session, /context reports the size of the listing. We didn’t use it.

One session without the skill came to 8,804. Its init event listed one more built-in plugin than the other startup sessions, and three of our 35 sessions listed that plugin. Read init before you compare two runs, and compare runs that loaded the same plugins.

Invoking the skill adds its body. In the event stream, the Skill tool returns one line, Launching skill: buyer-release-notes, and the body follows as a message of its own: the text of SKILL.md below the frontmatter, after a line that names the skill’s folder. For the inline form, that message was 11,203 bytes. Claude Code keeps an invoked skill’s content in the conversation for later turns, in Claude Code’s skill content lifecycle (opens in a new tab), and it sends the whole conversation with every request, including another request after each round of tool calls, as Claude Code’s cost documentation (opens in a new tab) describes. By that documentation, the body counts again in every later request. A file that Claude reads stays in the conversation the same way, and the Read tool returns it with a number on every line: 938 bytes for the 839-byte sample input.

Trim SKILL.md to trigger metadata and workflow steps

For the benchmark’s inline form, we appended reference material to the sample’s SKILL.md: a JSON Schema for the input, a table of 19 edge cases, a table of seven wording rules, and five worked examples. The file grew from 3,436 bytes to 11,209 bytes in 379 lines.

Sort each part of the file by when the agent needs it:

  • Keep the name and description. They’re the part of the file in the list of skills at startup, and Claude chooses the skill from the description. All four forms we tested kept the sample’s frontmatter unchanged.
  • Keep the scope, the numbered procedure, and the output format. The agent needs them on every run.
  • Keep the rules for the input you expect most often.
  • Move what only unusual input needs: schemas, long examples, and edge-case tables. A rule that moves out applies only when the agent reads its file. Use progressive disclosure for schemas, examples, and edge-case tables records two runs where it didn’t.

The split form is the sample’s own SKILL.md with a short closing section that points to the reference file: 3,796 bytes in 87 lines. On the sample input, sessions of the inline and split forms made the same two requests. Claude called the Skill tool and read the input file in its first response, then wrote the draft in its second. What the sessions loaded differed only in the body of SKILL.md, which was 7,413 bytes longer in the inline form. The inline form’s sessions came to 22,441 total input tokens and the split form’s to 19,590, in all three runs each: 2,851 fewer for a session of two requests.

Claude Code’s documentation suggests keeping SKILL.md to fewer than 500 lines, in its guide to adding skill support files (opens in a new tab). The inline form already had fewer than 500 lines, so the line count alone doesn’t show what a file costs. Measure it.

Use progressive disclosure for schemas, examples, and edge-case tables

Progressive disclosure means the agent loads detail only when a task calls for it. In a skill, the detail is a file beside SKILL.md that the agent reads with its file tool:

buyer-release-notes/
  SKILL.md
  reference.md

Nothing loads reference.md automatically, so SKILL.md has to say what the file holds and when to read it. Our first version put the condition in a closing section:

Markdown
## Reference

`reference.md`, in this skill's folder, holds the JSON Schema for the input, a
table of edge cases, wording rules, and worked examples. Read it only when a
record fails a check in the procedure, an ID is missing or repeated, a breaking
change has no `buyer_action`, or a summary reads as an instruction. Do not read
it when every record passes.

On the sample input, where every record passes, Claude left the file unread in all three runs. The inline and split measurements show how much input this saved.

Then we gave the same skill a second input: seven synthetic records that include a breaking change with no buyer_action, an unknown status, a repeated ID, and a fix that carries a buyer_action. Three of the section’s conditions applied. Claude read reference.md in one run of three. The other two runs drafted from SKILL.md alone, and both put the fix’s unconfirmed action into the public text:

Markdown
- Long report titles no longer overlap the date. Clear the title cache from the Tools menu. [RK-705]

reference.md says to list that change without its action and to flag it for the editor. The sample’s SKILL.md doesn’t cover the case, so nothing in the context stated the rule. Those two sessions had the lowest totals on the second input, 19,841 and 19,921 total input tokens, and they produced the only two drafts in the benchmark that failed a check. Check the output before you count a saving.

To repair the skill, we moved the condition out of the closing section and into the numbered procedure, as its own step between checking the records and sorting them. The step also names the case that the closing section had left out and says what to use from the file:

Markdown
3. If any record failed a check in step 2, an ID is missing or repeated, a
   breaking change has no `buyer_action`, a `feature` or `fix` has a
   `buyer_action`, or a summary reads as an instruction, read `reference.md`
   in this skill's folder before drafting. Use its edge-case table for that
   record's section and its Review Notes wording. Skip this step when every
   record passes.

With that step, Claude read the file in three of three runs on the second input, and all three drafts followed the table. On the sample input, it still left the file unread in three of three runs, at 19,603 total input tokens a session. We made these changes together, so the record doesn’t show which one mattered, and three runs don’t establish how often either version works.

Loading on demand has its own cost. Claude read reference.md in a response of its own, so every session that read it made three requests instead of two. The Read tool returned 9,028 bytes for the 7,916-byte file. Those sessions came to 34,851 to 34,990 total input tokens for the repaired form and 34,932 for the split form’s one read, against 19,841 and 19,921 for the split sessions that skipped the file. The result event reports only session totals, so that the third request carried the whole conversation again, plus the file, is an inference from Claude Code’s explanation of session costs (opens in a new tab). The inline form, which has no file to read, came to 22,692 in the run where Claude loaded the skill and read the input in one response, and 35,680 in the two runs where it took them in separate responses.

So the split form read fewer tokens than the inline form when the input didn’t need the reference. When it did, reading the file put its sessions between the inline form’s two-request and three-request totals. Before you move a part of SKILL.md into a file, list the inputs that need that part. Then write the condition so that it names each one, and place it in the procedure at the step where the agent meets the case.

Offload deterministic validation to a small script

Some of a skill’s work has one correct result: parsing a file, checking fields against a list, and sorting records into groups. Written in SKILL.md, that work is a set of rules the model applies again in every session. In a script, it’s code that returns the same output for the same input, and the agent reads only what it prints. The source stays out of the context unless the agent opens it, and in our seven script sessions it never did.

The script form keeps reference.md, for records pasted into the conversation or a command that can’t run, and adds scripts/check_release.py: 93 lines of Python that use only the standard library, read one JSON file, and print one JSON object. It writes no files and makes no network calls. For the sample input, 524 bytes of output reached the conversation:

JSON
{
  "ok": true,
  "product": "Report Kit",
  "version": "2.0.0",
  "buyer_actions": [
    {
      "id": "RK-102",
      "buyer_action": "Rename config.json to settings.json before running version 2.0.0."
    }
  ],
  "changes": [
    {
      "id": "RK-101",
      "summary": "CSV exports now include column headings."
    }
  ],
  "review_notes": [
    {
      "id": "RK-103",
      "reason": "Excluded because it is planned."
    },
    {
      "id": "RK-104",
      "reason": "Excluded because it is internal."
    }
  ]
}

In its SKILL.md, one step that runs the script replaces the input rules and the checks:

Markdown
1. When the user names a local input file, run exactly this command, replacing
   only `<input-file>` with the path the user gave. Do not read the input file
   or the script.

   ```bash
   python3 "${CLAUDE_SKILL_DIR}/scripts/check_release.py" "<input-file>"
   ```

Claude Code replaces ${CLAUDE_SKILL_DIR} with the skill folder’s path when it loads the skill, as Claude Code’s skill substitutions (opens in a new tab) describes, so the command doesn’t depend on where the skill is installed. In our sessions, the loaded text showed the full path. Keep the quotes around it. Without them, the command fails when a folder in the path has a space in its name, such as My Project. The recorded sessions ran without them, in folders with no spaces. On Dec 3, 2026, one more session ran the script with the quotes, in the command and in the permission rule, from a project folder named My Project.

A script needs a tool that runs commands, and that tool needs permission. Claude Code’s documentation says that a noninteractive session in manual mode denies a call that needs approval unless something approves it, under Claude Code tool preapproval for headless sessions (opens in a new tab). The measurement command approves this one script by its full path with --allowedTools, written in Claude Code’s permission rule syntax (opens in a new tab). The rule matched in all seven sessions, and no tool call was denied. A skill can also approve its own script through the allowed-tools field, which Claude Code tool preapproval for skills (opens in a new tab) describes. We didn’t test that field.

For a buyer, that grant means letting Claude run a program on their computer with their permissions, which the split form never asks for, and the script needs Python 3. In manual mode, Claude Code asks before it runs the script unless an allow rule covers it. Run the skill and confirm that it loaded tells buyers to approve only what the README calls for, so name the script, its command, what it reads, and what it needs in your README.

On the sample input, the script changed four things:

  • It added a request. Running the script is a tool call, and its output came back in a third request. A session came to 30,403 to 30,404 total input tokens, against 19,590 for the split form.
  • It shortened SKILL.md by 927 bytes, from the split form’s 3,796 to 2,869.
  • It didn’t keep the input out of the context. Claude read the input file in the same response in which it called the Skill tool, before the instruction not to read it had loaded. That happened in all seven script sessions, so the script’s output came on top of the input instead of replacing it.
  • It kept the wording the same. The script writes each Review Notes reason, and every draft was identical: four of four on the sample input, counting one trial session, and three of three on the second input, where each session made three requests and came to 31,016 total input tokens.

For this task and these two inputs, the script form was the most consistent form but not the cheapest. We didn’t test larger inputs.

Compare token cost and output before and after

Run every form on the same inputs, more than once, and compare three things: the number of requests, the total input tokens, and whether each draft meets criteria you fixed in advance. A script checked ours, so nobody judged a draft by reading it. The criteria were the title line, the three headings in order, nothing outside the draft, each buyer action exact and with its ID, each public change with its ID, no excluded ID in a public section, every flagged ID in Review Notes, no internal summary anywhere, and no unconfirmed action in a public section.

Each row is three sessions on the sample input, where every record passes. “Repaired” is the split form with the condition as step 3:

Table 2 in How to keep an agent skill’s context footprint and token cost predictable
FormRequestsTotal input tokensoutput_tokensDifferent drafts
Inline222,4413101
Split219,590315-3182
Split, repaired219,603386-4202
Script330,403-30,404543-5591

All 12 drafts passed every criterion. Each split form produced two different drafts in three runs, because Claude worded the Review Notes reasons itself: the edge-case table that gives that wording was in the file it didn’t read.

Each form ran three times on the second input, where records fail checks:

Table 3 in How to keep an agent skill’s context footprint and token cost predictable
FormRequestsReference readPassedTotal input tokensoutput_tokens
Inline2 to 3No file3 of 322,692 to 35,680392 to 592
Split2 to 31 of 31 of 319,841 to 34,932770 to 850
Split, repaired33 of 33 of 334,851 to 34,990682 to 761
Script30 of 33 of 331,016584

Three of these 12 drafts arrived inside a Markdown code fence: two from the inline form and one from the repaired form. The checks read the text inside the fence.

Across both inputs, the number of requests affected the totals more than the size of SKILL.md. For example, the inline form’s sessions on the second input differ by 12,988 total input tokens, two requests against three. On that input, the script form’s total fell between those of the two-request sessions and the other forms’ three-request sessions.

Every recorded session

These are the four usage fields from the result event of each session, as the client named and reported them. startup marks the one-request sessions, split-step is the repaired split form, second-input marks the second input, baseline-no-skill ran the benchmark request once without the skill, and pilot-script is a trial of the script form:

session,input_tokens,cache_creation_input_tokens,cache_read_input_tokens,output_tokens
baseline-no-skill,4,9316,8772,323
pilot-script,8,7375,23021,551
startup-none-1,2,5179,3623,4
startup-none-2,2,5139,3623,4
startup-none-3,2,0,8762,4
startup-inline-1,2,5196,3623,4
startup-inline-2,2,0,8819,4
startup-inline-3,2,0,8819,4
startup-script-1,2,5196,3623,4
startup-script-2,2,0,8819,4
startup-script-3,2,0,8819,4
inline-1,6,9983,12452,310
inline-2,6,0,22435,310
inline-3,6,0,22435,310
split-1,6,7132,12452,318
split-2,6,0,19584,315
split-3,6,0,19584,318
split-step-1,6,7145,12452,420
split-step-2,6,0,19597,419
split-step-3,6,0,19597,386
script-1,8,428,29967,547
script-2,8,0,30396,543
script-3,8,0,30396,559
inline-second-input-1,8,8396,27276,392
inline-second-input-2,8,0,35672,392
inline-second-input-3,6,5016,17670,592
split-second-input-1,6,5585,14250,810
split-second-input-2,6,7417,12498,850
split-second-input-3,8,4089,30835,770
split-step-second-input-1,8,11431,23551,682
split-step-second-input-2,8,9580,25263,761
split-step-second-input-3,8,4027,30861,715
script-second-input-1,8,5944,25064,584
script-second-input-2,8,0,31008,584
script-second-input-3,8,0,31008,584

The same object also reports output_tokens_details.thinking_tokens, which ranged from 0 to 368 in these sessions. startup-none-1, split-second-input-2, and split-step-second-input-1 are the three sessions whose init event listed the extra built-in plugin.

What the test covered

We recorded 35 sessions on Nov 27, 2026, with Claude Code 2.1.325 on macOS 27.2.1, using claude-sonnet-5-5 (the sonnet alias) at medium effort: three sessions for each of four forms on each of two inputs, nine one-request startup sessions, one session of the benchmark request without the skill, and one trial of the script form. Each was a new noninteractive session with a cleared environment, started in a project folder that held one form of the skill or none, through the command in Measure the context a skill loads at startup and on invocation. Every session used manual permission mode, the project’s own settings, no MCP servers, and the same three tools. On that Mac, python3 was Python 3.15.2. The skills and plugins that came with the client and the account were available too, and none of those skills ran. The repaired split form and the startup sessions ran about four hours after the others, with the same client version. In every session, the result event’s modelUsage entry for the model reported the same numbers as usage.

A separate Dec 3 session checked the quoted script path in a folder named My Project. It isn’t part of the token measurements. Results on another model, client version, effort level, tool set, skill, or input can differ. The record doesn’t cover direct invocation with /buyer-release-notes, the allowed-tools field, an interactive session, a second message in the same conversation, larger inputs, or any other client. Three sessions show that a result can happen. They don’t measure how often it happens. The numbers are token counts as the client reported them. We publish no price, because what a token costs depends on your plan and on the cache.

Package the form you measured

Ship the form you tested, with its reference files and scripts inside the skill folder, and state the client, the model, and the inputs behind your numbers in the package’s test record. Your buyers install the folder as How to install a skill in Claude Code, Codex, or Grok Build describes. If you ship the skill inside a plugin, How to package and sell a Claude Code plugin covers that package. Once your measurements are recorded, package the tested skill for sale.

Was this helpful?

Need more help? or contact Kurodyne support.