xdg-base-directory
БесплатноБез исполняемых скриптовНе проверенWhen an application needs to store config, data, cache, or state files. When designing where user-specific files should live. When code writes to ~/.appname…
от BbgnsurfTech★ 30 звёзд на GitHubОб этом скилле
XDG Base Directory Specification
Implement standardized directory paths for configuration, data, cache, and state files following the XDG Base Directory Specification.
When to Use This Skill
Use this skill when:
- Creating CLI tools or applications that store user-specific files
- Implementing configuration file management for Linux/Unix applications
- Building cross-platform Python applications requiring standardized directory paths
- Migrating legacy applications from
~/.appnameto XDG-compliant paths - Designing file storage architecture for Python packages
- Implementing proper environment variable handling for user directories
- Writing applications that respect user-configured directory preferences
- Testing applications with custom XDG directory overrides
Core Specification Rules
The XDG Base Directory Specification (version 0.8, May 2021) defines these critical requirements:
1. All Paths Must Be Absolute
Environment variable values MUST be absolute paths. Relative paths are invalid and MUST be ignored.
def validate_xdg_path(path_str: str | None) -> Path | None:
"""Validate XDG path is absolute per specification."""
if not path_str:
return None
path = Path(path_str)
if not path.is_absolute():
return None # Ignore relative paths per spec
return path
2. Empty Variables Use Defaults
When an environment variable is unset or empty, use the specification-defined default value.
3. Priority Order for Search Paths
- User-specific directories (
$XDG_CONFIG_HOME,$XDG_DATA_HOME) take precedence - System directories (
$XDG_CONFIG_DIRS,$XDG_DATA_DIRS) searched in order - First match wins
4. Colon Separator for Search Paths
$XDG_DATA_DIRS and $XDG_CONFIG_DIRS use colon (:) as path separator, similar to $PATH.
Environment Variables
User-Specific Directories (Single Path)
| Variable | Purpose | Default | Use For |
|---|---|---|---|
$XDG_CONFIG_HOME |
User configuration files | $HOME/.config |
Settings, preferences, user configs |
$XDG_DATA_HOME |
User data files | $HOME/.local/share |
Databases, generated content, persistent data |
$XDG_STATE_HOME |
User state files | $HOME/.local/state |
Logs, history, undo buffers, recent files |
$XDG_CACHE_HOME |
User cache files | $HOME/.cache |
Temporary data, downloaded files, build artifacts |
$XDG_RUNTIME_DIR |
User runtime files | System-set (/run/user/$UID) |
Sockets, pipes, lock files, IPC |
System-Wide Directories (Search Paths)
| Variable | Purpose | Default |
|---|---|---|
$XDG_DATA_DIRS |
System data search path | /usr/local/share/:/usr/share/ |
$XDG_CONFIG_DIRS |
System config search path | /etc/xdg |
User Executables (Convention, Not XDG)
| Path | Purpose |
|---|---|
$HOME/.local/bin |
User-specific executable files |
Note: Distributions should ensure $HOME/.local/bin appears in $PATH.
Directory Selection Guide
Choose the appropriate directory based on data characteristics:
Use $XDG_CONFIG_HOME for:
- Application settings and preferences
- User-specific configuration files
- TOML/YAML/JSON configuration
- Example:
~/.config/myapp/config.toml
Use $XDG_DATA_HOME for:
- Persistent application data
- User-generated content
- Downloaded models or assets
- Database files
- Example:
~/.local/share/myapp/models/model.gguf
Use $XDG_STATE_HOME for:
- Action history (command history, undo buffers)
- Application state that can be regenerated
- Recently used files lists
- Log files specific to user actions
- Example:
~/.local/state/myapp/history.log
Use $XDG_CACHE_HOME for:
- Temporary files safe to delete
- Downloaded data that can be re-fetched
- Build artifacts and compiled files
- Thumbnail caches
- Example:
~/.cache/myapp/downloads/
Use $XDG_RUNTIME_DIR for:
- Unix domain sockets
- Named pipes (FIFOs)
- Lock files
- Temporary IPC files
- Warning: Often tmpfs-mounted with size limits; avoid large files
- Warning: Cleaned on logout; do not store persistent data
- Example:
/run/user/1000/myapp/socket
Python Implementation Patterns
Stdlib-Only Implementation
Use for applications targeting only Linux/Unix systems or requiring no dependencies.
"""XDG Base Directory compliant path management using stdlib only."""
from pathlib import Path
import os
def get_config_home() -> Path:
"""Get XDG_CONFIG_HOME path.
Returns user-specific configuration directory.
Falls back to $HOME/.config if XDG_CONFIG_HOME unset or relative.
"""
xdg = os.environ.get('XDG_CONFIG_HOME')
if xdg and Path(xdg).is_absolute():
return Path(xdg)
return Path.home() / '.config'
Установить xdg-base-directory в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл xdg-base-directory?
When an application needs to store config, data, cache, or state files. When designing where user-specific files should live. When code writes to ~/.appname or hardcoded home paths. When implementing cross-platform file storage with platformdirs.
Как установить скилл xdg-base-directory?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл xdg-base-directory запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic