Add and manage application secrets and environment variables. Use when adding API keys, credentials, or updating env.ts.
From schema0-devnpx claudepluginhub schema0/ai-agent-plugins --plugin schema0-devThis skill is limited to using the following tools:
Prerequisite: This skill requires a schema0 template project. Before using, ensure
CLAUDE.mdexists in the project root and read it for project rules and conventions.
Process for adding and managing secure environment variables and integrating external services (AI providers, payment processors, email services, etc.).
When you need to add a new secret (like an API key for a third-party service):
Add the secret using the MCP tool:
.env or deployment secrets).Update Type Definitions in packages/auth/env.ts:
packages/auth/env.ts to include the new variable in the server schema.z.string().optional() for keys that might not be present in all environments.// packages/auth/env.ts
export const env = createEnv({
server: {
// ... existing vars
NEW_SECRET_KEY: z.string().optional(),
},
// ...
});
Install Dependencies:
bun add <package-name>
Create Service Client (Optional):
For complex services, create a client in packages/api/src/lib/:
// packages/api/src/lib/my-service.ts
import { env } from "@template/auth";
export const myServiceClient = new MyService({
apiKey: env.NEW_SECRET_KEY,
});
Usage in Router:
Access the secret in your code via env.NEW_SECRET_KEY (import from @template/auth).
import { env } from "@template/auth";
export const myRouter = {
action: protectedProcedure.handler(async () => {
// Use env.NEW_SECRET_KEY directly
const result = await myServiceCall(env.NEW_SECRET_KEY);
return result;
}),
};
Add secret OPENAI_API_KEY using MCP tool.
Update packages/auth/env.ts:
OPENAI_API_KEY: z.string().optional(),
Install dependencies:
bun add ai @ai-sdk/openai
Use in router:
import { openai } from "@ai-sdk/openai";
import { streamText } from "ai";
import { env } from "@template/auth";
// ... inside handler
const result = streamText({
model: openai({ apiKey: env.OPENAI_API_KEY })("gpt-4o-mini"),
// ...
});
Add secrets STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET.
Update packages/auth/env.ts.
Install stripe.
Create client packages/api/src/lib/stripe.ts:
import Stripe from "stripe";
import { env } from "@template/auth";
export const stripe = new Stripe(env.STRIPE_SECRET_KEY);
RESEND_API_KEY.packages/auth/env.ts.resend.packages/api/src/lib/resend.ts.Secrets are injected at deploy time (not build time) and must never be committed to git. All secret operations are managed through the schema0 CLI:
schema0 secrets set SECRET_NAME=value
schema0 secrets set --env-file .env.production
schema0 secrets list
schema0 secrets delete SECRET_NAME
The env object is fully typed. Accessing a non-existent key will cause a TypeScript error.