Skip to main content
Command arguments in Pro Workflow support array access, validation, defaults, and conditional logic. Master argument handling for robust commands.

Basic Usage

# Command: /search testing edge cases

$ARGUMENTS
# Result: testing edge cases

Validation Patterns

Required Arguments

---
description: Refactor a file
argument-hint: <file> <action> <target>
---

# Refactor Command

File: $ARGUMENTS[0]
Action: $ARGUMENTS[1]
Target: $ARGUMENTS[2]

Validation:
- If any argument is missing, ask the user for clarification
- File must exist (use Read tool to verify)
- Action must be one of: rename, extract, inline, move

Optional Arguments

---
description: Search learnings
argument-hint: <query> [category] [project]
---

# Search Learnings

Query: $ARGUMENTS[0] (required)
Category: $ARGUMENTS[1] (optional, filter by category)
Project: $ARGUMENTS[2] (optional, filter by project)

If category or project not provided, search all.

Default Values

---
description: Run tests with coverage
argument-hint: [pattern]
---

# Run Tests

Pattern: $ARGUMENTS[0] or "**/*.test.ts" if not provided

\`\`\`bash
PATTERN="${ARGUMENTS[0]:-**/*.test.ts}"
npm test -- "$PATTERN" --coverage
\`\`\`

Argument Parsing

Quoted Strings

Quoted arguments are treated as single values:
# Command invocation
/search "run tests before commit"

# In command
$ARGUMENTS      # "run tests before commit"
$ARGUMENTS[0]   # "run tests before commit"

Multiple Words

# Without quotes
/search run tests before commit

$ARGUMENTS      # run tests before commit
$ARGUMENTS[0]   # run
$ARGUMENTS[1]   # tests
$ARGUMENTS[2]   # before

Flags and Options

---
description: Advanced search with flags
argument-hint: <query> [--category=X] [--project=Y] [--limit=N]
---

# Search with Flags

Parse arguments:

\`\`\`bash
QUERY="$ARGUMENTS[0]"
CATEGORY=""
PROJECT=""
LIMIT=10

for arg in $ARGUMENTS[1:]; do
  case $arg in
    --category=*) CATEGORY="${arg#*=}" ;;
    --project=*)  PROJECT="${arg#*=}" ;;
    --limit=*)    LIMIT="${arg#*=}" ;;
  esac
done
\`\`\`

Conditional Logic

Argument Count

---
description: Flexible commit command
argument-hint: [type] [message]
---

# Smart Commit

If 0 arguments:
  - Auto-generate commit message from git diff

If 1 argument:
  - Type: "feat"
  - Message: $ARGUMENTS[0]

If 2+ arguments:
  - Type: $ARGUMENTS[0]
  - Message: $ARGUMENTS[1:]

Examples:
- /commit → auto-generate
- /commit "add auth" → feat: add auth
- /commit fix "resolve login bug" → fix: resolve login bug

Argument Validation

---
description: Create a new agent
argument-hint: <name> <description>
---

# Create Agent

Name: $ARGUMENTS[0]
Description: $ARGUMENTS[1:]

Validation:
1. Check name format (lowercase, hyphens only)
2. Check if agent already exists
3. Validate description is not empty

If validation fails, show error and exit.

Environment Variable Substitution

---
description: Show session info
---

# Session Info

Session ID: ${CLAUDE_SESSION_ID}
Project: ${PROJECT_NAME}
User: ${USER}
Working Dir: ${PWD}

Advanced Patterns

Multi-Command Dispatch

---
description: Database operations
argument-hint: <operation> [...args]
---

# Database CLI

Operation: $ARGUMENTS[0]
Args: $ARGUMENTS[1:]

Dispatch based on operation:

- **init**: Initialize database
- **add**: Add learning ($ARGUMENTS[1] = category, $ARGUMENTS[2:] = rule)
- **search**: Search ($ARGUMENTS[1:] = query)
- **list**: List all ($ARGUMENTS[1] = category filter)
- **stats**: Show statistics

Examples:
- /db init
- /db add Testing "Run tests before commit"
- /db search authentication
- /db list Git
- /db stats

File Path Expansion

---
description: Edit multiple files
argument-hint: <pattern>
---

# Bulk Edit

Pattern: $ARGUMENTS[0]

Expand pattern to file list:

\`\`\`bash
PATTERN="$ARGUMENTS[0]"
FILES=$(find . -name "$PATTERN" -type f)

for file in $FILES; do
  echo "Editing: $file"
  # Apply transformation
done
\`\`\`

Example:
/bulk-edit "*.test.ts"

Interactive Argument Collection

---
description: Create new feature
argument-hint: [feature-name]
---

# Create Feature

Feature name: $ARGUMENTS[0]

If not provided, ask:
  "What feature are you building?"

Then ask:
  "Which files will this touch? (comma-separated)"
  "Any dependencies to install?"
  "Should I create tests?"

Collect all inputs before proceeding.

Escaping and Special Characters

Quotes in Arguments

# Single quotes
/search 'console.log'

# Double quotes
/search "error: 'not found'"

# Escaped quotes
/search "error: \"not found\""

Paths with Spaces

# Quoted path
/refactor "src/my component/index.ts" rename MyComponent

# In command
$ARGUMENTS[0]  # src/my component/index.ts

Error Handling

---
description: Safe command with validation
argument-hint: <required> [optional]
---

# Safe Command

Validate arguments:

\`\`\`bash
if [ -z "$ARGUMENTS[0]" ]; then
  echo "Error: Missing required argument"
  echo "Usage: /safe <required> [optional]"
  exit 1
fi

if [ ! -f "$ARGUMENTS[0]" ]; then
  echo "Error: File not found: $ARGUMENTS[0]"
  exit 1
fi
\`\`\`

Proceed only if validation passes.

Testing Arguments

# Test command with various inputs
/my-command test
/my-command "test with spaces"
/my-command test arg1 arg2
/my-command

# Debug argument parsing
echo "Arguments: $ARGUMENTS"
echo "Count: ${#ARGUMENTS[@]}"
echo "First: $ARGUMENTS[0]"
echo "Rest: $ARGUMENTS[1:]"

Best Practices

Validate Early

Check arguments at the start. Fail fast with clear error messages.

Document Examples

Show usage examples in the command description or body.

Use Defaults

Provide sensible defaults for optional arguments.

Quote Paths

Always quote file paths that might contain spaces.

Next Steps

Delegation

Pass arguments to agents

Frontmatter

Command configuration options

Agents

Create agents that accept arguments

Examples

Real-world command examples

Build docs developers (and LLMs) love