Add Setting Env
Add server-side environment variables that control default values for user settings.
mkdir -p ~/.claude/skills/add-setting-env && curl -fsSL 'https://raw.githubusercontent.com/lobehub/lobehub/canary/.agents/skills/add-setting-env/SKILL.md' -o ~/.claude/skills/add-setting-env/SKILL.md
Get the complete skill folder, including its scripts and reference files.
When to use this skill
Use Add Setting Env when an AI agent needs a reusable SKILL.md workflow for this job: Add server-side environment variables that control default values for user settings.
When not to use it
Skip Add Setting Env when the task is outside the creativity category, or when a more specific skill in this directory already covers the same workflow with clearer triggers.
How to install
Where will you use it?
mkdir -p ~/.claude/skills/add-setting-env && curl -fsSL 'https://raw.githubusercontent.com/lobehub/lobehub/canary/.agents/skills/add-setting-env/SKILL.md' -o ~/.claude/skills/add-setting-env/SKILL.md
- Claude Code personal install: place the skill and its bundled files at ~/.claude/skills/add-setting-env/SKILL.md. For a shared project, commit the folder at .claude/skills/add-setting-env/ instead.
- Current Claude Code detects SKILL.md changes in watched directories during the session. If you just created a top-level skills directory, run /reload-skills. Check that the skill is listed before testing its trigger.
- For Claude chat or Cowork in the Desktop app, manage uploaded skills in Customize > Skills; copying files into a local Claude Code folder is not a Desktop install. Other agents may use different install locations.
Full install guide for Claude, Cursor, and Codex →
Try a starter prompt
After installing the skill, paste this starter prompt into your agent to verify it triggers on a small task.
Use the Add Setting Env skill for this task: Use Add Setting Env when this documented workflow matches the task. Confirm any required inputs or files before making changes.
What supports this recommendation?
67/100 provisional content score. This measures documentation, practical detail and source signals. It is not a measured task success rate or a security certification.
- Documentation
- 68/100
- Practical detail
- 68/100
- Source evidence
- 63/100
- Source signals
- 70/100
Model compatibility evidence
- claudeuntested
No model-specific signal or recorded compatibility test was found.
- chatgptuntested
No model-specific signal or recorded compatibility test was found.
- geminiuntested
No model-specific signal or recorded compatibility test was found.
- copilotuntested
No model-specific signal or recorded compatibility test was found.
- llamauntested
No model-specific signal or recorded compatibility test was found.
- perplexityuntested
No model-specific signal or recorded compatibility test was found.
- mistraluntested
No model-specific signal or recorded compatibility test was found.
- grokuntested
No model-specific signal or recorded compatibility test was found.
Inferred compatibility is based on content signals. Check the app, its available tools and setup requirements before running a skill.
What this skill does
# Adding Environment Variable for User Settings
Add server-side environment variables to configure default values for user settings.
**Priority**: User Custom > Server Env Var > Hardcoded Default
## Steps
### 1. Define Environment Variable
Create `packages/env/src/<domain>.ts` (import path stays `@/envs/<domain>` — tsconfig maps to `packages/env/src/*` first):
```typescript import { createEnv } from '@t3-oss/env-core'; import { z } from 'zod';
export const get<Domain>Config = () => { return createEnv({ server: { YOUR_ENV_VAR: z.coerce.number().min(MIN).max(MAX).optional(), }, runtimeEnv: { YOUR_ENV_VAR: process.env.YOUR_ENV_VAR, }, }); };
export const <domain>Env = get<Domain>Config(); ```
### 2. Update Type (if new domain)
Add to `packages/types/src/serverConfig.ts`:
```typescript import { User<Domain>Config } from './user/settings';
export interface GlobalServerConfig { <domain>?: PartialDeep<User<Domain>Config>; } ```
**Prefer reusing existing types** from `packages/types/src/user/settings`.
### 3. Assemble Server Config (if new domain)
In `apps/server/src/globalConfig/index.ts`:
```typescript import { <domain>Env } from '@/envs/<domain>';
export const getServerGlobalConfig = async () => { const config: GlobalServerConfig = { <domain>: cleanObject({ <settingName>: <domain>Env.YOUR_ENV_VAR, }), }; return config; }; ```
### 4. Merge to User Store (if new domain)
In `src/store/user/slices/common/action.ts`:
```typescript const serverSettings: PartialDeep<UserSettings> = { <domain>: serverConfig.<domain>, }; ```
### 5. Update .env.example
```bash # <Description> (range/options, default: X) # YOUR_ENV_VAR=<example> ```
### 6. Update Documentation
- `docs/self-hosting/environment-variables/basic.mdx` (EN) - `docs/self-hosting/environment-variables/basic.zh-CN.mdx` (CN)
## Example: AI\_IMAGE\_DEFAULT\_IMAGE\_NUM
```typescript // packages/env/src/image.ts (import as @/envs/image) AI_IMAGE_DEFAULT_IMAGE_NUM: z.coerce.number().min(1).max(20).optional(),
// packages/types/src/serverConfig.ts image?: PartialDeep<UserImageConfig>;
// apps/server/src/globalConfig/index.ts image: cleanObject({ defaultImageNum: imageEnv.AI_IMAGE_DEFAULT_IMAGE_NUM }),
// src/store/user/slices/common/action.ts image: serverConfig.image,
// .env.example # AI_IMAGE_DEFAULT_IMAGE_NUM=4 ```
Intended uses
- Use Add Setting Env when this documented workflow matches the task.
Implementation notes
- Review the source instructions and adapt inputs before running the workflow.
Try it, then tell us how it went
A copied prompt does not tell us whether the task worked. Report your result after checking the output. We collect your tool and outcome, never your files or prompt.