Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Debuggingbeginner

Environment Diff

Share

Compare environment configurations

Works with OpenClaude

You 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 .env should be readable without errors
  • Confirm the format: are these shell exports, JSON, YAML, or dotenv format?

Steps

  1. Export both environments to temporary files: env > /tmp/env.current.txt and cat .env.prod > /tmp/env.prod.txt
  2. Strip comments and empty lines: grep -v '^#' /tmp/env.current.txt | grep -v '^$' > /tmp/env.current.clean
  3. Sort both files alphabetically for consistent comparison: sort /tmp/env.current.clean > /tmp/env.current.sorted
  4. Use diff -u /tmp/env.current.sorted /tmp/env.prod.sorted to show unified diff with context
  5. Filter for only variable name differences: diff /tmp/env.current.sorted /tmp/env.prod.sorted | grep '^[<>]' | cut -d'=' -f1
  6. For sensitive values, mask secrets before comparing: replace values matching patterns like API keys or passwords
  7. Generate a structured report with diff --suppress-common-lines to show only changed lines
  8. 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

Quick Info

CategoryDebugging
Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
debuggingenvironmentdiff

Install command:

curl -o ~/.claude/skills/environment-diff.md https://claude-skills-hub.vercel.app/skills/debugging/environment-diff.md

Related Debugging Skills

Other Claude Code skills in the same category — free to download.

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.