How to Bundle Scripts Inside a Claude Skill
A Claude Skill with only instructions is a better prompt. Adding a script turns it into something that produces deterministic output — a real upgrade when the task involves spreadsheets, dates, or file parsing.
Short answer: put helper scripts in the Skill folder, reference them by relative path in SKILL.md, and let Claude execute them in the sandboxed environment. Keep scripts focused and take input from files or stdin rather than long argument strings.
How should a script-bearing Skill be laid out?
A predictable structure helps Claude find things.
weekly-report/
SKILL.md
scripts/build_report.py
references/columns.md
templates/summary.md
Claude loads SKILL.md first, reads references/ only when the instructions say to, and runs files under scripts/ when a step calls for it. That ordering keeps context small.
How does Claude actually run your script?
- The instruction in
SKILL.mdnames the script and the expected input, for example: “Run scripts/build_report.py against the user’s CSV and read its stdout.” - Claude writes the input file into the sandbox working directory.
- It executes the script with the bundled Python interpreter.
- It reads stdout back into the conversation and continues.
Because the script’s stdout re-enters context, keep output terse. A script that dumps 5,000 rows will consume your window and derail the task.
What makes a Skill script reliable?
| Practice | Reason |
|---|---|
| Read input from a file path | Long CLI args get mangled |
| Print structured output (JSON) | Easier for Claude to consume |
| Exit non-zero on failure | Claude notices and retries |
| No network calls | Sandbox blocks them anyway |
Favor the standard library. A dependency on pandas or requests will fail if the sandbox environment does not include it, and you cannot install packages at runtime.
How do you keep context usage under control?
This is the part teams get wrong. Every line Claude reads from your Skill costs tokens. Two techniques keep a Skill cheap.
First, put rarely used detail in references/ files and tell Claude to read them only when a specific condition applies. Second, have scripts output summaries rather than raw data — ten rows of JSON, not ten thousand.
Anthropic’s own guidance pushes toward the smallest instruction set that works. If your SKILL.md is 2,000 lines, it is firing on every matching request and eating your budget silently.
When is bundling a script the wrong move?
If the task is fundamentally judgment — tone, structure, prioritization — a script adds rigidity without helping. Skills that try to encode fuzzy decisions as code end up brittle, and you spend more time debugging the script than doing the work.
Scripts pay off for deterministic transforms: parsing CSV, computing dates, reformatting JSON, resizing images. Pair them with a rich SKILL.md and you get a Skill that is both consistent and flexible.
Quick Summary
- Store helper scripts under
scripts/and reference them by relative path in SKILL.md. - Claude runs scripts in a sandbox and reads stdout back into the conversation.
- Emit terse, structured output — verbose stdout burns your context window.
- Stick to the standard library; you cannot install packages at runtime.
- Use scripts for deterministic transforms, not for judgment calls.
