artisan-commands
When to use
Use when creating or modifying Laravel Artisan commands — maintenance scripts, imports/exports, batch processing, repair/cleanup, scheduled tasks, developer utilities.
Do NOT use when:
- Writing queue jobs (use
jobs-events skill)
- Writing scheduled task config (use
laravel-scheduling skill)
Procedure: Create an Artisan command
Step 0: Inspect
- Check existing commands — match naming, signature style, output format.
- Determine audience: developer, support, operations, cron, or scheduler.
- Determine if interactive or automated.
- Identify related services — commands orchestrate, not own business logic.
Step 1: Scaffold
- Create command class in
app/Console/Commands/ or module App/Commands/.
- Name:
{domain}:{action} — e.g. users:cleanup, orders:sync.
- Define arguments (required) and options (toggles/filters) explicitly.
Step 2: Implement handle()
- Validate preconditions (environment, input, dependencies).
- Call service/action for business logic.
- Report progress and results via console output.
- Return appropriate exit code.
Step 3: Safety checks
- Destructive? → Add
--force flag + confirmation.
- Scheduled? → Ensure non-interactive, idempotent, loud failures.
- Long-running? → Use chunking/cursors, progress bar.
- Production? → Add environment check if needed.
Step 4: Test
- Assert exit codes, console output, side effects, option behavior.
- Use
$this->artisan() in Pest tests.
Conventions
→ See guideline php/artisan-commands.md for full conventions.
Output format
- Artisan command class with signature, description, and handle method
- Registration in service provider or auto-discovery
- Example usage shown in a code comment
Gotcha
$this->info() is suppressed in quiet mode — use $this->line() for critical info.
- Always add
--force for destructive commands — never delete data without confirmation.
- Add environment checks for production commands.
Do NOT
- Do NOT run destructive operations without
--force confirmation.
- Do NOT use
$this->ask() for non-interactive commands (cron/queue).
- Do NOT put business logic in commands — delegate to services.
Auto-trigger keywords
- artisan command
- console command
- CLI command
- command signature
1---2name: artisan-commands3description: Use when creating or modifying Artisan commands. Covers clear signatures, safe execution flow, helpful output, and project conventions for console tooling.4---56# artisan-commands78## When to use910Use when creating or modifying Laravel Artisan commands — maintenance scripts, imports/exports, batch processing, repair/cleanup, scheduled tasks, developer utilities.1112Do NOT use when:13- Writing queue jobs (use `jobs-events` skill)14- Writing scheduled task config (use `laravel-scheduling` skill)1516## Procedure: Create an Artisan command1718### Step 0: Inspect19201. Check existing commands — match naming, signature style, output format.212. Determine audience: developer, support, operations, cron, or scheduler.223. Determine if interactive or automated.234. Identify related services — commands orchestrate, not own business logic.2425### Step 1: Scaffold26271. Create command class in `app/Console/Commands/` or module `App/Commands/`.282. Name: `{domain}:{action}` — e.g. `users:cleanup`, `orders:sync`.293. Define arguments (required) and options (toggles/filters) explicitly.3031### Step 2: Implement handle()32331. Validate preconditions (environment, input, dependencies).342. Call service/action for business logic.353. Report progress and results via console output.364. Return appropriate exit code.3738### Step 3: Safety checks3940- Destructive? → Add `--force` flag + confirmation.41- Scheduled? → Ensure non-interactive, idempotent, loud failures.42- Long-running? → Use chunking/cursors, progress bar.43- Production? → Add environment check if needed.4445### Step 4: Test4647- Assert exit codes, console output, side effects, option behavior.48- Use `$this->artisan()` in Pest tests.4950## Conventions5152→ See guideline `php/artisan-commands.md` for full conventions.5354## Output format55561. Artisan command class with signature, description, and handle method572. Registration in service provider or auto-discovery583. Example usage shown in a code comment5960## Gotcha6162- `$this->info()` is suppressed in quiet mode — use `$this->line()` for critical info.63- Always add `--force` for destructive commands — never delete data without confirmation.64- Add environment checks for production commands.6566## Do NOT6768- Do NOT run destructive operations without `--force` confirmation.69- Do NOT use `$this->ask()` for non-interactive commands (cron/queue).70- Do NOT put business logic in commands — delegate to services.7172## Auto-trigger keywords7374- artisan command75- console command76- CLI command77- command signature