A CLI tool for switching JSON/TOML configuration files. Define configuration profiles and switch between them with a single command.
npm install -g cfgmodOr run directly with npx:
npx cfgmod <command>- Create a configuration file at
~/.cfgmod/cfgmod.json:
{
"variables": {
"DB_HOST": "localhost"
},
"profiles": {
"dev": {
"targets": [
{
"files": ["~/.config/myapp/config.json"],
"config": {
"database": {
"host": "${DB_HOST}",
"port": 5432
}
}
}
]
},
"prod": {
"targets": [
{
"files": ["~/.config/myapp/config.json"],
"config": {
"database": {
"host": "prod-db.example.com",
"port": 5432
}
}
}
]
}
}
}- Switch to a profile:
cfgmod use devSwitch to a configuration profile.
cfgmod use dev
cfgmod use prod --dry-run # Preview changes without modifying files
cfgmod use prod --force # Force apply even if current config is unknownForce switch to a profile, skipping the current config check. This is an alias for cfgmod use <profile> --force.
cfgmod reload devList all available profiles.
cfgmod listOutput:
Profiles:
● dev (current)
→ ~/.config/myapp/config.json
○ prod
→ ~/.config/myapp/config.json
Show the currently active profile.
cfgmod current| Option | Environment Variable | Description |
|---|---|---|
-c, --config <path> |
CFGMOD_CONFIG |
Path to cfgmod.json |
--dry-run |
- | Preview changes without modifying files |
-y, --force |
- | Force apply changes even if current config is unknown |
By default, cfgmod looks for configuration at ~/.cfgmod/cfgmod.json. You can override this with:
- CLI option:
--config /path/to/cfgmod.json - Environment variable:
CFGMOD_CONFIG=/path/to/cfgmod.json
{
"variables": {
"VAR_NAME": "value",
"FROM_ENV": "${env:ENV_VAR_NAME}"
},
"profiles": {
"profile-name": {
"targets": [
{
"files": ["path/to/config.json", "path/to/another.toml"],
"config": {
"nested": {
"key": "value"
}
}
}
]
}
}
}Define reusable values in the variables section:
{
"variables": {
"API_HOST": "api.example.com",
"API_KEY": "${env:MY_API_KEY}"
},
"profiles": {
"dev": {
"targets": [
{
"files": ["config.json"],
"config": {
"api": {
"host": "${API_HOST}",
"key": "${API_KEY}"
}
}
}
]
}
}
}${VAR_NAME}- Reference a variable defined invariables${env:ENV_VAR_NAME}- Reference an environment variable
Use wildcards to apply the same value to multiple keys:
{
"profiles": {
"local": {
"targets": [
{
"files": ["servers.json"],
"config": {
"servers": {
"*": {
"host": "localhost"
}
}
}
}
]
}
}
}Given a target file:
{
"servers": {
"web": { "host": "web.example.com", "port": 80 },
"api": { "host": "api.example.com", "port": 8080 },
"db": { "host": "db.example.com", "port": 5432 }
}
}After cfgmod use local:
{
"servers": {
"web": { "host": "localhost", "port": 80 },
"api": { "host": "localhost", "port": 8080 },
"db": { "host": "localhost", "port": 5432 }
}
}Both * and $wildcard are supported as wildcard keys.
A single profile can modify multiple files with different configurations:
{
"profiles": {
"dev": {
"targets": [
{
"files": ["~/.config/app-a/config.json"],
"config": {
"database": { "host": "localhost" }
}
},
{
"files": ["~/.config/app-b/settings.toml"],
"config": {
"api": { "endpoint": "http://localhost:3000" }
}
}
]
}
}
}Apply the same configuration to multiple files (files must have the same structure):
{
"profiles": {
"dev": {
"targets": [
{
"files": [
"~/.config/instance-1/config.json",
"~/.config/instance-2/config.json"
],
"config": {
"server": { "host": "localhost" }
}
}
]
}
}
}Use cfgmod to switch between different API providers for Claude Code:
{
"variables": {
"OFFICIAL_URL": "https://api.anthropic.com",
"OFFICIAL_TOKEN": "${env:ANTHROPIC_API_KEY}",
"PROXY_URL": "https://your-proxy.example.com",
"PROXY_TOKEN": "${env:PROXY_API_KEY}"
},
"profiles": {
"official": {
"targets": [
{
"files": ["~/.claude/settings.json"],
"config": {
"env": {
"ANTHROPIC_BASE_URL": "${OFFICIAL_URL}",
"ANTHROPIC_AUTH_TOKEN": "${OFFICIAL_TOKEN}"
}
}
}
]
},
"proxy": {
"targets": [
{
"files": ["~/.claude/settings.json"],
"config": {
"env": {
"ANTHROPIC_BASE_URL": "${PROXY_URL}",
"ANTHROPIC_AUTH_TOKEN": "${PROXY_TOKEN}"
}
}
}
]
}
}
}Switch to official API:
cfgmod use officialSwitch to proxy:
cfgmod use proxyPreview changes before applying:
cfgmod use proxy --dry-run- JSON (
.json) - TOML (
.toml)
| Scenario | Behavior |
|---|---|
| cfgmod.json not found | Error with instructions |
| Target file not found | Error |
| Profile not found | Error with available profiles |
| Current config doesn't match any profile | Warning, use --force to override |
| Variable not defined | Error |
| Environment variable not set | Error |
MIT