Introduction
Environment variables connect your Hydrogen storefront to Shopify, Weaverse Studio, and any third-party services your theme uses. The Weaverse CLI and AI-agent setup generate most local values for you, but it is still useful to know which variables matter and where they come from.Essential Environment Variables
Shopify and Hydrogen Variables
SESSION_SECRET: A random secret used to sign session cookies. The Weaverse CLI/agent setup generates this automatically; if you configure a project manually, generate a random value instead of choosing a memorable one.PUBLIC_STORE_DOMAIN: Your Shopify store domain, such asyour-store.myshopify.com.PUBLIC_STOREFRONT_API_TOKEN: Public Storefront API access token used by client-side Storefront API calls. This is not required for themock.shopdemo setup.PRIVATE_STOREFRONT_API_TOKEN: Private Storefront API access token used for server-side Storefront API calls. Keep this value secret.PUBLIC_STOREFRONT_ID: The numeric Hydrogen storefront ID.PUBLIC_CHECKOUT_DOMAIN: Checkout domain, often your original Shopify Online Store domain. Some themes fall back toPUBLIC_STORE_DOMAIN.PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID: Customer Account API client ID.PUBLIC_CUSTOMER_ACCOUNT_API_URL: Customer Account API URL, usually in the formathttps://shopify.com/{SHOP_ID}.SHOP_ID: Shopify store ID. Some Hydrogen features and theme code use this alongside Customer Account API values.
Weaverse Variables
WEAVERSE_PROJECT_ID: Unique ID for your Weaverse project. Find it in Weaverse Studio under Project Settings.WEAVERSE_API_KEY: Optional API key from your Weaverse account or project settings. Only include it when your theme or automation needs direct API access.WEAVERSE_HOST: Optional Weaverse service host. Default:https://studio.weaverse.io.
Optional Theme Variables
PUBLIC_STOREFRONT_API_VERSION: Storefront API version. If omitted, Hydrogen uses its configured default.PUBLIC_GOOGLE_GTM_ID: Google Tag Manager ID for analytics.JUDGEME_PRIVATE_API_TOKEN: API token for Judge.me reviews integration.KLAVIYO_PRIVATE_API_TOKEN: API token for Klaviyo integration.PUBLIC_SHOPIFY_INBOX_SHOP_ID: Shopify Inbox shop ID for chat functionality.
Custom Metafields and Metaobjects
METAOBJECT_COLORS_TYPE: Type identifier for color metaobjects.CUSTOM_COLLECTION_BANNER_METAFIELD: Metafield identifier for collection banners.
Variables with
PUBLIC_ can be exposed to browser code. Do not put secrets in PUBLIC_ variables. Keep private API tokens in server-only variables such as PRIVATE_STOREFRONT_API_TOKEN.Setting Up Environment Variables
Using Demo Setup (with mock.shop)
SESSION_SECRET with either command:
Production Setup
TypeScript Support
For TypeScript support, add your environment variables toenv.d.ts:
Best Practices
-
Security:
- Never commit
.envfiles to version control - Use
.env.examplefor required variables - Keep sensitive tokens private
- Rotate tokens regularly
- Never commit
-
Organization:
- Group related variables together
- Use clear, descriptive names
- Document all variables in your project
- Keep development and production variables separate
-
Development:
- Use different values for development and production
- Validate environment variables at startup
- Provide fallback values where appropriate
- Use TypeScript for type safety
Obtaining Required Tokens
Recommended: Hydrogen Sales Channel
For stores on a Shopify plan, use Shopify’s Hydrogen sales channel:- Install the Hydrogen sales channel.
- Create one Hydrogen storefront project for your store.
-
From your local storefront folder, run:
- Choose the store, storefront, and environment when prompted.
.env file. If the CLI cannot pull values yet, copy them manually from Hydrogen sales channel → Storefront settings → Environments and variables.
Alternative: Headless Sales Channel
For development stores, stores without a Shopify plan, or custom Storefront API setups:- Install the Headless sales channel.
- Create or open a storefront in the Headless channel.
- Copy the Storefront API values into
.env. - Request the Storefront API permissions your theme needs.
Weaverse Project ID
- Log in to Weaverse Studio
- Open your project and go to Project Settings
- Copy your Project ID