Skills Parameter Passing and Receiving

Skills do not receive explicit parameters like traditional functions; instead, they perceive input information through Claude's context.

Understanding this "implicit parameter passing" mechanism is the key to writing practical Skills.


Skills: How to Obtain Parameters

When Claude reads a Skill, the entire conversation context becomes the Skill's parameters.

This means that what the user says, uploaded files, and historical conversation records can all serve as input sources for the Skill.

Input Sources Example Description
User's current message "Help me process this PDF" The most direct input
Uploaded files User uploaded report.pdf Passed in via path or content
Historical conversation Data formats previously discussed Referencable in the context
System variables Current date, working directory path Automatically perceived by Claude

Declaring Expected Input in SKILL.md

In SKILL.md, natural language descriptions can tell Claude what information to extract from the context.

The following is a Skill example for processing CSV files, demonstrating how to declare input expectations in the instructions:

Example

---
name: csv-analyzer
description: Analyze user-uploaded CSV files and output statistical summaries. Triggered when the user mentions CSV or tabular data analysis.
---

# CSV Analyzer

## Input Requirements

The user should provide the following information (obtained from the conversation context):
- **File path**: The path of the uploaded CSV file (located at/mnt/user-data/uploads/)
- **Analysis objective**(Optional): What the user wants to know, such as"find null values"、"statistical distribution"
- **Output format**(Optional): Table, chart, or textual summary

If the above information is not clear, proactively confirm with the user before executing.

The "input requirements" in a Skill are written for Claude itself. Claude will proactively extract information from the context based on this specification, or ask the user for clarification when information is insufficient.


Receiving Structured Parameters via Scripts

When a Skill includes Python or Shell scripts, parameters are passed via command-line arguments or standard input.

This is exactly the same as the parameter handling in ordinary scripts.

Example

# File path: scripts/analyze.py
import argparse
import pandas as pd

def main():
    # Define command-line arguments
    parser = argparse.ArgumentParser(description="CSV file analysis script")
    parser.add_argument("file",        help="Required: CSV file path")
    parser.add_argument("--col",       help="Optional: Specify the column name to analyze")
    parser.add_argument("--limit", type=int, default=10,
                        help="Optional: Maximum number of rows to display, default 10")
    args = parser.parse_args()

    # Read the file
    df = pd.read_csv(args.file)

    # Filter columns as needed
    if args.col:
        df = df[[args.col]]

    # Output statistical information
    print(df.head(args.limit).to_string())
    print("\n--- Statistical Summary ---)
    print(df.describe())

if __name__ == "__main__":
    main()

How Claude calls this script in SKILL.md:

Example

## Execute Analysis

After obtaining the file path, run the following command:

```bash
python scripts/analyze.py <File path> [--col <Column name>] [--limit <Number of rows>]
```

Display the command-line output to the user and provide textual interpretation.

File Path Parameter Handling Specifications

User-uploaded files are uniformly located under/mnt/user-data/uploads/path.

In Skill scripts, always use absolute paths to access files to avoid path resolution errors.

Example

import os

# Correct: Use an absolute path
UPLOAD_DIR = "/mnt/user-data/uploads"
file_path = os.path.join(UPLOAD_DIR, "report.csv")

# Incorrect: Using a relative path (will fail due to different working directories)
# file_path = "uploads/report.csv"

# Check if the file exists
if not os.path.exists(file_path):
    print(f"Error: File does not exist → {file_path}")
    exit(1)

Parameter Validation: Checking Input Before Execution

Before execution, Skill scripts should always verify that key parameters are valid.

This prevents runtime crashes caused by missing parameters or format errors.

Example

# File path: scripts/validate_input.py
import sys
import os

def validate_csv_input(file_path: str) -> bool:
    """Validate whether the CSV file input is valid"""

    # Check whether the file path is provided
    if not file_path:
        print("Error: File path not provided")
        return False

    # Check if the file exists
    if not os.path.exists(file_path):
        print(f"Error: File does not exist → {file_path}")
        return False

    # Check the file extension
    if not file_path.lower().endswith(".csv"):
        print(f"Error: File type not supported, expected .csv, actual → {file_path}")
        return False

    # Check file size (warn when exceeding 100MB)
    size_mb = os.path.getsize(file_path) / (1024 * 1024)
    if size_mb > 100:
        print(f"Warning: File is large ({size_mb:.1f} MB), processing may be slow")

    return True

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python validate_input.py <file path>")
        sys.exit(1)

    ok = validate_csv_input(sys.argv[1])
    sys.exit(0 if ok else 1)

Parameter validation failure messages should clearly state what was expected and what was actually received, making it easy for Claude to provide specific reasons to the user.

Other Extensions