--- name: craft-query description: Codex skill alias for /craft-query. Build complex Craft CMS element queries --- # Codex Command Alias: /craft-query - This generated skill exposes the Claude slash command `/craft-query` to Codex. - Treat the user's message that invoked this skill as the command arguments. - When the embedded command body says `$ARGUMENTS`, substitute those user-supplied arguments. - Follow the embedded command body as the workflow source of truth. - Translate Claude-only tool names to Codex equivalents when needed: use `update_plan` for TodoWrite-style ledgers, `request_user_input` for AskUserQuestion-style gates when available, and normal chat questions when that tool is not available. - If the command body says to launch an agent and Codex exposes `multi_agent_v1.spawn_agent`, use that tool with a role-appropriate agent type and a self-contained prompt. - If the command body requires a nested `Skill(...)` call but Codex exposes no generic Skill tool, execute the referenced skill's documented protocol inline from its SKILL.md and clearly record the adapter mode. - If neither native tool invocation nor a documented Codex adapter can preserve the workflow's gates, stop and report the missing capability instead of manually approximating the workflow. ## Embedded Claude Command # Query Builder Help construct Craft CMS element queries for entries, assets, categories, users, and Matrix content. ## Process 1. **Understand the goal** -- What data does the user need? 2. **Choose the element type** -- Entries, assets, categories, users? 3. **Build the query** -- Add parameters step by step 4. **Optimize** -- Add eager loading, consider caching 5. **Test** -- Verify the query returns expected results ## Query Building Blocks ### Basic Structure ```twig {% set results = craft.entries() .section('blog') .orderBy('postDate DESC') .limit(10) .all() %} ``` ### Execution Methods - `.all()` -- Array of all results - `.one()` -- Single element or null - `.exists()` -- Boolean check - `.count()` -- Integer count - `.ids()` -- Array of IDs only ### Common Parameters - `.section()` / `.volume()` / `.group()` -- Filter by container - `.type()` -- Filter by entry type - `.status()` -- Include drafts, disabled, etc. - `.site()` -- Multi-site queries - `.relatedTo()` -- Relational queries - `.search()` -- Full-text search - `.orderBy()` -- Sort results - `.limit()` / `.offset()` -- Pagination ### Relational Queries ```twig {# Find entries related to a category #} {% set posts = craft.entries() .section('blog') .relatedTo(category) .all() %} {# Direction matters for some queries #} {% set products = craft.entries() .relatedTo({ targetElement: category, field: 'productCategories' }) .all() %} ``` ### Eager Loading ```twig {% set posts = craft.entries() .section('blog') .with([ 'featureImage', 'author', 'contentBlocks.image', ]) .all() %} ``` ## MCP Integration If the Craft MCP server is available: - `list_sections` -- See available sections - `list_fields` -- Understand field structure - `run_query` -- Test raw SQL queries - `explain_query` -- Analyze performance ## Output Provide working Twig code with explanations. Include performance considerations and alternatives where relevant.