A slash command is an explicitly invoked, slash-prefixed entry point for an interactive agent workflow. It turns a recurring task into a reusable prompt with constraints instead of relying on an open-ended session. section 9.5.2 section 3.3.6
The engineering value is control. Agent sessions can read files, run commands, iterate, and consume substantially more tokens than standard completions. A command narrows exploration, limits output, caps retries, and states a token target. It does not make an agent correct; tests and unresolved-failure reporting remain necessary. section 9.5.2
A production-oriented slash command should:
- Restrict reading to files directly relevant to the requested change. section 9.5.2
- Prefer changed code or diff output over explanations when the task permits. section 9.5.2
- Run existing tests, define a maximum retry count, and stop with an explicit report when failures persist. section 9.5.2
- Pair with file-reading and command-output rules that exclude irrelevant directories and filter unbounded output. section 9.5.2
- Treat distributed command bundles as governed dependencies when plugins package commands with skills, subagents, hooks, or MCP configurations. section 3.3.6
Bounded focused refactor
A focused-refactor command can require reading only relevant files, generating only a diff, running existing tests without writing new ones, fixing failures for at most two iterations, and stopping near a 50,000-token budget. section 9.5.2
Listing 9.6 Custom slash commands for cost-controlled agent workflows
markdown <!-- .claude/commands/focused-refactor.md --> # Focused Refactor Refactor the specified function or module with these constraints: - Read ONLY the files directly relevant to the change - Do NOT explore the broader codebase unless explicitly needed - Generate ONLY the changed code (diff format preferred) - Do NOT explain changes unless asked - Run existing tests after changes; do NOT write new tests - If tests fail, fix the issue in max 2 iterations, then stop and report what's unresolved - Budget: aim to complete in under 50,000 tokens total $ARGUMENTS
Inspect the complete Markdown template for a cost-controlled focused-refactor command, including its constraints and argument placeholder. section 9.5.2
