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

craftcms

Skill90 starsChanged 4 months agoMITView on GitHub

Craft CMS 5 plugin and module development in PHP. Covers elements, element queries, services, models, records, controllers, migrations, queue jobs, console commands, field types, events, Twig extensions, widgets, permissions, GraphQL, testing, and debugging.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

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

    Always addSelect() in beforePrepare(): the Craft convention, additive when several extensions contribute columns.

    line 26
  2. Very specific:

    Never put id in getConfig(): project config uses UIDs.

    line 28
  3. Very specific:

    Never hardcode /admin: cpTrigger is configurable.

    line 31
  4. Very specific:

    Read only what the task needs.

    line 40

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

Craft Version of This Project

!sh ${CLAUDE_SKILL_DIR}/scripts/craft-version.sh

If no Craft version line appears above, establish the version before any version-specific advice: craftcms/cms in composer.lock for a site, the lowest version the craftcms/cms constraint in composer.json allows for a plugin, or ask. Then check it against the version tags in this skill ([5.10+], [changed 5.12], [seomatic 5.1+]).

Extending Craft CMS 5 with PHP: plugins, modules, custom element and field types, backend integrations. Site work (content modeling, Twig, plugin selection) belongs to craft-site and craft-content-modeling.

Companion Skills

Always load craft-php-guidelines (PHP standards, required for any PHP) and ddev (every command runs through DDEV). Also load: craft-garnish for CP JavaScript, craft-pest for tests (its rollback is opt-in and its env overrides are cwd-bound: both write silently to the dev database), craft-cloud when craft-cloud.yaml or craftcms/cloud is present, craft-mcp for MCP servers, OAuth and personal access tokens [5.12+], craft-plugins for plugin-specific work. Full notes: task-routing.md (Companion skills).

Docs: https://craftcms.com/docs/5.x/extend/ · class reference https://docs.craftcms.com/api/v5/ · generator https://craftcms.com/docs/5.x/extend/generator.html. Use WebFetch when a reference doesn't cover enough.

Common Pitfalls (Cross-Cutting)

  • Always addSelect() in beforePrepare(): the Craft convention, additive when several extensions contribute columns.
  • Queue workers run in primary site context: use ->site('*') for cross-site queries (queue-jobs.md).
  • Never put id in getConfig(): project config uses UIDs.
  • Logic belongs in services, not models or controllers. DateTimeHelper in elements/queries, Carbon in services, never mixed in one class.
  • Modules register template roots, translations and controllerNamespace manually (plugin-vs-module.md).
  • Never hardcode /admin: cpTrigger is configurable. UrlHelper::cpUrl() in PHP, cpUrl() in Twig.
  • Split settings pages: load the full settings model, update it, then savePluginSettings(); passing getBodyParams() straight in drops unsubmitted keys (cp.md).
  • A route or query param named token collides with Craft's tokenParam: 400 before your controller runs (controllers.md, Reserved request params).
  • EVENT_DEFINE_RULES on Entry::class runs for every entry, including nested entries built before fieldId/ownerId exist, where getType() throws Either \sectionId` or `fieldId` + `ownerId` must be set on the entry.Always add the rule, decide in'when'behind anisset($entry->fieldId) || isset($entry->sectionId)guard, validate with aValidator subclass (events.md`, Validation Rules on Core Elements From a Module).
  • project-config/write empties config/project/ and rewrites it from the DB. On a stale local DB it deletes teammates' YAML. Run craft up first, require a clean project-config/diff, and check git diff -- config/project afterwards. Schema saves from PHP belong in a migration or console command, never a bare bootstrap script (YAML is only flushed on EVENT_AFTER_REQUEST). See deployment.md (project-config/write safely) and migrations.md (Project config writes outside a request).
  • Any non-underscore-prefixed template in a plugin's templates/ is directly routable in the CP, bypassing beforeAction() gates. Underscore-prefix the rest (cp.md, CP template routing bypasses controllers).

Reference Files

Read only what the task needs; multiple files often apply. The full task index (130+ task-to-section mappings) is task-routing.md: grep it for a keyword from the task.

Task examples:

  • "Build a custom element type" → elements.md (Architecture first) + element-index.md + fields.md + migrations.md + cp.md
  • "Add a webhook endpoint" → controllers.md + events.md
  • "Queue job that syncs elements" → queue-jobs.md + elements.md + debugging.md
  • "Require a field on one entry type / nested entry fails: Either sectionId or fieldId + ownerId must be set" → events.md (Validation Rules on Core Elements From a Module)
  • "project-config/write deleted YAML" → deployment.md; "saveField()/saveEntryType() from a script changed nothing in YAML" → migrations.md (Project config writes outside a request)
  • "Create or delete sites from code / siteId filter lost after creating a site / phantom sites after deleteSite" → architecture.md (Creating or deleting sites at runtime)
  • "'Changed since' filter off by hours" → architecture.md (Those strings are naive UTC); "['like', ...] returns nothing" → architecture.md (Element-query param setters don't take Yii operator tuples)
  • "Edit-screen sidebar panel / toolbar split button / metaFieldsHtml" → cp-ui-patterns.md (Element Edit Screen) + elements.md
  • "Plugin settings page, tabs, config-file override warning" → cp.md (Settings Pages)
  • "Install fails: too many keys" → migrations.md; "Upgrade to 5.12" [5.12+] → upgrade-5.12.md
  • Tests → load craft-pest; Cloud compatibility → load craft-cloud (plugin-development.md); headless front ends → craft-site (headless.md)
  • "Which Craft version does this feature need? / What can this project use on its version?" → grep version-table.md for the feature or version (every version tag in the pack, with older-version alternatives); it is large, so don't read it whole

Large files: read the Contents block, then only the section. architecture.md, config-app.md, config-general.md, controllers.md, cp.md, cp-ui-patterns.md, element-index.md, elements.md, events.md, graphql.md and permissions.md start with a Contents block that gives each section's line range. Read the first 40 lines, then Read only the section you need with offset/limit, never the whole file.

TaskRead~Tokens
Full task index: task or symptom → file and section; full pitfall and companion notesreferences/task-routing.md4.9K
Elements: lifecycle, queries, status, authorization, drafts, propagation, field layouts, user edit screens, eventsreferences/elements.md8.4K
Element index: sources, table/card attributes, status pills, sort, conditions, actions, exporters, relation-field displayreferences/element-index.md6.1K
Services, models, records, project config, runtime site creation/deletion, MemoizableArray, API clients, validatorsreferences/architecture.md7.4K
Plugin vs module differences, module template-root/translation/console registrationreferences/plugin-vs-module.md0.6K
Controllers: CP CRUD, webhooks, API endpoints, action routing, authorizationreferences/controllers.md3.9K
CP templates, form macros, settings pages, navigation, permissions, read-only modereferences/cp.md7.2K
CP components: widgets, utility pages, slideouts, ajax, editable tables, modals, alertsreferences/cp-components.md1.8K
CP UI patterns: tri-state controls, status indicators, CSS tokens, condition builders, asset bundles, edit-screen sidebar/toolbarreferences/cp-ui-patterns.md3.4K
Migrations, Install.php, foreign keys, indexes, idempotencyreferences/migrations.md3.9K
Queue jobs: BaseJob, TTR, retry, progress, batch jobs, site contextreferences/queue-jobs.md4.2K
Console commands, options, progress, output helpers, resave actionsreferences/console-commands.md6.0K
Debugging, performance, profiling, Xdebug, loggingreferences/debugging.md4.6K
PHPStan, ECS, Rector, CI, review checklistreferences/quality.md3.5K
Testing: pointer to craft-pest + Codeception basicsreferences/testing.md0.6K
Field types, native fields, field layout UI elements, FieldLayoutBehaviorreferences/fields.md3.6K
Events: registration, EVENT_DEFINE_RULES, custom events, behaviors, Twig extensions, utilities, widgets, filesystemsreferences/events.md4.4K
GraphQL: auth, tokens, types, queries, mutations, directives, resolversreferences/graphql.md8.4K
Plugin Vite: CP asset bundles, HMR, TypeScript, Vuereferences/plugin-vite.md2.7K
Headless & hybrid: headlessMode, CORS, preview tokenscraft-site skill references/headless.md3.4K
GeneralConfig (system, routing, security, users, sessions, search, assets, images)references/config-general.md8.4K
Craft version table, generated from the pack's version tagsreferences/version-table.md13.3K
GeneralConfig (content, templates, performance, GC, localization, headless, GraphQL)references/config-general-extended.md7.2K
App config: cache, session, queue, mutex (Redis, one database each), mailer, search, logging, CORS, DB replicas, modulesreferences/config-app.md8.0K
Config bootstrap: env vars, aliases, App::parseEnv, custom.php, db.php, routes.phpreferences/config-bootstrap.md3.6K
Caching: template cache, data cache, static caching, CDN, invalidationreferences/caching.md5.2K
Permissions: handles, user groups, registration, checking, eventsreferences/permissions.md4.7K
Element authorization: four-layer defense, can*() methods, query scopingreferences/element-authorization.md4.6K
Sessions & auth: session model, auth tokens, invalidation, elevated sessionsreferences/sessions-and-auth.md3.0K
Identity protocols: SSO/OIDC logout, signing algs, issuer vs tenancy, SCIMreferences/identity-protocols.md1.3K
Custom field types: value lifecycle, settings, input HTML, validation, GraphQLreferences/field-types-custom.md3.5K
Conditions framework: custom condition rules, registrationreferences/conditions.md2.3K
Email: system messages, programmatic sending, templates, eventsreferences/email.md2.4K
Deployment: pipeline, project-config/write safely, zero-downtime, CI/CD, rollbackreferences/deployment.md2.5K
Drafts & revisions: provisional drafts, autosave, applying, mergereferences/drafts-revisions.md2.5K
Upgrading 5.11 to 5.12.4 [5.12+]: behaviour changes, plugin-code changes, deploy stepsreferences/upgrade-5.12.md2.1K

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.