Prompt Engineering for Magento 2 Devs Using Claude Code
Prompt engineering for Magento with Claude Code is mostly about three things: naming the files and the symptom, saying what done looks like, and giving Claude a check it can run. This page has a prompt builder and four worked examples, each with the prompt, why every line is there and what to check in the result.
- builder inputs
- 7
- worked examples
- 4
- no signup
- Free
Prompt engineering lab
Pick a goal, scope and constraints. The builder assembles a Claude Code prompt in the shape I use for Magento work. Treat it as a first draft: add the file names and the symptom, then read what Claude does with it.
Four prompts, line by line
Each example is a prompt for a real kind of Magento task, the reason for each part, and what you still have to check yourself. Module names are examples; swap in your own paths.
Fix a bug with a failing test first
Customers report that the delivery note they type at checkout is empty on the admin order view.
Look at app/code/Panth/DeliveryNote/Observer/SaveDeliveryNote.php and etc/events.xml.
First explain where the value is lost. Do not edit yet.
Then write a PHPUnit test in app/code/Panth/DeliveryNote/Test/Unit that fails because of this bug, fix the bug, and run:
vendor/bin/phpunit app/code/Panth/DeliveryNote/Test/Unit
Show me the command and its output. Do not touch vendor/.
Why each part is there
- Symptom and files Naming the file and the symptom gives Claude what it cannot find on its own, which is what the Claude Code best-practices page recommends.
- Explain before editing A short diagnosis first shows whether it understood the bug before it changes code.
- A check it can run The PHPUnit path is the definition of done. Claude can run it, read the failure and try again.
Check: the test failed before the fix and passes after it, and the diff stays inside the module.
Follow a pattern that already exists
@app/code/Panth/Loyalty/view/adminhtml/ui_component/panth_loyalty_rule_listing.xml is our existing rule grid.
Build the same kind of admin grid for the panth_loyalty_points table: listing XML, data provider, controller,
ACL resource Panth_Loyalty::points and a menu entry under the existing Loyalty menu.
Plan first: list every file you will create or change, then wait for my go.
No new libraries. After writing, run php -l on each new PHP file.
Why each part is there
- @ includes the file Typing @ and a path puts that file in the prompt, so Claude copies your structure instead of a generic one.
- Plan, then wait For a change across many files, a file list you approve is cheaper to fix than a finished diff.
- Limits stated once "No new libraries" and the ACL name are choices Claude cannot read from the code.
Check: the ACL resource exists in etc/acl.xml, the controller checks it, and the grid loads after setup:upgrade on your local copy.
Port a Luma template to Hyvä
Port app/design/frontend/Panth/default/Magento_Catalog/templates/product/view/stock-alert.phtml to Hyvä.
It uses a RequireJS widget through data-mage-init. Replace it with an Alpine.js x-data component and Tailwind classes.
Our theme is Hyvä 1.4, which uses Tailwind CSS v4. Read the theme's web/tailwind folder before choosing classes.
Keep the same block and data. Do not edit vendor/hyva-themes.
Then run npm run build in app/design/frontend/Panth/default/web/tailwind and tell me if it fails.
Why each part is there
- Version stated Hyvä 1.4 and later ship Tailwind v4; 1.2 and 1.3 ship v3. Saying which one avoids classes for the wrong version.
- Old and new pattern named "RequireJS widget to Alpine.js x-data" says exactly what changes and what stays.
- Build as the check npm run build fails on broken Tailwind input, so Claude sees the error itself.
Check: open the product page in a browser. A passing build does not prove the component behaves the same.
Review a branch without editing
Use a subagent to review git diff main...HEAD for Magento problems:
ObjectManager used outside Setup or Test code, raw SQL where db_schema.xml should be used,
new admin controllers without an ACL check, and unescaped output in .phtml files.
Report each finding as file:line and one sentence. Skip style. Do not edit any file.
Why each part is there
- A fresh context A subagent did not watch the code being written, so the reasoning that produced it does not sway the review.
- A fixed list Four named problems give a short, checkable report instead of a general opinion.
- Output format file:line per finding is easy to verify and paste into a pull request.
Check: open each file:line yourself. A review prompt finds candidates; it does not prove there are no other problems.
Keep going
10 anti-patterns to avoid
Shortcuts I catch in code review every week.
Open this topic-
Learning paths
Beginner to expert tracks with milestones. -
Your 30-day roadmap
30 days, one 45-minute task each. -
Glossary
20 concepts you pair with Claude on. -
Anatomy of a Magento module
Click any file to see what it does and why. -
12 weekly recipes
Real tasks with the code and the prompt. -
Slash-commands and hooks
8 commands and 5 hooks for .claude/. -
Pattern playground
Edit a pattern in the browser, copy it. -
bin/magento sandbox
Click a command, see simulated output. -
Live code reviewer
Paste code, get a Magento-aware review.
Common questions
Need the module shipped, not just learned?
I build Magento modules with Claude Code, tested and ready for review. Adobe Certified since 2021.