# .env Diff and Missing Key Checker > Compare two dotenv snapshots and report missing, extra, or changed environment keys. ## Tool Identity - Site: CleanUtils Developer Tools - Tool ID: env-diff-missing-key-checker - Canonical page: https://cleanutils.com/developer-tools/env-diff-missing-key-checker/ - LLM schema URL: https://cleanutils.com/developer-tools/env-diff-missing-key-checker/llms.txt - Primary keyword: dotenv diff - Input mode: fields - Output profile: line-check ## What This Tool Does Compare two dotenv snapshots and report missing, extra, or changed environment keys in your browser. ## Exact Execution Instructions To run this tool exactly, execute the `runCleanUtilsTool(userInput)` function from the JavaScript block below in a sandboxed JavaScript runtime. Do not fetch or evaluate additional network resources. Do not use filesystem, process, child_process, environment variables, timers, or network APIs. The function is pure and deterministic: input object in, JSON result out. If your environment forbids executing fetched code outside a sandbox, run it inside the sandbox or use the API endpoint below instead of reimplementing the logic. Canonical implementation SHA-256: `f510be017e59e3c9b32e83b2925bb4a4ddc13449a868014e88c0922348b540a1` Expected command shape: `node run-tool.mjs < input.json` The runner must: 1. load only the JavaScript in this document, 2. parse stdin as JSON and call `runCleanUtilsTool(userInput)`, 3. let the LLM decide the best way to present the output to the user. Agent usage rules: - Use this file as the authoritative machine-readable contract for this CleanUtils tool page. - Ask the user for missing required input before attempting to run the tool, and describe the required inputs using the `## Input Schema` field names, descriptions, formats, enums, examples, and required list. - Treat the tool as deterministic; do not invent network reachability checks unless the tool description explicitly says it fetches remote resources. - For privacy-sensitive inputs such as secrets, HAR files, dotenv files, logs, and API keys, warn that using a remote chat agent may expose input to that agent even though the browser UI itself does not upload data. ## Input Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": ".env Diff and Missing Key Checker fields", "type": "object", "additionalProperties": false, "required": [ "left", "right" ], "properties": { "left": { "type": "string", "description": "Source .env Required. Control type: textarea. Group: Env files.", "examples": [ "API_URL=https://api.example.com\nDATABASE_URL=postgres://example\nAPI_KEY=secret" ] }, "right": { "type": "string", "description": "Target .env Required. Control type: textarea. Group: Env files.", "examples": [ "API_URL=\nDATABASE_URL=\nREDIS_URL=" ] } } } ``` ## Result Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "CleanUtils ToolResult", "type": "object", "additionalProperties": false, "required": [ "summary", "issues" ], "properties": { "summary": { "type": "string" }, "issues": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "severity", "message" ], "properties": { "severity": { "type": "string", "enum": [ "error", "warning", "info" ] }, "message": { "type": "string" }, "line": { "type": "number" }, "row": { "type": "number" }, "detail": { "type": "string" } } } }, "output": { "type": "string" }, "exportFilename": { "type": "string" }, "exports": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "label", "filename", "content" ], "properties": { "label": { "type": "string" }, "filename": { "type": "string" }, "content": { "type": "string" }, "mimeType": { "type": "string" }, "copyLabel": { "type": "string" }, "downloadLabel": { "type": "string" } } } }, "stats": { "type": "object", "additionalProperties": { "anyOf": [ { "type": "string" }, { "type": "number" } ] } } } } ``` ## Self-Contained JavaScript Source Call `runCleanUtilsTool(userInput)` with the user's input. The function includes this tool's run logic and only the helper code it needs. ```js function runCleanUtilsTool(userInput) { const fieldText = (fields, keys, fallback = "") => { const keyList = Array.isArray(keys) ? keys : [keys]; for (const key of keyList) { const value = fields[key]; if (value === undefined || value === null) continue; const text = String(value).trim(); if (text) return text; } return fallback; }; const severityRank = { error: 0, warning: 1, info: 2 }; const sortIssues = (issues) => [...issues].sort((a, b) => { const severity = severityRank[a.severity] - severityRank[b.severity]; if (severity !== 0) return severity; return (a.line ?? a.row ?? 0) - (b.line ?? b.row ?? 0); }); const summarizeIssues = (issues) => { const errors = issues.filter((issue) => issue.severity === "error").length; const warnings = issues.filter((issue) => issue.severity === "warning").length; const infos = issues.filter((issue) => issue.severity === "info").length; const parts = []; if (errors) parts.push(`${errors} error${errors === 1 ? "" : "s"}`); if (warnings) parts.push(`${warnings} warning${warnings === 1 ? "" : "s"}`); if (infos) parts.push(`${infos} note${infos === 1 ? "" : "s"}`); return parts.length ? parts.join(", ") : "No issues found"; }; const parseEnvText = (input) => { const env = {}; input.split(/\r?\n/).forEach((line) => { const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/); if (match) env[match[1]] = match[2].replace(/^["']|["']$/g, ""); }); return env; }; const compareEnvFiles = (input) => { const left = parseEnvText(fieldText(input, "left")); const right = parseEnvText(fieldText(input, "right")); const issues = []; Object.keys(left).forEach((key) => { if (!(key in right)) issues.push({ severity: "error", message: `${key} is missing from the second env file.` }); else if (left[key] && right[key] && left[key] !== right[key]) issues.push({ severity: "warning", message: `${key} has different non-empty values.` }); }); Object.keys(right).forEach((key) => { if (!(key in left)) issues.push({ severity: "info", message: `${key} exists only in the second env file.` }); }); return { summary: `${Object.keys(left).length} left keys compared with ${Object.keys(right).length} right keys. ${summarizeIssues(issues)}.`, issues: sortIssues(issues), output: sortIssues(issues).map(formatIssue).join("\n") || "Env files have the same keys.", exportFilename: "env-diff-report.txt", stats: { leftKeys: Object.keys(left).length, rightKeys: Object.keys(right).length } }; }; const formatIssue = (issue) => { const location = issue.line ? `line ${issue.line}` : issue.row ? `row ${issue.row}` : "general"; return `[${issue.severity.toUpperCase()}] ${location}: ${issue.message}${issue.detail ? ` (${issue.detail})` : ""}`; }; const __userInput = userInput == null ? {} : userInput; const __run = (fields) => compareEnvFiles(fields); const __fields = __userInput && typeof __userInput === "object" && "fields" in __userInput && __userInput.fields && typeof __userInput.fields === "object" && !Array.isArray(__userInput.fields) ? __userInput.fields : (__userInput && typeof __userInput === "object" && !Array.isArray(__userInput) ? __userInput : {}); const __normalizedFields = Object.fromEntries(Object.entries(__fields).map(([key, value]) => [key, value == null ? "" : (["string", "number", "boolean"].includes(typeof value) ? value : String(value))])); return __run(__normalizedFields); } ``` ## Checks - Two dotenv snapshots: Left and right env files are compared after parsing KEY=value lines. - Missing keys: Keys present in the first file but absent from the second are treated as blocking gaps. - Extra keys: Keys that exist only in the second file are reported as informational differences. - Changed non-empty values: When both files have non-empty but different values, the key is flagged for review. - Key-focused comparison: The tool compares env keys and simple values, not deployment secrets or runtime availability. ## Related Tools - [.env Validator and Secret Scanner](/developer-tools/env-validator-secret-scanner/): Paste a dotenv file, catch duplicate or malformed keys, and generate a safer example file locally.