cli-command
Skill4 starsChanged 56 days agoMITView on GitHub
Scaffold a bin/magento console command or a cron job onto an existing Magento 2 module. Two modes: - command — Symfony Command subclass, CommandList DI registration, arguments, options, and Cli::RETURN_* exit codes. - cron — crontab.xml job declaration plus a job class with a delegate service; fixed <schedule> cron expression or <config_path> (pair with system-config). - Command name convention: {vendor_lower}:{module_lower}:{action} (all lowercase, colon-separated). See context/references/naming.md. - Return codes: use Magento\Framework\Console\Cli::RETURN_SUCCESS (0) and Magento\Framework\Console\Cli::RETURN_FAILURE (1). Never return bare 0/1 literals. -…
1 other project uses a version of this.
Adopted by
Most recently taken up by
- ComposioHQ/composiotheir own version, first seen Sep 29, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- ComposioHQ/composio★ 30ksame name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository35 other files it gives its agents.
- a11y-auditSkill
- admin-formSkill
- admin-listingSkill
- auditSkill
- breeze-adaptSkill
- breeze-compatSkill
- breeze-themeSkill
- contextSkill
- data-migrationSkill
- debugSkill
- deploySkill
- docsSkill
- eav-attributeSkill
- extension-pointSkill
- featureSkill
- fixSkill
- frontendSkill
- graphqlSkill
- i18nSkill
- indexerSkill
- lintSkill
- marketplaceSkill
- message-queueSkill
- module-createSkill
- perf-auditSkill
- releaseSkill
- remediateSkill
- reviewSkill
- securitySkill
- system-configSkill
- test-generateSkill
- triageSkill
- upgradeSkill
- webapiSkill
- widgetSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. About 0 are common, 5 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 27
Return codes: use Magento\Framework\Console\Cli::RETURN_SUCCESS (0) and Magento\Framework\Console\Cli::RETURN_FAILURE (1).
- Very specific: line 33
Area code: When the command or cron job interacts with store models that require a scope (e.g.
- Very specific: line 36
Cron idempotency: Every cron job must be safe to run twice in a row with the same outcome.
- Very specific: line 40
Schedule variants: use <schedule> for a literal cron expression (*/5 * * * *).
- Distinctive: line 66
Ask for any missing values in one batch.
- Distinctive: line 112
3A — Write the failing tests (RED): Before generating implementation code, write tests that express expected behaviour and confirm they …
- Very specific: line 125
Use self::assertNull or equivalent — no self::assertTrue(true).
- Very specific: line 127
Follow context/references/tdd-discipline.md.
- Distinctive: line 130
3B — Generate implementation (GREEN): Write the minimal code to make the 3A tests pass, using the templates:
- Very specific: line 148
Run the Phase 3A tests with {ctx.runner} vendor/bin/phpunit and confirm they now
- Very specific: line 150
Apply the shared module-hygiene baseline (required): After generating or modifying PHP files, run …
- Very specific: line 158
Run review --diff (gate: zero Critical/High findings).
- Very specific: line 163
Write a brief Markdown report to {output_root}/cli-commands/{Vendor}_{Module}-{mode}-{slug}-{date}.md listing:
- Distinctive: line 169
Test path + red→green evidence
- Very specific: line 243
All templates follow the placeholder registry in context/references/placeholder-schema.md.
- Very specific: line 249
All generated files pass php -l / xmllint --noout.
- Distinctive: line 252
No business logic in the command or cron class — delegated to the injected service.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Magento 2 CLI Command / Cron Job
Scaffold a bin/magento console command or a cron job onto an existing Magento 2
module. Two modes:
- command — Symfony
Commandsubclass,CommandListDI registration, arguments, options, andCli::RETURN_*exit codes. - cron —
crontab.xmljob declaration plus a job class with a delegate service; fixed<schedule>cron expression or<config_path>(pair withsystem-config).
Core Rules
- Command name convention:
{vendor_lower}:{module_lower}:{action}(all lowercase, colon-separated). Seecontext/references/naming.md. - Return codes: use
Magento\Framework\Console\Cli::RETURN_SUCCESS(0) andMagento\Framework\Console\Cli::RETURN_FAILURE(1). Never return bare0/1literals. - Delegate to a service. The command or cron class must do no business logic itself —
it constructs the call context and delegates to a constructor-injected
{ServiceName}. Tests mock the service, not the command internals. - Area code. When the command or cron job interacts with store models that require a
scope (e.g. store emulation), set the area code via
\Magento\Framework\App\State. The command class receivesStatevia DI; never callsetAreaCodetwice. - Cron idempotency. Every cron job must be safe to run twice in a row with the same
outcome. Long-running jobs should acquire a mutex (e.g. a flag file or a cache-backed
lock) to prevent overlap. See
${CLAUDE_SKILL_DIR}/references/cron-anatomy.md. - Schedule variants: use
<schedule>for a literal cron expression (*/5 * * * *); use<config_path>to read the expression from admin config (pair withsystem-configto add the field). Default cron group isdefault. - Coding style. Generated PHP follows PER-CS 3.0 as the baseline, with the Magento 2
coding standard taking precedence on any conflict;
--standard=Magento2PHPCS is the gate. Seecontext/references/php-coding-style.md. - Source of truth. Generate from templates → shared references → baked-in Magento 2 knowledge
→ official Magento/Adobe docs (live-fetched only when uncertain). Do NOT read, grep, or "study"
other modules under
app/code/vendor/*/Magento core to infer conventions, entity shapes, naming, or wiring. Narrow exceptions: the target module/class of this operation, and the specific contract of a module this code explicitly depends on. Affirm sources in the final report. Seecontext/references/source-of-truth.md.
Workflow
Phase 0 — Context Resolution
Invoke context (or run
${CLAUDE_PLUGIN_ROOT}/skills/context/scripts/resolve-context.sh); capture the
JSON as {ctx}. Abort if {ctx.magento_root} is unresolved.
Hard stop if the target module does not exist. Offer module-create and
do not scaffold into a non-existent module.
Phase 1 — Resolve Inputs
Ask for any missing values in one batch.
Command mode
| Input | Default | Notes |
| Module | (ask) | Existing {Vendor}_{Module} |
| Command class name | (ask) | PascalCase, e.g. SyncOrdersCommand; placed in Console/Command/ |
| Command name (CLI) | (ask) | {vendor_lower}:{module_lower}:{action}, e.g. acme:orders:sync |
| Command description | (ask) | Short description shown in bin/magento list |
| Arguments | (ask) | Zero or more: name, required (yes/no), description |
| Options | (ask) | Zero or more: name, shortcut, mode (value/flag), description |
| Service FQCN | (ask) | The injected service class this command delegates to |
Cron mode
| Input | Default | Notes |
| Module | (ask) | Existing {Vendor}_{Module} |
| Cron job class name | (ask) | PascalCase, e.g. SyncOrders; placed in Cron/ |
| Cron job name (XML) | (ask) | snake_case, unique across the Magento instance, e.g. acme_orders_sync |
| Schedule | (ask) | Literal cron expr (*/5 * * * *) OR config path (acme_orders/cron/schedule) |
| Cron group | default | Group id in crontab.xml; default covers most use cases |
| Service FQCN | (ask) | The injected service class this cron job delegates to |
See ${CLAUDE_SKILL_DIR}/references/console-command-anatomy.md and
${CLAUDE_SKILL_DIR}/references/cron-anatomy.md.
Phase 2 — Plan
Present every file to create or modify. Typical file sets per mode:
Command mode:
Console/Command/{CommandClass}.phpetc/di.xml(merge —CommandListregistration)Test/Unit/Console/Command/{CommandClass}Test.php
Cron mode:
Cron/{CronJobName}.phpetc/crontab.xml(merge)Test/Unit/Cron/{CronJobName}Test.php
Wait for "proceed."
Phase 3 — Test First, then Generate
3A — Write the failing tests (RED). Before generating implementation code, write tests that express expected behaviour and confirm they fail for the right reason.
- Command test (
Test/Unit/Console/Command/{CommandClass}Test.php): useSymfony\Component\Console\Tester\CommandTester; inject a mock{ServiceName}configured withexpects(self::once()); run the command viaCommandTester::execute(); assertself::assertSame(0, $tester->getStatusCode())(orMagento\Framework\Console\Cli::RETURN_SUCCESS); assert the output display contains the expected confirmation message. - Cron test (
Test/Unit/Cron/{CronJobName}Test.php): mock{ServiceName}withexpects(self::once())->method('execute')(or the relevant method); call the cronexecute()method; assert the return value (typicallyvoid/$this); callexecute()a second time on a fresh instance to demonstrate idempotency-safety of the class itself. Useself::assertNullor equivalent — noself::assertTrue(true).
Follow context/references/tdd-discipline.md. Run the 3A tests and confirm
they fail for the right reason (class-not-found, not a setup error).
3B — Generate implementation (GREEN). Write the minimal code to make the 3A tests pass, using the templates:
${CLAUDE_SKILL_DIR}/templates/command-class.php${CLAUDE_SKILL_DIR}/templates/command-di.xml${CLAUDE_SKILL_DIR}/templates/cron-job-class.php${CLAUDE_SKILL_DIR}/templates/crontab.xml${CLAUDE_SKILL_DIR}/templates/test-command-unit.php${CLAUDE_SKILL_DIR}/templates/test-cron-unit.php
See ${CLAUDE_SKILL_DIR}/references/console-command-anatomy.md,
${CLAUDE_SKILL_DIR}/references/cron-anatomy.md, and
${CLAUDE_SKILL_DIR}/references/pitfalls.md.
Phase 4 — Verify
php -lon every generated.phpfile.xmllint --noouton every generated.xmlfile.- Run the Phase 3A tests with
{ctx.runner} vendor/bin/phpunitand confirm they now pass (they failed before 3B); run the module suite to confirm nothing else broke. - Apply the shared module-hygiene baseline (required). After generating or modifying
PHP files, run
${CLAUDE_PLUGIN_ROOT}/skills/context/scripts/add-license-headers.sh {ctx.magento_root}/app/code/{Vendor}/{Module} {Vendor}to stamp the standard copyright header onto every new.php(idempotent — it skips files that already carry it). When adding acomposer.jsonrequireentry, resolve a bounded constraint via${CLAUDE_PLUGIN_ROOT}/skills/context/scripts/resolve-dep-constraint.sh <vendor/package>— never"*". Seecontext/references/module-hygiene.md. - Run
review --diff(gate: zero Critical/High findings). - Consult
${CLAUDE_SKILL_DIR}/references/pitfalls.mdbefore declaring Phase 4 done.
Phase 5 — Report
Write a brief Markdown report to
{output_root}/cli-commands/{Vendor}_{Module}-{mode}-{slug}-{date}.md listing:
- Mode (
commandorcron) - Command/job name
- Files generated
- Test path + red→green evidence
bin/magento setup:upgrade+bin/magento cache:flushcommands- (command mode) how to invoke:
bin/magento {CommandName} [args] [options] - (cron mode) how to trigger manually:
bin/magento cron:run --group={CronGroup}
Docs may now be stale. This change modified module code. Run
docs --module={Vendor}_{Module}to refresh the module's README, CHANGELOG, anddocs/*.md(technical reference, guides, and API references as applicable).
Inputs
/cli-command --mode=command --module=Acme_Orders --class=SyncOrdersCommand \
--name=acme:orders:sync --service=Acme\Orders\Service\OrderSyncer
/cli-command --mode=cron --module=Acme_Orders --class=SyncOrders \
--job=acme_orders_sync --schedule="*/15 * * * *" --service=Acme\Orders\Service\OrderSyncer
/cli-command --mode=command --module=Acme_Orders --class=SyncOrdersCommand \
--name=acme:orders:sync --service=Acme\Orders\Service\OrderSyncer --docs-root=<path>--docs-root=<path> — output-root override; see "Output root" below.
Outputs
{ctx.magento_root}/app/code/{Vendor}/{Module}/Console/Command/{CommandClass}.php # command mode
{ctx.magento_root}/app/code/{Vendor}/{Module}/etc/di.xml # command mode (merge)
{ctx.magento_root}/app/code/{Vendor}/{Module}/Test/Unit/Console/Command/{CommandClass}Test.php
{ctx.magento_root}/app/code/{Vendor}/{Module}/Cron/{CronJobName}.php # cron mode
{ctx.magento_root}/app/code/{Vendor}/{Module}/etc/crontab.xml # cron mode (merge)
{ctx.magento_root}/app/code/{Vendor}/{Module}/Test/Unit/Cron/{CronJobName}Test.php # cron mode
{output_root}/cli-commands/{Vendor}_{Module}-{mode}-{slug}-{date}.md{output_root} defaults to .docs ({ctx.docs_root}), anchored at the project root, never
under {ctx.magento_root}, app/code, or a module dir. See the Artifact location rule in
context/SKILL.md.
Output root (--docs-root)
This skill accepts --docs-root=<path> (see
context/references/artifact-layout.md). When set, write the run report (and any
report artifacts) under <path>/cli-commands/; otherwise default to
{ctx.docs_root}/cli-commands/. feature passes this so a feature
run's reports collect under its folder.
Reference Files
${CLAUDE_SKILL_DIR}/references/console-command-anatomy.md—configure(),execute(), return codes,CommandListDI registration.${CLAUDE_SKILL_DIR}/references/cron-anatomy.md—crontab.xmlgroups,<schedule>vs<config_path>, thedefaultgroup,cron:run.${CLAUDE_SKILL_DIR}/references/pitfalls.md— delegate-to-service, area-code, cron idempotency/overlap, locking, long-running progress.context/references/naming.md— naming conventions.context/references/tdd-discipline.md— shared test-first RED/GREEN loop.context/references/php-coding-style.md— PER-CS + Magento coding style.context/references/placeholder-schema.md— token registry.context/references/source-of-truth.md— source-of-truth hierarchy + the no-unrelated-module-scanning rule (allowed reads, live-doc fetch protocol, report affirmation).
Templates
templates/command-class.php→Console/Command/{CommandClass}.phptemplates/command-di.xml→etc/di.xml(merge)templates/cron-job-class.php→Cron/{CronJobName}.phptemplates/crontab.xml→etc/crontab.xml(merge)templates/test-command-unit.php→Test/Unit/Console/Command/{CommandClass}Test.phptemplates/test-cron-unit.php→Test/Unit/Cron/{CronJobName}Test.php
All templates follow the placeholder registry in
context/references/placeholder-schema.md. Every token used must be in the
Registry there — tests/test-placeholder-tokens.sh enforces it.
Acceptance Criteria
- All generated files pass
php -l/xmllint --noout. - Command name follows
{vendor_lower}:{module_lower}:{action}pattern. execute()returnsCli::RETURN_SUCCESSorCli::RETURN_FAILURE(never bare0/1).- No business logic in the command or cron class — delegated to the injected service.
- Command test:
CommandTesterasserts status code 0 and expected output; service mock usesexpects(self::once()). - Cron test: service mock uses
expects(self::once()); second invocation demonstrates class-level idempotency-safety; nomarkTestIncomplete, noself::assertTrue(true). review --diffreturns zero Critical/High findings.
Related Skills
| Phase | Skill |
| 0 | context |
| Before (if module absent) | module-create |
| Cron schedule from admin config | system-config |
| After | review --diff |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

