Compare environment configurations
✓Works with OpenClaudeYou are a DevOps debugging specialist. The user wants to compare two environment configurations to identify differences in variables, settings, and values.
What to check first
- Verify both environment files exist:
ls -la .env .env.production .env.staging(or equivalent paths) - Check file permissions:
cat .envshould be readable without errors - Confirm the format: are these shell exports, JSON, YAML, or dotenv format?
Steps
- Export both environments to temporary files:
env > /tmp/env.current.txtandcat .env.prod > /tmp/env.prod.txt - Strip comments and empty lines:
grep -v '^#' /tmp/env.current.txt | grep -v '^$' > /tmp/env.current.clean - Sort both files alphabetically for consistent comparison:
sort /tmp/env.current.clean > /tmp/env.current.sorted - Use
diff -u /tmp/env.current.sorted /tmp/env.prod.sortedto show unified diff with context - Filter for only variable name differences:
diff /tmp/env.current.sorted /tmp/env.prod.sorted | grep '^[<>]' | cut -d'=' -f1 - For sensitive values, mask secrets before comparing: replace values matching patterns like API keys or passwords
- Generate a structured report with
diff --suppress-common-linesto show only changed lines - Validate syntax of both configs before declaring diff complete
Code
const fs = require('fs');
const path = require('path');
function parseEnvFile(filePath) {
const content = fs.readFileSync(filePath, 'utf-8');
const env = {};
content.split('\n').forEach(line => {
line = line.trim();
if (!line || line.startsWith('#')) return;
const [key, ...valueParts] = line.split('=');
if (key) {
env[key.trim()] = valueParts.join('=').trim();
}
});
return env;
}
function maskSensitive(value) {
const sensitivePatterns = ['password', 'token', 'secret', 'key', 'api_key'];
if (sensitivePatterns.some(p => value.toLowerCase().includes(p))) {
return '***REDACTED***';
}
return value;
}
function compareEnvs(env1Path, env2Path) {
const env1 = parseEnvFile(env1Path);
const env2 = parseEnvFile(env2Path);
const allKeys = new Set([...Object.keys(env1), ...Object.keys(env2)]);
const differences = [];
allKeys.forEach(key => {
const val1 = env1[key];
const
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Debugging Skills
Other Claude Code skills in the same category — free to download.
Error Analyzer
Analyze error messages and suggest fixes
Stack Trace Decoder
Decode and explain stack traces
Memory Leak Finder
Find and fix memory leaks
Performance Profiler
Profile code and identify bottlenecks
Log Analyzer
Analyze log files and identify patterns
Network Debugger
Debug network/HTTP request issues
Race Condition Finder
Identify potential race conditions
Deadlock Detector
Find potential deadlocks in concurrent code
Want a Debugging skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.