AI on a Leash: Training Copilot for Hydrogen Best Practices

Introduction

GitHub Copilot accelerates Shopify Hydrogen development β€” but without constraints, it can generate unsafe, bloated, or edge-incompatible code.

The solution? Teach Copilot the rules of Hydrogen by embedding guardrails directly into your repo.

Why Guardrails for Copilot?

  • ⚠️ Unsafe patterns β†’ e.g., importing Node-only modules (fs, crypto) in Oxygen workers.
  • 🐘 Bundle bloat β†’ Copilot suggests entire SDKs (Firebase Admin, Stripe Node).
  • 🐌 Performance hits β†’ over-fetching APIs, ignoring caching.
  • ❌ Deploy failures β†’ Oxygen rejects oversized workers.

πŸ‘‰ Copilot is powerful β€” but it needs a leash.

Strategy: .copilot-instructions.md

Embed rules in a repo-level guide:

# Copilot Guardrails for Hydrogen - Do not fetch Admin API from Oxygen workers. - Always use `defer()` for non-critical data. - Keep PDP bundles <5MB compressed. - Limit subrequests to <40 per route. - Use `CacheShort` / `CacheLong` headers on all GraphQL queries.

πŸ‘‰ Copilot reads this context when suggesting code.

Crystal Seeds: Prompt Packs

Agencies can maintain reusable prompt packs (β€œCrystal Seeds”):

  • Performance seed β†’ reminds Copilot of budgets.
  • Security seed β†’ reminds Copilot of HMAC webhook verification.
  • SEO seed β†’ suggests <Seo> component boilerplate.

Stored in /docs/ai/ and reused across repos.

Training the Team

  • Junior devs onboard faster β†’ Copilot keeps them within safe lanes.
  • Senior devs spend less time correcting anti-patterns.
  • Guardrails scale across projects β†’ consistency by default.

Case Example: Agency Rollout

  • Before: juniors shipped 9MB bundles with Firebase Admin in workers.
  • After .copilot-instructions.md:
    • Bundles slimmed to <3MB.
    • Subrequests under 30.
    • No more deploy rejections.
  • Outcome: agency improved delivery times + client trust.

Guardrails Checklist

  • βœ… Create .copilot-instructions.md in root.
  • βœ… Add Crystal Seeds for performance, security, SEO.
  • βœ… Update with lessons from audits.
  • βœ… Train devs to read + extend seeds.

Conclusion

Copilot is a force multiplier, but Hydrogen requires precision. By teaching AI the rules of the framework, agencies can combine speed with safety, scaling Hydrogen builds without scaling mistakes.

Don’t just use Copilot. Train it.