dlx-claude/scripts/README.md

124 lines
3.2 KiB
Markdown

# Scripts Directory
Automation scripts for managing Claude configurations and memory.
## sync-memory.sh
Synchronizes Claude's in-memory project knowledge to this version-controlled repository.
### Usage
```bash
# Interactive sync with commit prompt
./scripts/sync-memory.sh
# Auto-commit with timestamp
./scripts/sync-memory.sh --auto
# Preview changes without modifying files
./scripts/sync-memory.sh --dry-run
```
### What It Syncs
- `~/.claude/projects/-source-dlx-src-dlx-ansible/memory/MEMORY.md``memory/dlx-ansible/MEMORY.md`
- `~/.claude/projects/-source-hiveops-src-hiveops-mgmt/memory/MEMORY.md``memory/hiveops-mgmt/MEMORY.md`
- `~/.claude/projects/-source-hiveops-src-hiveops-incident/memory/MEMORY.md``memory/hiveops-incident/MEMORY.md`
- `~/.claude/projects/-source-hiveops-src-hiveops-browser/memory/MEMORY.md``memory/hiveops-browser/MEMORY.md`
### Automatic Syncing
#### Option 1: Cron Job (Scheduled)
Run sync every day at 2 AM:
```bash
# Add to crontab
crontab -e
# Add this line:
0 2 * * * cd /source/dlx-src/dlx-claude && ./scripts/sync-memory.sh --auto && git push origin main 2>&1 | logger -t claude-sync
```
#### Option 2: Git Hook (On Commit)
Create a post-commit hook in projects to trigger sync:
```bash
# In ~/.claude/hooks/ (if Claude supports this)
# Or manually run after significant work sessions
```
#### Option 3: Manual (Recommended)
Run manually after completing significant work:
```bash
cd /source/dlx-src/dlx-claude
./scripts/sync-memory.sh
git push origin main
```
### Workflow
1. Work with Claude Code on infrastructure projects
2. Claude updates memory files in `~/.claude/projects/`
3. Run sync script to version control knowledge
4. Push to Gitea for team sharing and backup
### Best Practices
- Run sync after completing major tasks
- Review changes before committing (use interactive mode)
- Use `--dry-run` to preview changes first
- Keep memory files under 200 lines (Claude's limit)
- Document critical learnings immediately
## cleanup-plans.sh
Manages Claude's plan files by archiving old plans to keep the directory clean.
### Usage
```bash
# List all plan files with ages
./scripts/cleanup-plans.sh
# Archive plans older than 30 days
./scripts/cleanup-plans.sh --archive
# Archive all plans
./scripts/cleanup-plans.sh --archive-all
# Change age threshold (e.g., 60 days)
./scripts/cleanup-plans.sh --archive --days 60
```
### What It Does
Claude Code creates plan files in `~/.claude/plans/` for each planning session. Over time, these accumulate. This script:
1. Lists all plan files with their ages
2. Identifies plans older than a threshold (default: 30 days)
3. Archives old plans to `~/.claude/plans-archive/YYYY-MM-DD/`
4. Preserves recent plans in the active directory
### When to Use
- Monthly cleanup: Archive plans older than 30 days
- Project cleanup: Archive all plans when starting fresh
- Regular maintenance: Keep the plans directory manageable
### Archive Location
Archived plans are moved to: `~/.claude/plans-archive/YYYY-MM-DD/`
This preserves plans by archive date, allowing you to:
- Reference old planning sessions if needed
- Restore plans if accidentally archived
- Delete archive folders when truly no longer needed
---
**Created**: 2026-02-09