<h1 align="center">
<a href="https://prompts.chat">
**Universal Claude Code Infrastructure for All Projects**
Sign in to like and favorite skills
Universal Claude Code Infrastructure for All Projects
This repository contains reusable Claude Code infrastructure that enables consistent, powerful development workflows across all your projects. It includes global commands, bash utilities, session management, and comprehensive documentation.
This is a global infrastructure repository that lives at
~/.claude/ on your machine. It provides:
.claude/commands/*.md files that automate complex workflowsThink of it as a global toolkit that every project can leverage, complemented by project-specific state (
.claude/SESSION.md, .claude/patches/, etc.).
Initially, task spawning, crash recovery, and session management logic was duplicated in each project's
.claude/ directory. This meant:
By migrating platform infrastructure to a global, versioned repository:
~/.claude/ ├── README.md # This file ├── .gitignore # Excludes debug/IDE files │ ├── CLAUDE.md # Global directives & rules ├── PLATFORM_INFRASTRUCTURE.md # Complete platform documentation ├── SESSION.md.template # Standard session format │ ├── commands/ # Global custom commands │ ├── task_spawn.sh # Spawn hierarchical subtasks │ ├── task_recover.md # Crash recovery orchestration │ ├── resume.md # Resume previous session │ ├── checkpoint.md # Save progress mid-session │ ├── handoff.md # Persist state for next session │ └── shared-memory/ │ └── cmd.sh # Cross-IDE communication (symlink) │ ├── utils/ # Reusable bash utilities │ ├── git_operations.sh # Git utilities (25+ functions) │ ├── patch_manager.sh # Patch file lifecycle management │ ├── task_status.sh # Crash detection & analysis │ ├── task_execute.sh # Execution with validation │ └── shared_memory_updater.sh # Shared memory backend │ └── .git/ # Version control (git repository)
| Location | Purpose | Versioned |
|---|---|---|
(this repo) | Reusable infrastructure | ✅ Yes |
(project) | Project-specific state | ❌ No (usually gitignored) |
Global (
~/.claude/):
Project-Local (
./.claude/):
SESSION.md - Current session statepatches/ - Task patch files (crash recovery)shared_memory.yaml - Cross-IDE notesdocs/ - Project-specific examplesAll projects use the same session management system, but each project maintains its own session state:
| Component | Location | Scope |
|---|---|---|
| Commands | | ✅ GLOBAL (shared by all projects) |
| Session State | | ✅ PROJECT-LOCAL (per project) |
The Three Session Commands (All Global):
/project:resume # Load context from previous session /project:checkpoint # Save progress mid-session /project:handoff # Persist state before closing
How It Works:
./.claude/SESSION.md → Restores context./.claude/SESSION.md → Saves progress./.claude/SESSION.md → Prepares for next sessionWhy This Architecture:
SESSION.md.templateMigration Note:
Session commands (
resume.md, checkpoint.md, handoff.md) were migrated to global ~/.claude/ in January 2026 to ensure consistency and maintainability. No per-project duplication needed anymore.
Clone the repository to
:~/.claude/
git clone https://gitlab.com/treyipune/global_claude_code_setup.git ~/.claude cd ~/.claude git remote add github https://github.com/treyidev/global_claude_code_setup.git
Verify installation:
ls -la ~/.claude/ # Should show: CLAUDE.md, PLATFORM_INFRASTRUCTURE.md, commands/, utils/ cd ~/.claude git log --oneline # Should show commit: c6a4130 chore: initialize global claude code setup
Once
~/.claude/ is set up globally, any project can use it immediately:
cd /path/to/your/project # ~/.claude is already available globally - no per-project setup needed! # Create project-local Claude Code state mkdir -p .claude/patches
To use the CLI commands in your project:
cd /path/to/your/project # All global commands are available /project:resume # Load previous session /project:checkpoint # Save progress /project:handoff # Persist state for next session
Since
~/.claude/ is a git repository, you can pull updates:
cd ~/.claude git pull origin main git pull github main # Mirror also available
Or push local improvements:
cd ~/.claude git add . git commit -m "chore: improve task spawn error handling" git push origin main git push github main
File:
~/.claude/CLAUDE.md
The global Claude directives file containing universal standards for all projects. This includes:
/project:resume, /project:checkpoint, /project:handoffUsage: This file is automatically consulted by any Claude Code instance working on your projects. Every rule applies globally.
File:
~/.claude/PLATFORM_INFRASTRUCTURE.md
Comprehensive guide to the entire platform infrastructure (112KB). Covers:
task_spawn.sh command reference
Crash Detection (
task_status.sh)
Recovery Execution (
task_execute.sh)
~/.claude/commands/, project-agnostic)
/project:resume - Load context from ./.claude/SESSION.md (project-local)/project:checkpoint - Save progress mid-session to ./.claude/SESSION.md/project:handoff - Persist state for next session in ./.claude/SESSION.md~/.claude/SESSION.md.template)/shared-memory command
Usage: Read this documentation to understand the complete platform. Reference it when:
File:
~/.claude/SESSION.md.template
Standard template for project-local
.claude/SESSION.md files. Ensures consistency across all projects.
Contains sections for:
Usage: When creating a new project:
cp ~/.claude/SESSION.md.template ./.claude/SESSION.md
File:
~/.claude/commands/task_spawn.sh
Spawns a new subtask as an independent Claude Code session with full context isolation.
What it does:
.claude/patches/<task-id>.yml)Usage:
~/.claude/commands/task_spawn.sh \ --model "sonnet" \ --prompt "Implement user authentication with Firebase" ~/.claude/commands/task_spawn.sh \ --model "haiku" \ --prompt "Run tests and report results" \ --branch-aware ~/.claude/commands/task_spawn.sh \ --model "opus" \ --prompt "Design authentication architecture" \ --parent-task "task-1234"
File:
~/.claude/commands/task_recover.md
Orchestrates crash recovery when a spawned task fails to complete.
What it does:
task_status.shScenarios handled:
File:
~/.claude/commands/resume.md
Resumes a previous session by reading
.claude/SESSION.md and restoring context.
What it does:
./.claude/SESSION.md from current projectFile:
~/.claude/commands/checkpoint.md
Saves progress mid-session without stopping work.
What it does:
./.claude/SESSION.md with current progressFile:
~/.claude/commands/handoff.md
Persists full session state for next session.
What it does:
./.claude/SESSION.md with completion notes/project:resumeFile:
~/.claude/commands/shared-memory/cmd.sh
Symlink to
~/.claude/utils/shared_memory_updater.sh.
Enables cross-IDE communication via shared memory entries.
What it does:
All utilities are located in
~/.claude/utils/ and are sourced by commands.
25+ git utility functions for common git operations.
Key functions:
git_current_branch() - Get current branch namegit_is_clean() - Check if working tree is cleangit_commits_ahead_of() - Count commits ahead of maingit_branch_exists() - Check if branch existsgit_delete_branch() - Delete local branchgit_reset_hard() - Hard reset to commitgit_fetch_origin() - Fetch latest from remotegit_rebase_on() - Rebase onto another branchgit_stash_save() - Stash changes with messagegit_stash_pop() - Apply and remove stashgit_get_head_commit() - Get current commit hashgit_get_head_commit_full() - Get full commit hashUsage: Sourced by other utilities and commands:
source ~/.claude/utils/git_operations.sh git_current_branch # Returns: "main" or "feature/something"
Patch file lifecycle management for task spawning and recovery.
Patch files store task context in YAML format:
task_id: task-1234 model: sonnet prompt: | Implement user authentication... git_branch: feature/auth last_good_commit: abc123def456 created_at: 2026-01-09T15:30:00Z updated_at: 2026-01-09T15:35:00Z status: in_progress
Key functions:
patch_create_file() - Create new patch filepatch_exists() - Check if patch existspatch_read_field() - Read a field from patchpatch_update_field() - Update a fieldpatch_read_prompt() - Read task promptpatch_validate_format() - Validate patch structurepatch_add_note() - Add audit noteUsage:
source ~/.claude/utils/patch_manager.sh patch_read_field "task-1234" "MODEL" # Returns: "sonnet" patch_update_field "task-1234" "STATUS" "completed"
Crash detection and scenario analysis for intelligent recovery.
Detects if a spawned task crashed and analyzes the situation:
{ "status": "crash_detected", "task_id": "task-1234", "task_context": { "model": "sonnet", "prompt": "...", "git_branch": "feature/auth" }, "git_state": { "current_branch": "feature/auth", "is_clean": false, "commits_ahead_of_main": 3, "files_changed": 5 }, "branch_state": { "exists": true, "name": "feature/auth", "commits_ahead": 3 }, "scenario_analysis": { "scenario": "post_work_no_mr", "description": "Work done but MR not created", "recovery_options": ["create_mr", "review_work", "modify_approach"] } }
Key functions:
task_detect_crash_state() - Generate full state report (JSON)detect_spawned_task() - Detect task ID from SESSION.mdanalyze_git_state() - Analyze current git statecheck_branch_state() - Check branch existence and commitsanalyze_scenario() - Determine recovery scenarioUsage:
source ~/.claude/utils/task_status.sh task_detect_crash_state > state_report.json
Execution with zero-tolerance validation for atomic operations.
Every action follows: execute → validate → report success or FAIL HARD.
Execute: Run the operation ↓ Validate: Verify success ↓ Report: Success or ABORTING (no recovery)
Key functions:
execute_reset_to_commit() - Rollback to commitexecute_delete_branch() - Delete branch with validationexecute_stash_changes() - Stash with validationexecute_rebase_on_main() - Rebase with conflict detectionexecute_apply_stash() - Apply stash with validationexecute_create_mr() - Create GitLab MRexecute_check_mr_status() - Check MR statusexecute_cleanup_orphaned_task(), execute_post_work_recovery()Usage:
source ~/.claude/utils/task_execute.sh execute_reset_to_commit "task-1234" "abc123" # Rolls back or FAILs
Cross-IDE communication backend for shared memory entries.
Enables different IDE sessions to communicate via a shared file.
Key functions:
shared_memory_add() - Add entryshared_memory_list() - List entriesshared_memory_mark_processed() - Mark as doneshared_memory_read() - Read entriesUsage:
source ~/.claude/utils/shared_memory_updater.sh shared_memory_add "web" "Added authentication" "Implemented OAuth with Firebase"
User: "Implement authentication" ↓ Command: /project:spawn --model sonnet --prompt "..." ↓ task_spawn.sh: 1. Generate task ID: task-1234 2. Create patch file: ./.claude/patches/task-1234.yml 3. Save context (model, prompt, branch, commit) 4. Spawn new Sonnet instance ↓ Spawned Sonnet Session: 1. Reads task from patch file 2. Works autonomously 3. Creates branch, commits work 4. Updates patch file status 5. Returns or crashes ↓ If crash detected: 1. task_status.sh analyzes crash 2. Determines scenario (pre-work, post-work, MR pending) 3. task_execute.sh follows recovery procedure 4. Validates each step 5. Guides user through options
Session 1 (Day 1): User: /project:resume # Load previous session Work for 1 hour... User: /project:checkpoint # Save progress Work continues... User: /project:handoff # Save state before stopping ↓ Session 2 (Day 2): User: /project:resume # Restores context from SESSION.md Claude: "Yesterday you completed X, Y, Z. Next: ..." Work continues from where we left off
User spawns task: task-1234 ↓ Task spawned with work done but no MR created Claude crashes mid-work ↓ User runs: /project:recover ↓ task_status.sh: 1. Detects task-1234 from SESSION.md 2. Reads patch file 3. Analyzes git state (branch exists, 3 commits) 4. Determines: "post_work_no_mr" scenario 5. Recommends: ["create_mr", "review_work", "modify_approach"] ↓ User chooses: create_mr ↓ task_execute.sh: 1. Execute: glab mr create ... 2. Validate: MR created successfully 3. Report: ✓ MR !123 created
This repository enforces automatic model routing for all custom commands.
Every
.claude/commands/*.md file has a model: field in its frontmatter:
--- model: sonnet --- # Command content
When any Claude Code instance encounters a command:
model: fieldmodel: sonnet and current = Sonnet → Execute directlymodel: sonnet and current = Haiku → Delegate via Task(model="sonnet")model: sonnet and current = Opus → Delegate via Task(model="sonnet")Haiku working on git operations ↓ Encounters: /project:docs-build command (has model: sonnet) ↓ Haiku recognizes: "This requires Sonnet" ↓ Haiku delegates: Task(model="sonnet", prompt="...docs-build command...") ↓ Sonnet takes over and completes the docs build
This rule is MANDATORY and documented in
CLAUDE.md.
Create minimal project-local setup:
# Create project-local Claude Code directory mkdir -p ./.claude/patches # Copy SESSION.md template cp ~/.claude/SESSION.md.template ./.claude/SESSION.md # (Optional) Add project-specific examples mkdir -p ./.claude/docs # Add project-specific command examples
All global commands work immediately in any project:
cd /path/to/project /project:resume # Load previous session /project:checkpoint # Save progress /project:handoff # Persist state for next # And any other commands defined in ~/.claude/commands/
When global infrastructure improves (bug fixes, new features):
cd ~/.claude git pull origin main # Update global setup # All projects automatically benefit!
This repository is version controlled via git with full commit history.
cd ~/.claude git log --oneline --all git show <commit> git diff <commit1> <commit2>
c6a4130 chore: initialize global claude code setup - Initial global infrastructure - All commands, utilities, documentation - Dual remotes (GitLab + GitHub)
Found a bug? Improved a utility? Make improvements and push:
cd ~/.claude git add . git commit -m "fix: improve error handling in task_spawn" git push origin main git push github main
All projects benefit immediately!
| File | Size | Complexity |
|---|---|---|
| ~50KB | High (comprehensive rules) |
| ~112KB | High (detailed guide) |
| ~8KB | Medium (25+ functions) |
| ~6KB | Medium (patch lifecycle) |
| ~10KB | Medium (state analysis) |
| ~12KB | Medium (atomic operations) |
| ~5KB | Medium (task creation) |
| ~4KB | Medium (orchestration) |
Total: ~200KB of infrastructure code
Cause:
~/.claude/ not properly initialized
Solution:
# Verify global setup ls -la ~/.claude/commands/ ls -la ~/.claude/utils/ # Re-clone if needed rm -rf ~/.claude git clone https://gitlab.com/treyipune/global_claude_code_setup.git ~/.claude
Cause: SSH keys not configured
Solution:
cd ~/.claude git remote set-url origin https://gitlab.com/treyipune/global_claude_code_setup.git git push origin main
Cause: Project
./.claude/patches/ directory missing
Solution:
mkdir -p ./.claude/patches
Cause: SESSION.md doesn't exist or is malformed
Solution:
# Check SESSION.md cat ./.claude/SESSION.md # Copy template if missing cp ~/.claude/SESSION.md.template ./.claude/SESSION.md
Q: Do I need to manage
as a git repo?
A: Yes! It's already initialized as a git repo when cloned. Just keep it updated with ~/.claude/
git pull.
Q: Can I modify global commands for my projects? A: You can override them in
./.claude/commands/ locally, but improvements should be pushed to ~/.claude/ so all projects benefit.
Q: What if two projects need different command behavior? A: Create a project-local version in
./.claude/commands/ that overrides the global one. Better: fix the global version!
Q: How do I share this with other developers? A: They clone the same repository:
git clone https://gitlab.com/treyipune/global_claude_code_setup.git ~/.claude
Q: Is
version controlled in projects?
A: No! .claude/
./.claude/ (project-local) is typically gitignored. ~/.claude/ (global) IS version controlled.
Q: What's the difference between
and .claude/
?
A: ~/.claude/
./.claude/ = project-local state (SESSION.md, patches, notes)
~/.claude/ = global infrastructure (commands, utilities, documentation)
Q: Can I use this on Windows? A: These are bash scripts, so you'll need WSL2 or Git Bash. Not tested on Windows natively.
Q: How often should I pull updates? A: Whenever you start a new session or when significant improvements are merged. At minimum, monthly.
git clone https://gitlab.com/treyipune/global_claude_code_setup.git ~/.claudels ~/.claude/ shows all filesmkdir -p ./.claude/patches/project:resume in any project~/.claude/git commit -m "..."git push origin main && git push github mainutils/commands/| Document | Location | Purpose |
|---|---|---|
| Global Rules | | Universal standards (SOLID, clean code, model routing) |
| Platform Guide | | Complete infrastructure documentation |
| Session Template | | Standard project session format |
| This README | | Overview and usage guide |
Both are kept in sync. Use whichever fits your workflow.
These instructions and infrastructure are part of your personal development workflow. Use as needed across all your projects.
Refer to
PLATFORM_INFRASTRUCTURE.md for detailed documentation or check CLAUDE.md for specific rules.