Build CLI configuration management
✓Works with OpenClaudeYou are a CLI application architect building a configuration management system. The user wants to create a command-line tool that reads, validates, writes, and manages application configuration files with support for multiple formats and environment variable overrides.
What to check first
- Confirm Node.js version supports
fs/promises(v14+) by runningnode --version - Verify target config formats: JSON, YAML, .env, TOML — decide which to support initially
- Check if
dotenvandyamlpackages are already installed withnpm list dotenv yaml
Steps
- Install required dependencies:
npm install dotenv yaml commander chalk table-layoutfor parsing, CLI building, and output formatting - Create a
Configclass that usesfs/promises.readFile()to load config files with format auto-detection based on file extension - Implement a
validate()method using a schema object to enforce required keys and type checking with early validation errors - Add an
override()method that merges command-line arguments andprocess.envvariables with loaded config, prioritizing CLI args > env vars > file config - Create a
set()andget()method for dot-notation key access (e.g.,get('database.host')reaches nestedconfig.database.host) - Build CLI commands with Commander.js:
config get <key>,config set <key> <value>,config list,config validate - Implement a
write()method usingfs/promises.writeFile()to persist changes back to the config file in original format - Add error handling for file not found, permission denied, invalid JSON/YAML, and schema validation failures with descriptive messages
Code
import fs from 'fs/promises';
import path from 'path';
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
import { program } from 'commander';
import chalk from 'chalk';
import dotenv from 'dotenv';
class ConfigManager {
constructor(configPath, schema = {}) {
this.configPath = configPath;
this.schema = schema;
this.config = {};
this.format = path.extname(configPath).slice(1) || 'json';
}
async load() {
try {
const content = await fs.readFile(this.configPath, 'utf-8');
if (this.format === 'json') {
this.config = JSON.parse(content);
} else if (this.format === 'yaml' || this.format === 'yml') {
this.config = parseYaml(content);
} else if (this.format === 'env') {
this.config = dotenv.parse(content);
}
this.validate();
return this.config;
} catch (err) {
if (err.code === 'ENOENT
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 CLI Tools Skills
Other Claude Code skills in the same category — free to download.
CLI App Builder
Build CLI applications with Commander.js
Interactive CLI
Create interactive CLI prompts (Inquirer.js)
CLI Progress Bar
Add progress bars and spinners to CLI
CLI Help Generator
Generate help text and man pages
CLI Testing
Test CLI applications
CLI Packaging
Package CLI for npm/brew distribution
CLI Autocomplete
Add shell autocompletion to CLI tools
CLI Color Output
Add colored and formatted CLI output
Want a CLI Tools 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.