Runtime Execution Skill
Execute Python and Node scripts using the best available package manager.
Python Execution Priority
- •uv (preferred) - Fast, reliable, handles dependencies automatically
- •poetry - Good for projects with poetry.lock
- •.venv/bin/python - Pre-existing virtual environment
- •python3 - Last resort, may miss dependencies
Node Execution Priority
- •pnpm (preferred) - Fast, disk-efficient
- •npm - Standard, widely available
- •yarn - Alternative package manager
- •npx - For one-off script execution
Usage Patterns
Python Script Execution
bash
# In a directory with pyproject.toml:
cd ${PLUGIN_DIR}/scripts
# Preferred (auto-installs deps)
uv run python script.py [args]
# Alternative
poetry run python script.py [args]
# If venv exists
.venv/bin/python script.py [args]
# Last resort (may fail on deps)
python3 script.py [args]
Node Script Execution
bash
# In a directory with package.json:
cd ${PLUGIN_DIR}/scripts
# Preferred
pnpm run script-name
pnpm exec script.js
# Alternative
npm run script-name
npx script.js
# Yarn
yarn run script-name
Detection Logic
When executing a script, detect the runtime context:
bash
# Python detection
if command -v uv &>/dev/null && [ -f pyproject.toml ]; then
uv run python "$@"
elif command -v poetry &>/dev/null && [ -f poetry.lock ]; then
poetry run python "$@"
elif [ -f .venv/bin/python ]; then
.venv/bin/python "$@"
else
python3 "$@"
fi
# Node detection
if command -v pnpm &>/dev/null && [ -f pnpm-lock.yaml ]; then
pnpm exec "$@"
elif command -v npm &>/dev/null && [ -f package-lock.json ]; then
npx "$@"
elif command -v yarn &>/dev/null && [ -f yarn.lock ]; then
yarn exec "$@"
else
node "$@"
fi
Important Notes
- •Always
cdto the script directory first (where pyproject.toml/package.json lives) - •Use
uv runfor Python - it auto-syncs dependencies from pyproject.toml - •Warn user if falling back to system Python/Node (deps may be missing)
- •For plugins, scripts are in
${CLAUDE_PLUGIN_ROOT}/scripts/
Common Issues
Missing Dependencies
If using system python3 and imports fail:
bash
# Install uv (recommended) curl -LsSf https://astral.sh/uv/install.sh | sh # Or create venv manually python3 -m venv .venv .venv/bin/pip install -e .
Wrong Python Version
bash
# Check version uv run python --version # Specify version in pyproject.toml: # requires-python = ">=3.10"