From cf-saas-stack
Provides environment variable access patterns for Cloudflare Workers, including client creation in tRPC context and React Router loaders. Useful when adding new external services or debugging env binding issues.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cf-saas-stack:environment-variablesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
**NEVER use `process.env` to access environment variables.** This project runs on Cloudflare Workers where environment variables must be accessed through the Cloudflare `Env` bindings.
NEVER use process.env to access environment variables. This project runs on Cloudflare Workers where environment variables must be accessed through the Cloudflare Env bindings.
For external services (APIs, SDKs), create client instances in the tRPC context and pass them through:
// app/trpc/index.ts
export const createTRPCContext = async (opts) => {
const gemini = opts.cfContext.GEMINI_API_KEY
? createGeminiClient(opts.cfContext.GEMINI_API_KEY)
: null;
return { db, auth, gemini };
};
// In tRPC routes - use the client instance
export const myRouter = createTRPCRouter({
myProcedure: protectedProcedure.mutation(async ({ ctx }) => {
if (!ctx.gemini) {
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: "Gemini not configured" });
}
await ctx.gemini.generateContent(prompt);
}),
});
.env for local developmentbunx wrangler types to regenerate worker-configuration.d.tsapp/lib/ (e.g., createMyServiceClient)createTRPCContext and add to contextwrangler secret put VARIABLE_NAMEapp/trpc/index.ts)For use in tRPC routes via ctx.
workers/app.ts)For use in React Router loaders/actions via context.
ctx.)ctx.db - Drizzle database instancectx.auth - Better Auth session/userctx.gemini - Google Gemini AI client (nullable)context.)context.trpc - tRPC caller for server-side API callscontext.auth - Better Auth instancecontext.gemini - Google Gemini AI client (nullable)context.cloudflare.env - Raw env (avoid using directly)npx claudepluginhub casper-studios/casper-marketplace --plugin cf-saas-stackContext-based client pattern for passing external service clients through request context
Deploys MCP servers as Cloudflare Workers using createWorkerHandler from @cyanheads/mcp-ts-core/worker. Covers handler signature, binding types, runtime guards, and wrangler.toml.
Deploys MCP servers as Cloudflare Workers using createWorkerHandler. Covers handler signature, binding types, env extensibility, and wrangler.toml requirements.