Skilllibrary config-files-xdg
install
source · Clone the upstream repo
git clone https://github.com/merceralex397-collab/skilllibrary
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/merceralex397-collab/skilllibrary "$T" && mkdir -p ~/.claude/skills && cp -r "$T/10-cli-systems-and-ops/config-files-xdg" ~/.claude/skills/merceralex397-collab-skilllibrary-config-files-xdg && rm -rf "$T"
manifest:
10-cli-systems-and-ops/config-files-xdg/SKILL.mdsource content
Purpose
Place application config, data, cache, and state files in XDG Base Directory compliant paths with correct fallbacks.
When to use this skill
- deciding where a CLI tool should read/write config, data, or cache
- implementing XDG Base Directory resolution with platform fallbacks
- migrating a tool from
to XDG-compliant paths~/.myapp - adding
flag that overrides default config path--config
Do not use this skill when
- writing systemd unit files — prefer
systemd-services - working with language-specific config (
,.eslintrc
) — those follow ecosystem conventionspyproject.toml - the app is server-only with env-var-based config
Procedure
- Classify files — config (user-editable settings), data (persistent app state), cache (regenerable), runtime (sockets, locks).
- Resolve XDG paths — read
(default$XDG_CONFIG_HOME
),~/.config
(default$XDG_DATA_HOME
),~/.local/share
(default$XDG_CACHE_HOME
),~/.cache
(default$XDG_STATE_HOME
).~/.local/state - Create app subdirectory — use
, not$XDG_CONFIG_HOME/myapp/
. Create dirs with$XDG_CONFIG_HOME/myapp.conf
permissions.0700 - Support overrides — accept
flag and--config
env var. Priority: flag > env > XDG path > default.MYAPP_CONFIG - Handle platform differences — on macOS use
if XDG vars are unset; on Windows use~/Library/Application Support
.%APPDATA% - Add migration — if
exists and XDG path does not, offer to migrate. Print the action taken.~/.myapp
XDG directory mapping
| Category | Env var | Default | Example |
|---|---|---|---|
| Config | | | |
| Data | | | |
| Cache | | | |
| State | | | |
| Runtime | | | |
Key patterns
func configDir() string { if v := os.Getenv("XDG_CONFIG_HOME"); v != "" { return filepath.Join(v, "myapp") } home, _ := os.UserHomeDir() return filepath.Join(home, ".config", "myapp") }
from pathlib import Path import os def config_dir() -> Path: xdg = os.environ.get("XDG_CONFIG_HOME") base = Path(xdg) if xdg else Path.home() / ".config" d = base / "myapp" d.mkdir(parents=True, exist_ok=True) return d
Decision rules
- Config files are user-editable (TOML/YAML). Data files are app-managed (SQLite, JSON state).
- Cache must be safe to delete without data loss — the app must regenerate it.
- Never write to
at runtime — config is read-only; use state or data for writes.$XDG_CONFIG_HOME - Use
permissions for directories,0700
for files containing secrets.0600 - Support
(colon-separated search path) for system-level defaults.$XDG_CONFIG_DIRS
References
Related skills
— resolving paths in shell scriptsbash
— integrating XDG with Viper configcli-development-go
— integrating XDG with Click/Typercli-development-python