Agent skill

shebangpython

Validate Python shebangs and PEP 723 inline script metadata. Use when checking if Python files have correct shebangs based on their dependency requirements, when fixing incorrect shebang patterns, or when adding PEP 723 script blocks to standalone scripts with external dependencies.

Stars 33
Forks 4

Install this agent skill to your Project

npx add-skill https://github.com/Jamie-BitFlight/claude_skills/tree/main/plugins/python3-development/skills/shebangpython

SKILL.md

<file_paths>$ARGUMENTS</file_paths>

Python Shebang Validation

The model validates Python shebangs against dependency requirements and ensures correct PEP 723 inline script metadata.

Arguments

<file_paths/>

Instructions

If file paths provided above:

  1. Read each file using the Read tool
  2. Check for shebang presence and correctness
  3. Validate against the rules below
  4. Check execute bit status
  5. Fix any misalignments with this guidance
  6. Report findings for each file

If no arguments provided:

  1. Ask the user which files or directories need shebang validation
  2. Suggest searching for Python files that might need shebangs
  3. Offer to check if existing shebangs are correct

Shebang Selection Rules

Rule 1: Stdlib-only executable scripts

Pattern: #!/usr/bin/env python3

Conditions:

  • File is executable
  • Has no external dependencies
  • Uses only Python standard library

Reasoning: No dependency installation required, standard Python interpreter sufficient.

Rule 2: Package executables

Pattern: #!/usr/bin/env python3

Conditions:

  • File is part of installed package
  • Has setup.py or pyproject.toml managing dependencies

Reasoning: Dependencies installed via package manager, not script metadata.

Rule 3: Standalone scripts with external dependencies

Pattern: #!/usr/bin/env -S uv --quiet run --active --script

Conditions:

  • File is executable standalone script
  • Requires external packages

Reasoning: PEP 723 inline metadata declares dependencies, uv installs them automatically.

Rule 4: Non-executable files

Pattern: No shebang line

Conditions:

  • File is library module
  • Imported by other code
  • Not directly executable

Reasoning: Not intended for direct execution.


UV Shebang Command Structure

The shebang: #!/usr/bin/env -S uv --quiet run --active --script

Component Breakdown

Component Position Purpose
#!/usr/bin/env -S Prefix Shebang invoking env with -S flag for multiple arguments
uv Command The uv binary on PATH
--quiet GLOBAL flag (before subcommand) Suppresses progress output from uv
run Subcommand Executes Python scripts with automatic environment management
--active run flag (after subcommand) Prefer active virtual environment over isolated environment
--script run flag (after subcommand) Indicates file contains PEP 723 inline script metadata

Command Syntax Pattern

text
uv [GLOBAL_FLAGS] SUBCOMMAND [SUBCOMMAND_FLAGS] [ARGS]

Flag Ordering Rule

Global flags modify the uv binary behavior and MUST appear before the subcommand. Subcommand flags modify that specific subcommand's behavior and MUST appear after the subcommand.

Valid: uv --quiet run --active --script Invalid: uv run --quiet --active --script (--quiet is global flag)

Invalid Variations

The model MUST reject these malformed shebangs:

  • #!/usr/bin/env -S uv run --quiet --active --script (--quiet in wrong position)
  • #!/usr/bin/env -S uv --quiet run --script (missing --active)
  • #!/usr/bin/env -S uv run --active --script (missing --quiet)
  • #!/usr/bin/env -S uv --quiet --active run --script (--active in wrong position)

Execute Bit Requirement

All files with shebangs MUST have execute permission set.

bash
chmod +x filename

Without execute bit, the shebang is ignored by the kernel.


Mandatory Verification Format

For each file, output in this exact order:

  1. Current shebang: [exact line from file or "none"]
  2. PEP 723 metadata dependencies: [exact list or "none"]
  3. External package count: [number with evidence]
  4. Import analysis:
    • stdlib: [list]
    • external: [list]
  5. Rule condition evaluation:
    • Rule 1: [condition 1 MET/NOT MET] [condition 2 MET/NOT MET] [condition 3 MET/NOT MET]
    • Rule 2: [condition 1 MET/NOT MET] [condition 2 MET/NOT MET]
    • Rule 3: [condition 1 MET/NOT MET] [condition 2 MET/NOT MET]
    • Rule 4: [condition 1 MET/NOT MET]
  6. Applicable rule: [number] because [one-sentence justification citing specific unmet/met conditions]
  7. Execute bit: [executable/not executable via test command]
  8. Verdict: CORRECT / INCORRECT [if incorrect, Edit the file to fix]

Transformation Examples

Example 1: Remove redundant PEP 723 from stdlib-only script

Before (invalid - no external dependencies):

python
#!/usr/bin/env -S uv --quiet run --active --script
# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///

from __future__ import annotations

import re
from pathlib import Path

After (corrected):

python
#!/usr/bin/env python3

from __future__ import annotations

import re
from pathlib import Path

Bundled Transitive Dependency Constraint

typer>=0.12.0 ships with rich and shellingham as bundled transitive dependencies. When typer appears in a PEP 723 dependencies block, the model MUST NOT add rich or shellingham as separate entries.

python
# WRONG — rich is transitively installed by typer
# dependencies = [
#   "typer>=0.21.2",
#   "rich>=13.0.0",   # ← redundant, DO NOT ADD
# ]

# CORRECT — typer only; rich and shellingham arrive automatically
# dependencies = [
#   "typer>=0.21.2",
# ]

This rule applies regardless of how much rich API surface the script uses (Console, Panel, Progress, Table, etc.). The import works because typer guarantees rich's presence.

SOURCE: "By default, typer comes with rich and shellingham." — https://typer.tiangolo.com/#installation (accessed 2026-02-22)


Example 2: Add PEP 723 to script with external dependencies

Before (invalid - missing PEP 723):

python
#!/usr/bin/env python

from __future__ import annotations

from pathlib import Path
from typing import Annotated

import typer
from rich.console import Console
from rich.panel import Panel

After (corrected):

python
#!/usr/bin/env -S uv --quiet run --active --script
# /// script
# requires-python = ">=3.11"
# dependencies = [
#     "typer>=0.21.2",
# ]
# ///

from __future__ import annotations

from pathlib import Path
from typing import Annotated

import typer
from rich.console import Console
from rich.panel import Panel

References

Expand your agent's capabilities with these related and highly-rated skills.

Jamie-BitFlight/claude_skills

ccc

This skill should be used when code search is needed (whether explicitly requested or as part of completing a task), when indexing the codebase after changes, or when the user asks about ccc, cocoindex-code, or the codebase index. Trigger phrases include 'search the codebase', 'find code related to', 'update the index', 'ccc', 'cocoindex-code'.

33 4
Explore
Jamie-BitFlight/claude_skills

agent-browser

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.

33 4
Explore
Jamie-BitFlight/claude_skills

delegate

Quick delegation template for sub-agent prompts. Use when assigning work to a sub-agent, before invoking the Agent tool, or when preparing prompts for specialized agents. Provides the WHERE-WHAT-WHY framework. For comprehensive delegation guidance, activate the agent-orchestration how-to-delegate skill.

33 4
Explore
Jamie-BitFlight/claude_skills

swarm-spawning

Spawn agents and teammates in Claude Code swarms. Use when choosing between subagents vs teammates, selecting agent types (Explore, Plan, general-purpose, plugin agents), configuring spawn backends (in-process, tmux, iterm2), or setting environment variables for spawned agents.

33 4
Explore
Jamie-BitFlight/claude_skills

knowledge-explorer

Manage the research/ knowledge base (KB) of tool and library research entries. Use when browsing KB topics, adding new research entries, updating existing entries with dated revisions, fetching GitHub repo metadata into a draft KB entry, or migrating old-format entries to skill-spec frontmatter. Triggers on tasks like "what do we have on X", "add this to the KB", "update the KB entry for Y", "fetch github info for owner/repo", or "migrate old entries".

33 4
Explore
Jamie-BitFlight/claude_skills

design-anti-patterns

Enforce anti-AI UI design rules based on the Uncodixfy methodology. Use when generating HTML, CSS, React, Vue, Svelte, or any frontend UI code. Prevents "Codex UI" — the generic AI aesthetic of soft gradients, floating panels, oversized rounded corners, glassmorphism, hero sections in dashboards, and decorative copy. Applies constraints from Linear/Raycast/Stripe/GitHub design philosophy: functional, honest, human-designed interfaces. Triggers on: UI generation, dashboard building, frontend component creation, CSS styling, landing page design, or any task producing visual interface code.

33 4
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results