Intermediate9 min

Argument Substitution and Dynamic Skills

Skills become dramatically more reusable when they can accept arguments. Claude Code supports five substitution variables — $ARGUMENTS, $0/$1/$2, $ARGUMENTS[N], and two environment variables — that let a single skill serve a family of related tasks.

Quick Reference

  • $ARGUMENTS: everything typed after the skill name
  • $0, $1, $2: positional args split by space (shorthand for $ARGUMENTS[0] etc.)
  • $ARGUMENTS[N]: explicit 0-based index — same as $0/$1/$2
  • ${CLAUDE_SESSION_ID}: current session ID — useful for logging
  • ${CLAUDE_SKILL_DIR}: directory containing the SKILL.md — reference adjacent files
  • Multi-word args: use shell-style quoting — /skill 'hello world' second
  • Validation: check $ARGUMENTS in the skill body and ask for required args if missing
  • argument-hint: shows the expected arg format in the / menu autocomplete

All Substitution Variables

VariableWhat it containsExample
$ARGUMENTSFull argument string after the command/fix-issue 1234 → $ARGUMENTS = '1234'
$0First positional argument (same as $ARGUMENTS[0])/deploy staging api → $0 = 'staging'
$1Second positional argument/deploy staging api → $1 = 'api'
$2Third positional argument/migrate 1.0 2.0 rollback → $2 = 'rollback'
$ARGUMENTS[N]Explicit 0-based index (same as $0, $1, etc.)$ARGUMENTS[2] = third argument
${CLAUDE_SESSION_ID}Current session UUID — for logging or namingUnique per session
${CLAUDE_SKILL_DIR}Absolute path to the SKILL.md's directoryReference adjacent template files
Arguments Are Split by Space

Arguments are split by whitespace by default. For multi-word arguments, use shell-style quoting: /skill 'hello world' second will give $0 = 'hello world' and $1 = 'second'.