Agent skill
state-directory-manager
Manage persistent state directories with XDG-compliant paths and cleanup for bash scripts
Install this agent skill to your Project
npx add-skill https://github.com/vamseeachanta/workspace-hub/tree/main/.claude/skills/_core/bash/state-directory-manager
SKILL.md
State Directory Manager
When to Use This Skill
✅ Use when:
- Scripts need to persist data between runs
- Storing user preferences or configuration
- Caching results for performance
- Managing log files with rotation
- Creating portable CLI tools
❌ Avoid when:
- One-time scripts that don't need state
- Scripts that should be purely stateless
- When environment variables are sufficient
Complete Example: State Manager Module
#!/bin/bash
# ABOUTME: Complete state directory manager
# ABOUTME: Reusable module for bash scripts
# ─────────────────────────────────────────────────────────────────
# State Directory Manager v1.0.0
# ─────────────────────────────────────────────────────────────────
# Application identity (override in your script)
: "${STATE_APP_NAME:=my-app}"
# Directory setup
STATE_BASE_DIR="${HOME}/.${STATE_APP_NAME}"
STATE_CONFIG_DIR="$STATE_BASE_DIR/config"
STATE_DATA_DIR="$STATE_BASE_DIR/data"
STATE_CACHE_DIR="$STATE_BASE_DIR/cache"
STATE_LOG_DIR="$STATE_BASE_DIR/logs"
STATE_TMP_DIR="$STATE_BASE_DIR/tmp"
# File paths
STATE_CONFIG_FILE="$STATE_CONFIG_DIR/config"
STATE_STATE_FILE="$STATE_DATA_DIR/state"
STATE_LOG_FILE="$STATE_LOG_DIR/app.log"
*See sub-skills for full details.*
## Usage in Scripts
```bash
#!/bin/bash
# Your script that uses the state manager
# Set app name before sourcing
STATE_APP_NAME="my-tool"
# Source the state manager
source /path/to/state-manager.sh
# Now use it
state_config_set "api_key" "abc123"
api_key=$(state_config_get "api_key")
state_set "last_run" "$(date -Iseconds)"
state_log "INFO" "Script started"
# Use cache
if ! result=$(state_cache_get "api_response"); then
result=$(curl -s https://api.example.com/data)
state_cache_set "api_response" "$result"
fi
Resources
Version History
- 1.0.0 (2026-01-14): Initial release - extracted from workspace-hub patterns
Sub-Skills
- 1. XDG Base Directory Standard (+2)
- 4. State File Operations
- 5. Cache Management (+1)
- Best Practices
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
gsd-complete-milestone
Archive completed milestone and prepare for next version
gsd-reapply-patches
Reapply local modifications after a GSD update
gsd-verify-work
Validate built features through conversational UAT
gsd-thread
Manage persistent context threads for cross-session work
clinical-trial-protocol
Generate clinical trial protocols for medical devices or drugs through a modular, waypoint-based architecture with research-only and full protocol modes.
single-cell-rna-qc
Performs quality control on single-cell RNA-seq data (.h5ad or .h5 files) using scverse best practices with MAD-based filtering and comprehensive visualizations.
Didn't find tool you were looking for?