agentleFS
chrisrowechrisrowe/craftcms-claude-skills/skills/craftcms/SKILL.md

craftcms

Skill2 starsChanged 8 months agoMITView on GitHub

Craft CMS 5 plugin and module development — extending Craft. Covers the full extend surface: elements, element queries, services, models, records, project config, controllers, CP templates, migrations, queue jobs, console commands, field types, native fields, events, behaviors, Twig extensions, utilities, widgets, filesystems, debugging, testing, and GraphQL. Triggers on: beforePrepare(), afterSave(), defineSources(), defineTableAttributes(), attributeHtml(), MemoizableArray, getConfig(), handleChanged, $allowAnonymous, $enableCsrfValidation, BaseNativeField, EVENT_DEFINE_NATIVE_FIELDS, FieldLayoutBehavior, EVENT_REGISTER, EVENT_DEFINE, EVENT_BEFORE, EVENT_AFTER, CraftVariable, registerTwigExtension, DefineConsoleActionsEvent, PHPStan, Pest. Always use when writing, editing, or reviewing any Craft CMS plugin or module code.

1 other project uses a version of this, 1 of them edited.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 1

    1. michtio/craftcms-claude-skills★ 8211% same

    Wrote their own version · 0

    None found.

    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 repository7 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use web_fetch on specific doc pages when a reference file doesn't cover enough detail.

    line 20
  2. Very specific:

    Always use addSelect() in beforePrepare() — it's the Craft convention and safely additive when multiple extensions contribute columns.

    line 24
  3. Distinctive:

    Read the relevant reference file(s) for your task.

    line 33

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Craft CMS 5 — Extending (Plugins & Modules)

Reference for extending Craft CMS 5 through plugins and modules. Covers everything from elements and services to controllers, migrations, fields, and events.

This skill is scoped to extending Craft — building plugins, modules, custom element types, field types, and backend integrations. For site/platform development (content modeling, sections, entry types, Twig templating, plugin selection), see the craft-site skill.

For PHP coding standards and conventions, see the separate craft-php-guidelines skill.

Documentation

Use web_fetch on specific doc pages when a reference file doesn't cover enough detail.

Common Pitfalls (Cross-Cutting)

  • Always use addSelect() in beforePrepare() — it's the Craft convention and safely additive when multiple extensions contribute columns.
  • Queue workers run in primary site context — use ->site('*') for cross-site queries.
  • Including id in getConfig() — project config uses UIDs, never database IDs.
  • Business logic in models or controllers — services are where logic belongs.
  • Modules need manual template root, translation, and controllerNamespace registration — nothing is automatic.
  • DateTimeHelper in elements/queries, Carbon in services — never mix in the same class.

Reference Files

Read the relevant reference file(s) for your task. Multiple files often apply together.

Task examples:

  • "Build a custom element type" → read elements.md + element-index.md + fields.md + migrations.md
  • "Add a webhook endpoint" → read controllers.md + events.md
  • "Create a queue job that syncs elements" → read queue-jobs.md + elements.md + debugging.md
  • "Add a settings page with form fields" → read controllers.md + cp.md + architecture.md
  • "Register a custom field type" → read fields.md + events.md
  • "Fix PHPStan errors" → read quality.md
  • "Add a dashboard widget" → read events.md (Widget Types section)
  • "Expose template variables for plugin users" → read events.md (Twig Extensions section)
  • "Attach custom methods to entries" → read events.md (Behaviors section)
  • "Build a CP utility page" → read events.md (Utilities section) + cp.md
TaskRead
Element core: lifecycle, queries, status, authorization, drafts, revisions, propagation, field layouts, eventsreferences/elements.md
Element index: sources, table/card attributes, sort, conditions, actions, exporters, sidebar, metadatareferences/element-index.md
Services, models, records, project config, MemoizableArray, events, API clients, custom validatorsreferences/architecture.md
Controllers: CP CRUD, webhooks, API endpoints, action routing, authorizationreferences/controllers.md
CP templates, form macros, admin changes, VueAdminTable, asset bundles, CP layout, permissionsreferences/cp.md
Database migrations, Install.php, foreign keys, indexes, idempotency, deploymentreferences/migrations.md
Queue jobs, BaseJob, TTR, retry, progress, batch jobs, site contextreferences/queue-jobs.md
Console commands, arguments, options, progress bars, output helpers, resave actionsreferences/console-commands.md
Debugging, performance, query strategy, profiling, Xdebug, caching, loggingreferences/debugging.md
PHPStan, Pest testing, code review checklistreferences/quality.md
Field types, native fields, BaseNativeField, field layout elements, FieldLayoutBehaviorreferences/fields.md
Events: registration, lifecycle, naming conventions, custom events, behaviors, Twig extensions, utilities, widgets, filesystems, discovering eventsreferences/events.md
GraphQL types, queries, mutations, directives, schema components, resolversreferences/graphql.md

Plugin vs Module Differences

Plugins and modules share the same architecture patterns. The differences are in bootstrapping and registration:

FeaturePluginModule
CP template rootAutomatic (by handle)Manual via EVENT_REGISTER_CP_TEMPLATE_ROOTS
Site template rootManual via eventSame — manual for both
Translation categoryAutomatic (by handle)Manual PhpMessageSource in init()
Settings modelBuilt-in createSettingsModel()Env vars, config files, or private plugin (_ prefix)
Install migrationmigrations/Install.phpContent migrations only
Console commandsAutomatic controllerNamespaceMust set before parent::init(), must be bootstrapped
CP nav section$hasCpSection = trueEVENT_REGISTER_CP_NAV_ITEMS
Project configSettings auto-trackedManual ProjectConfig::set() only
Namespace aliasAutomatic via ComposerMust call Craft::setAlias()

Module Template Root Registration

use craft\events\RegisterTemplateRootsEvent;
use craft\web\View;

Event::on(View::class, View::EVENT_REGISTER_CP_TEMPLATE_ROOTS,
    function(RegisterTemplateRootsEvent $event) {
        $event->roots['my-module'] = __DIR__ . '/templates';
    }
);

Module Translation Registration

Craft::$app->i18n->translations['my-module'] = [
    'class' => \craft\i18n\PhpMessageSource::class,
    'sourceLanguage' => 'en',
    'basePath' => __DIR__ . '/translations',
    'allowOverrides' => true,
];

Module Console Command Registration

public function init()
{
    Craft::setAlias('@mymodule', __DIR__);

    if (Craft::$app->getRequest()->getIsConsoleRequest()) {
        $this->controllerNamespace = 'modules\\mymodule\\console\\controllers';
    } else {
        $this->controllerNamespace = 'modules\\mymodule\\controllers';
    }

    parent::init(); // MUST come after setting controllerNamespace
}

The module must be bootstrapped in config/app.php for console commands to be discoverable.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.