This pre-commit hook ensures that the .env.development.example file stays synchronized with .env.development by verifying that all variables defined in the example file are present in the development environment file.
-
Trigger: The hook runs automatically on commits that modify either
.env.developmentor.env.development.example. -
Validation: The script (scripts/check_env_vars.py) extracts all variable names from both files and compares them.
-
Results:
- ✅ Pass: If all variables from the example file are present in the development file
- ❌ Fail: If any variables are missing, with a helpful error message listing what needs to be added
The hook runs automatically when you commit changes to .env.development or .env.development.example:
git add .env.development.example
git commit -m "Add new environment variable"If validation fails, you'll see an error like:
❌ ERROR: Environment variable validation failed!
The following variables are defined in .env.development.example
but are missing from .env.development:
• NEW_VARIABLE_NAME
ACTION REQUIRED:
1. Review the new variables in .env.development.example
2. Add the missing variables to .env.development
3. Set appropriate values for your local environment
Run the validation script directly:
python3 scripts/check_env_vars.pyOr run just this specific pre-commit hook:
pre-commit run check-env-vars --all-files- Consistency: Ensures all developers have the same environment variables configured
- Documentation: Keeps the example file accurate as a reference for new team members
- Error Prevention: Catches missing environment variables before runtime errors occur
- Onboarding: New developers can easily see what environment variables need to be configured
When adding a new environment variable:
- Add it to
.env.development.examplewith a placeholder value - Add it to your local
.env.developmentwith your actual value - Commit
.env.development.example(but never commit.env.development) - The pre-commit hook will validate that both files are synchronized
# 1. Add to .env.development.example
echo "NEW_API_KEY=<your-api-key>" >> .env.development.example
# 2. Add to .env.development
echo "NEW_API_KEY=actual-secret-key-value" >> .env.development
# 3. Commit the example (the hook will validate before committing)
git add .env.development.example
git commit -m "Add NEW_API_KEY environment variable"The pre-commit hook is configured in .pre-commit-config.yaml:
- repo: local
hooks:
- id: check-env-vars
name: Verify .env.development variables
entry: python3 scripts/check_env_vars.py
language: system
pass_filenames: false
files: ^\.env\.development(\.example)?$
always_run: falseIf the hook doesn't run when expected:
# Reinstall pre-commit hooks
pre-commit install
# Test manually
pre-commit run check-env-vars --all-filesIf the script itself has issues:
# Run the script directly to see detailed errors
python3 scripts/check_env_vars.py
# Check that both files exist
ls -la .env.development .env.development.exampleIf you see variables reported as missing but they exist:
- Ensure the variable name in
.env.developmentexactly matches.env.development.example - Check for typos or extra spaces
- Variable names must start with a letter or underscore and contain only letters, numbers, and underscores
- Variable assignments must use the format:
VARIABLE_NAME=value
- scripts/README.md - Overview of all pre-commit hooks
- SECURITY_INCIDENT.md - Security incident response procedures
- Pre-commit Framework - Official pre-commit documentation