/llmctl-python:python-scriptsfrom llmctl Python
Single-file Python script discipline: PEP 723 inline script metadata as the only way a script declares its dependencies, an executable shebang, locking for reproducibility, argument/stream/exit-code conventions, and the criteria for graduating a script into a project. ALWAYS invoke before creating or editing a standalone .py file that is run rather than imported — automation, a one-off, a tool, a CI helper. Do not write a script that assumes pre-installed packages, ships a sidecar requirements.txt, or tells the user to install anything globally. Runner-agnostic: uv is the default, but any PEP 723-aware runner satisfies the rule. Conventions for the code inside the script belong to `python-standards`; multi-file project tooling to `modern-python`. Keywords: script, standalone, one-off, automation, shebang, PEP 723, inline metadata, uv run, pipx, cli, argparse, exit code.
Ships in llmctl Python. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A standalone script is a self-contained, executable artifact. Someone clones it, runs it, and it works — no README step, no virtualenv instructions, no "install these first". Everything below serves that property.
Scope boundary. How the code inside the script is written — typing, errors, data modelling, resources, logging — is owned by python-standards, which applies in full to a script body. Project bootstrap and tooling configuration are owned by the modern-python skill (APM dependency). This skill owns only the single-file form.
Every standalone script that imports anything outside the standard library carries a PEP 723 inline metadata block. This is not a preference — it is what makes the file self-contained.
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "httpx>=0.28",
# "rich>=14",
# ]
# ///
Rules for the block:
#-prefixed lines, opened by # /// script and closed by # ///. A line that is just # is an empty line; every other line is # followed by TOML.requires-python. Without it the script silently runs on whatever interpreter happens to be first on PATH, including ones its syntax does not support.dependencies always carries lower bounds ("httpx>=0.28"). A bare name resolves to whatever is newest on the day someone runs it.requires-python alone if the syntax needs a floor.Three things this replaces, none of which belong beside a single file: a sidecar requirements.txt, a comment telling the reader to pip install something, and an implicit assumption that the package is already there.
uv is the default — it is the fastest and most widely installed — but the rule above is about the file, not the tool. Any runner that reads inline metadata satisfies it:
| Runner | Invocation |
|---|---|
| uv | uv run script.py |
| pipx | pipx run script.py |
| hatch, pdm, pixi | their own run entry points |
| pip (26+) | pip install --requirements-from-script script.py, then run it |
Use whichever the project or machine already standardises on. What is not acceptable at any tier: installing the script's dependencies into the ambient system interpreter, or running it with a bare python script.py that only works because the packages happen to be installed already.
See inline-metadata.md for the full field reference, alternate indexes, and per-runner detail.
A script that is run directly gets a shebang and the executable bit:
#!/usr/bin/env -S uv run --script
-S is what lets env split the arguments so uv receives run --script; without it the whole string is treated as one program name. Then chmod +x script.py, and it runs as ./script.py.
Add --quiet (#!/usr/bin/env -S uv run --quiet --script) when the script's own stdout is consumed by something else and the runner's progress output would contaminate it.
Skip the shebang for a script that is only ever invoked through its runner explicitly, or that ships in a repo where the runner is not guaranteed — a shebang naming a tool the user does not have produces a worse error than uv run does.
Lower bounds keep a script working; they do not make two runs identical. Where the output matters — anything in CI, anything whose result is compared over time, anything shipped to someone else:
uv lock --script script.py writes a script.py.lock beside it, and subsequent runs resolve from that lock.--exclude-newer for an audit-grade rerun.A throwaway script needs none of this. A script that runs unattended needs one of them.
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = ["httpx>=0.28"]
# ///
"""One line saying what this does and what it prints."""
from __future__ import annotations
import argparse
import sys
from collections.abc import Sequence
def fetch_report(url: str, *, timeout_seconds: float) -> Report:
"""The actual work — pure enough to call from a test or another script."""
...
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
...
args = parser.parse_args(argv)
...
return 0
if __name__ == "__main__":
raise SystemExit(main())
Why each piece:
main(argv=None) -> int — takes its arguments instead of reading sys.argv directly, so it can be called from a test or another script with no subprocess.raise SystemExit(main()) — propagates the exit code. A bare main() call discards it and the script always reports success.--help description.if __name__. The __main__ guard wires things up; it does not compute.See script-template.md for complete annotated examples.
argparse from the standard library is the default — it keeps the dependency list empty. Reach for click or typer once there are subcommands or more than roughly six options, and add it to the block.0 success, non-zero failure, and distinct codes where a caller could plausibly branch on the reason. 130 on KeyboardInterrupt.0. Catch only what you can explain, and exit non-zero when you do.--json), unless the script exists to be piped.Anything that deletes, overwrites, moves, publishes or mutates a remote system:
--dry-run that prints exactly what would happen, and make it the default where the blast radius justifies it. --apply/--yes is the deliberate second step.Per python-standards §1, the tier decides the bar. For scripts specifically:
utils.py sitting beside your scripts: strict checking is strongly recommended. This is the tier where untyped code starts costing, and it arrives without announcing itself.Graduate it — hand off to modern-python for the project setup — when any of these is true:
console_scripts entry point) rather than run as a file.utils.py — that shared file is already a package with no packaging.Graduating is not a failure of the script form. Staying single-file past these points is.
# /// script block present whenever anything non-stdlib is importedrequires-python set; dependencies carry lower boundsrequirements.txt, no "run pip install first", no assumed global packagesmain(argv) -> int with raise SystemExit(main()); work in named functions--help--dry-run/--applypython-standardspython-standardsmodern-python skill (APM dependency)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
3 skills in this plugin
/modern-pythonConfigures Python projects with modern tooling (uv, ruff, ty). Use when creating projects, writing standalone scripts, or migrating from pip/Poetry/mypy/black./python-standardsAuthoring conventions for Python source: typing discipline, data modelling, module and API boundaries, error handling, resource and subprocess safety, logging, and concurrency choice. ALWAYS invoke when writing, reviewing or refactoring .py files — modules, packages, tests, or the body of a script. Covers how the code reads, not how the project is tooled: uv/pyproject setup, linter and type-checker configuration, packaging, CI and migration off pip/Poetry belong to the `modern-python` skill; single-file script mechanics and PEP 723 inline metadata belong to `python-scripts`. Do not write or review Python without this skill. Keywords: python, typing, type hints, annotations, dataclass, protocol, exceptions, pathlib, asyncio, logging, subprocess, docstring, api design.npx claudepluginhub siegenthalerroger/.llmctl-marketplace --plugin llmctl-python