End-of-session workflow that audits workspace for junk files, validates work against development principles, updates session documentation, and completes handoff...
FIRST: Determine which workflow to follow
Execute these steps in order:
Scan for obvious issues in root directories only:
# Junk files
find . -maxdepth 3 -type f \( -name "*.tmp" -o -name "*.bak" -o -name "*~" -o -name "*.swp" -o -name ".DS_Store" \) -not -path "./.git/*" -not -path "*/node_modules/*" -not -path "*/archive/*"
# Version conflicts (CRITICAL - always check)
find docs .claude -maxdepth 2 -type f -name "*.md" | grep -iE "(v2|v3|new|old|copy|backup|optimized|updated|revised)" | grep -v archive
Report findings to user. Skip to Step 2 if clean.
If version conflicts found in Step 1:
# Archive (if valuable)
git mv docs/guide-old.md archive/docs/
# Delete (if no reference value)
git rm docs/guide-old.md
CRITICAL: Update docs related to session work
Identify what changed:
# Files modified this session
git diff --name-only HEAD~5 HEAD | grep -v ".claude/sessions"
Update corresponding documentation:
docs/MCP_TOOLS_REFERENCE.mddocs/REST_API_GUIDE.mddocs/N8N_*.mddocs/ROADMAP.md.claude/PROJECT_OVERVIEW.mddocs/KNOWN_ISSUES.mdUpdate with session summary (100-200 lines max):
# Current Session Context
> **Last Updated**: YYYY-MM-DD
> **Last Session**: YYYY-MM-DD-N
## Quick Status
[Status table with current phase, components, blockers]
## Last Session (YYYY-MM-DD-N)
**Focus**: Brief description
**Completed**: 2-3 key items
**Commits**: X commits (SHAs)
## Next Session Priorities
1. Priority 1
2. Priority 2
3. Priority 3
## Key Files Changed Recently
- `path/to/file` - What changed
Create JSON archive for previous session:
mkdir -p .claude/sessions/archive/YYYY-MM
Create .claude/sessions/archive/YYYY-MM/YYYY-MM-DD-N.json:
{
"session_id": "YYYY-MM-DD-N",
"date": "YYYY-MM-DD",
"focus": "Brief description",
"completed": ["Item 1", "Item 2"],
"commits": [{"sha": "abc123", "message": "..."}],
"files_modified": ["path/to/file"],
"next_priorities": ["Priority 1"]
}
# Stage changes
git add .claude/sessions/ archive/ docs/
# Commit
git commit -m "$(cat <<'EOF'
docs: Session handoff YYYY-MM-DD - [brief description]
- Archived session YYYY-MM-DD-N
- [Summary of cleanup/updates]
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
EOF
)"
# Push
git push origin main
✅ Quick Handoff Complete!
📦 Cleanup:
- Junk files: X deleted
- Version conflicts: Y resolved
- Documentation: Z files updated
📋 Git: [SHA] → origin/main
🎯 Next: [Priority 1]
Quick handoff complete! Stop here.
Execute ALL steps in order:
Before applying rigid rules, use common sense:
# Overview of all directories
tree -L 2 -d . 2>/dev/null || find . -type d -maxdepth 2 | grep -v node_modules | grep -v .git | sort
# List root-level files
ls -lah | grep -v "^d"
# Check key folders
ls -lh docs/ .claude/
Apply critical thinking - flag anything that seems:
Report abnormalities to user:
Don't proceed until user responds to abnormalities (if any)
Comprehensive scan for cleanup candidates:
# All junk files
find . -type f \( -name "*.tmp" -o -name "*.bak" -o -name "*~" -o -name "*.swp" -o -name ".DS_Store" \) -not -path "./.git/*" -not -path "*/node_modules/*" -not -path "*/archive/*"
# All potential duplicates
find . -type f \( -name "*-copy.*" -o -name "*-old.*" -o -name "*-backup.*" -o -name "*-v[0-9]*" \) -not -path "./.git/*" -not -path "*/node_modules/*" -not -path "*/archive/*"
# Version conflicts
find docs .claude -type f -name "*.md" | grep -iE "(v2|v3|new|old|copy|backup|optimized|updated|revised)" | grep -v archive
# Empty directories
find . -type d -empty -not -path "./.git/*"
Report ALL findings to user before cleanup.
Present findings:
📋 Deep Workspace Audit Results
🗑️ Junk Files (N found):
- ./path/to/file.tmp
- ./another/file.bak
📦 Potential Duplicates (N found):
- ./docs/guide-old.md
- ./docs/guide-v2.md
⚠️ Version Conflicts (N found):
- Multiple versions of X
What would you like me to do?
1. Delete junk files + resolve conflicts (recommended)
2. Archive everything to ./archive/
3. Review each item individually
4. Skip cleanup
Wait for user response. Do NOT proceed without confirmation.
Based on user's choice from Step 3, apply cleanup rules:
Archive vs Delete decision criteria:
Archive (valuable for future reference):
Delete (no reference value):
*_IMPORT.md)When in doubt: Delete (it's in Git history)
Automatic cleanup triggers:
Execute cleanup:
# Archive (if valuable for reference)
git mv .claude/MAJOR_AUDIT.md archive/.claude/audits/
git mv docs/MIGRATION_PLAN.md archive/docs/migrations/
# Delete (if no reference value)
git rm docs/ROUTINE_IMPORT.md
git rm .claude/TEMP_ANALYSIS.md
For EACH version conflict found:
Read .claude/DEVELOPMENT_PRINCIPLES.md and validate session work:
Report validation results. Flag any violations or concerns.
Same as Quick Handoff Step 3 - update all docs related to session work.
Same as Quick Handoff Step 4 - update with session summary.
Same as Quick Handoff Step 5 - create JSON archive.
Only update if:
Otherwise skip.
# Stage all handoff changes
git add .claude/sessions/ archive/ docs/ .claude/PROJECT_OVERVIEW.md
# Commit with detailed message
git commit -m "$(cat <<'EOF'
docs: Session handoff YYYY-MM-DD - [brief description]
- Archived session YYYY-MM-DD-N ([focus])
- Cleaned up X files (deleted), Y files (archived)
- Resolved Z version conflicts
- Updated N documentation files
- Validated against development principles
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
EOF
)"
# Push
git push origin main
✅ Full Handoff Complete!
🧠 Critical Thinking Review:
- Abnormalities noted: N items
- User-directed cleanup: M items
📊 Workspace Audit:
- Deleted: X files (no reference value)
- Archived: Y documents (valuable for reference)
- Audits: N (insights/learnings)
- Plans: M (decisions/rationale)
- Migrations: P (how we got here)
- Version conflicts: Z resolved
✅ Principles Validation:
- LLM-First: [✅ / ⚠️ Notes]
- Data First: [✅ / ⚠️ Notes]
- Progressive Enhancement: [✅ / ⚠️ Notes]
- Complexity Budget: [✅ / ⚠️ Notes]
- Two-Speed Development: [✅ / ⚠️ Notes]
- Context-First Automation: [✅ / ⚠️ Notes]
- Cost-Conscious AI: [✅ / ⚠️ Notes]
📝 Documentation Updated:
- List of updated docs
📦 Session Archived:
- YYYY-MM-DD-N → .claude/sessions/archive/
📋 Git: [SHA] → origin/main
🎯 Next Session Priorities:
1. [Priority 1]
2. [Priority 2]
3. [Priority 3]
Full handoff complete!
.claude/ - Claude-specific configuration ONLY
.claude/
├── CLAUDE.md # Quick start guide
├── PROJECT_OVERVIEW.md # Current architecture
├── DEVELOPMENT_PRINCIPLES.md # Timeless principles
├── sessions/ # Session tracking
│ ├── CURRENT.md # Current state
│ └── archive/YYYY-MM/ # Session JSON archives
├── skills/ # Skill definitions
└── settings.local.json # Local settings
docs/ - ALL active project documentation
docs/
├── ROADMAP.md # Living roadmap
├── MCP_TOOLS_REFERENCE.md # Current tool reference
├── REST_API_GUIDE.md # API documentation
├── KNOWN_ISSUES.md # Active issues
├── N8N_*.md # N8N guides (living)
├── APPLE_SHORTCUTS_GUIDE.md # Integration guides
└── CLAUDE_WEB_MOBILE_SETUP.md # Setup guides
archive/ - Completed/superseded artifacts (mirrors active structure)
archive/
├── README.md # Archive policy
├── .claude/ # Claude artifacts
│ ├── audits/ # Completed audits
│ └── plans/ # Completed plans
├── docs/ # Documentation artifacts
│ ├── analysis/ # Completed analysis
│ ├── audits/ # System audits (>3 sessions)
│ ├── guides/ # Superseded guides
│ ├── imports/ # One-time imports
│ ├── migrations/ # Migration docs
│ └── plans/ # Completed plans
└── [deprecated-folders]/ # Old approaches
Git is Our Backup - Archive only if valuable for future reference
Archive when:
Delete when:
When in doubt: Delete (it's in Git history if needed)
Session ID Format: YYYY-MM-DD-N (e.g., 2025-12-16-1)
Archive Command Pattern:
git mv [source] archive/[mirror-path]/
Files to Update Every Handoff:
.claude/sessions/CURRENT.md (always).claude/PROJECT_OVERVIEW.md (only if major changes)Commit Message Pattern:
docs: Session handoff YYYY-MM-DD - [brief description]
- [Summary of changes]
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>