Orchestrates git workflow for Python feature/release/hotfix development. Loads and coordinates other skills based on current context. Includes PR feedback handling via work-item generation. Use when: - User says "next step?" or "continue workflow" - Working in git repo with TODO_[feature|release|hotfix]_*.md files - Need to determine workflow phase and load appropriate skills - Handling PR feedback via work-items Triggers: next step, continue, what's next, workflow status, PR feedback Coordinates: tech-stack-adapter, git-workflow-manager, bmad-planner, speckit-author, quality-enforcer, workflow-utilities Context management: Prompt user to run /context when context usage is high, then /init to reset before continuing workflow.
Main coordinator for multi-branch git workflow. Detects current context and loads appropriate skills dynamically.
def detect_context():
"""Determine current workflow phase and required skills."""
import os
from pathlib import Path
# Get repository info
repo_root = Path(os.popen('git rev-parse --show-toplevel').read().strip())
current_dir = Path.cwd()
current_branch = os.popen('git branch --show-current').read().strip()
# Determine if in worktree
is_worktree = current_dir != repo_root
# Find TODO file
if is_worktree:
# Look for TODO in parent (main repo)
todo_pattern = '../TODO_*.md'
import glob
todos = glob.glob(str(current_dir / todo_pattern))
if todos:
todo_file = Path(todos[0]).name
workflow_type = todo_file.split('_')[1] # feature|release|hotfix
else:
return None, None, None
else:
# In main repo
import glob
todos = glob.glob(str(repo_root / 'TODO_*.md'))
if todos:
todo_file = Path(todos[0]).name
workflow_type = todo_file.split('_')[1]
else:
workflow_type = None
todo_file = None
return {
'repo_root': repo_root,
'current_dir': current_dir,
'current_branch': current_branch,
'is_worktree': is_worktree,
'workflow_type': workflow_type,
'todo_file': todo_file
}
When user says "next step?":
Always load tech-stack-adapter first (once per session)
Read tech-stack-adapter/SKILL.md
Execute: python tech-stack-adapter/scripts/detect_stack.py
Store: TEST_CMD, BUILD_CMD, COVERAGE_CMD, etc.
Detect context and load appropriate skills
context = detect_context()
if context['is_worktree']:
# In feature/release/hotfix worktree
if context['workflow_type'] in ['feature', 'release', 'hotfix']:
load_skill('speckit-author') # For spec.md, plan.md
load_skill('git-workflow-manager') # For commits, pushes
else:
# In main repo on contrib branch
if 'contrib' in context['current_branch']:
load_skill('bmad-planner') # For requirements, architecture
load_skill('git-workflow-manager') # For branch operations
# Always available for quality checks
load_skill('quality-enforcer') # When running tests, checking coverage
load_skill('workflow-utilities') # For utilities
Parse TODO file to determine current step
import yaml
from pathlib import Path
def parse_todo_file(todo_path):
"""Extract workflow progress from TODO file."""
content = Path(todo_path).read_text()
# Extract YAML frontmatter
if content.startswith('---'):
parts = content.split('---', 2)
frontmatter = yaml.safe_load(parts[1])
body = parts[2]
else:
return None
return {
'workflow_progress': frontmatter.get('workflow_progress', {}),
'quality_gates': frontmatter.get('quality_gates', {}),
'metadata': frontmatter.get('metadata', {})
}
Prompt user with next step
Next step from workflow:
Phase <N>, Step <N.M>: <description>
This will:
- <action 1>
- <action 2>
- <action 3>
Would you like to proceed? (Y/n)
Wait for explicit "Y" confirmation
Execute step using loaded skills
Skills loaded: tech-stack-adapter, git-workflow-manager, workflow-utilities
Interactive BMAD planning session:
Output: planning/<feature>/ directory with requirements.md, architecture.md, epics.md
Skills loaded: bmad-planner, workflow-utilities
Next: Create feature worktree and move to Phase 2
Step 2.1: Create feature worktree from contrib branch (git-workflow-manager)
Step 2.2: Switch to worktree directory
Step 2.3: Call SpecKit interactive tool
Invocation:
import subprocess
import sys
# Call create_specifications.py
result = subprocess.run([
'python',
'.claude/skills/speckit-author/scripts/create_specifications.py',
workflow_type, # feature, release, or hotfix
slug, # feature slug (e.g., my-feature)
gh_user, # GitHub username
'--todo-file', f'../TODO_{workflow_type}_{timestamp}_{slug}.md'
], check=True)
# Script handles:
# - BMAD context detection (../planning/<slug>/)
# - Interactive Q&A with user (5-15 questions)
# - Generates specs/<slug>/spec.md and plan.md
# - Creates compliant directory structure
# - Updates TODO_*.md with tasks from plan.md
# - Commits changes to feature branch
print("✓ SpecKit specifications created")
What SpecKit does:
Step 2.4: Implement code following spec.md
Step 2.5: Write tests targeting ≥80% coverage
Step 2.6: Create containers (if applicable)
Input from Phase 1: BMAD planning documents (requirements, architecture, epics) - optional but recommended
Output: Working implementation with tests, specs, and updated TODO
Skills used: speckit-author (callable tool), git-workflow-manager, quality-enforcer, workflow-utilities
Skills loaded: quality-enforcer, workflow-utilities
Step 4.1: Create PR from feature → contrib/<gh-user> (git-workflow-manager)
Step 4.2: Reviewers add comments and conversations in GitHub/Azure DevOps web portal
Step 4.3: Handle PR Feedback via Work-Items (Optional)
When to use:
Decision tree:
PR reviewed with comments
├─ Simple fixes (typos, formatting, minor adjustments)
│ └─ Fix directly on feature branch, push update, skip to Step 4.4
└─ Substantive changes (new features, refactoring, architecture changes)
└─ Generate work-items, continue to Step 4.3
Invocation:
import subprocess
# Generate work-items from unresolved PR conversations
result = subprocess.run([
'python',
'.claude/skills/git-workflow-manager/scripts/generate_work_items_from_pr.py',
pr_number # e.g., '94'
], check=True)
# Script outputs:
# ✓ Found 3 unresolved conversations
# ✓ Created work-item: pr-94-issue-1 (URL)
# ✓ Created work-item: pr-94-issue-2 (URL)
# ✓ Created work-item: pr-94-issue-3 (URL)
# For each work-item, repeat Phase 2-4:
# 1. Create feature worktree: create_worktree.py feature pr-94-issue-1 contrib/<user>
# 2. Implement fix (SpecKit optional for simple fixes)
# 3. Run quality gates
# 4. Create PR: feature/YYYYMMDDTHHMMSSZ_pr-94-issue-1 → contrib/<user>
# 5. Merge in web portal
# 6. Repeat for remaining work-items
What it does:
isResolved==false, Azure: status==active|pending)pr-{pr_number}-issue-{sequence}Benefits:
Step 4.4: User approves and merges PR in GitHub/Azure DevOps web portal
Step 4.5: Archive workflow and delete worktree
Step 4.6: Update BMAD planning with as-built details (optional but recommended)
Invocation:
import subprocess
# Call update_asbuilt.py from main repo on contrib branch
result = subprocess.run([
'python',
'.claude/skills/speckit-author/scripts/update_asbuilt.py',
f'planning/{slug}', # BMAD planning directory
f'specs/{slug}' # SpecKit specs directory
], check=True)
# Script handles:
# - Reads as-built specs from specs/<slug>/
# - Compares with original planning from planning/<slug>/
# - Interactive Q&A about deviations and metrics
# - Updates planning/ files with "As-Built" sections
# - Commits updates to contrib branch
print("✓ BMAD planning updated with as-built details")
print(" Feedback loop completed")
What update_asbuilt.py does:
Benefits:
Step 4.7: Rebase contrib/<gh-user> onto develop (git-workflow-manager)
Step 4.8: Create PR from contrib/<gh-user> → develop
Skills used: git-workflow-manager, speckit-author (update_asbuilt.py, optional)
Skills loaded: git-workflow-manager, quality-enforcer
Phase 1 produces:
planning/<feature>/
├── requirements.md # Business requirements, user stories, acceptance criteria
├── architecture.md # Technology stack, data models, API design
└── epics.md # Epic breakdown, priorities, dependencies
Create Worktree:
# Worktree creation preserves link to main repo
git worktree add ../repo_feature_<slug> feature/<timestamp>_<slug>
Phase 2 consumes:
# SpecKit reads from main repo
planning_context = {
'requirements': Path('../planning/<feature>/requirements.md').read_text(),
'architecture': Path('../planning/<feature>/architecture.md').read_text(),
'epics': Path('../planning/<feature>/epics.md').read_text()
}
# Uses context to generate
specs/<feature>/
├── spec.md # Detailed specification (informed by requirements + architecture)
└── plan.md # Implementation tasks (informed by epics + architecture)
Why this connection matters:
CRITICAL: Monitor context usage and enforce 100K token threshold.
def check_context_usage(current_tokens):
"""
Monitor context usage and trigger checkpoint at 100K tokens.
Effective capacity: ~136K tokens (200K - 64K overhead)
Checkpoint threshold: 100K tokens (~73% of effective capacity)
"""
CHECKPOINT_THRESHOLD = 100_000
if current_tokens >= CHECKPOINT_THRESHOLD:
print("\n⚠️ CONTEXT CHECKPOINT: 100K tokens reached")
print("\n📝 Saving workflow state...")
# 1. Update TODO_*.md with current state
update_todo_frontmatter(
phase=current_phase,
step=current_step,
last_task=last_completed_task,
status=current_status
)
# 2. Add context checkpoint entry
add_context_checkpoint(
token_usage=current_tokens,
phase=current_phase,
step=current_step,
notes=generate_status_summary()
)
# 3. Update task statuses
for task in all_tasks:
update_task_status(task.id, task.status)
# 4. Commit changes
git_commit("chore: context checkpoint at 100K tokens")
print("✓ State saved to TODO_*.md")
print("\n🔄 REQUIRED ACTIONS:")
print(" 1. Run: /init (updates CLAUDE.md memory files)")
print(" 2. Run: /compact (compresses memory buffer)")
print(" 3. Continue working - context preserved in TODO_*.md")
print("\nToken usage will be reduced after /init + /compact.")
return True # Triggers pause for user action
# Warn at 80K tokens (10K before checkpoint)
elif current_tokens >= 80_000:
print(f"\n⚠️ Context usage: {current_tokens:,} tokens")
print(" Approaching 100K checkpoint threshold")
print(" Recommendation: Complete current task before checkpoint")
return False
When checkpoint is triggered, save to TODO_*.md:
YAML Frontmatter:
workflow_progress.last_update: Current timestampworkflow_progress.last_task: Most recent task IDcontext_checkpoints[]: Add new checkpoint entrytasks[].status: Update to current state (pending/in_progress/completed)TODO Body:
After /init and /compact, token usage is reduced by:
User can then:
Claude will:
def prompt_for_confirmation(step_info):
"""Always wait for explicit Y before proceeding."""
print(f"\nNext step from workflow:")
print(f"Step {step_info['phase']}.{step_info['step']}: {step_info['description']}")
print(f"\nThis will:")
for action in step_info['actions']:
print(f" - {action}")
print(f"\nWould you like to proceed with Step {step_info['phase']}.{step_info['step']}? (Y/n)")
# WAIT for user response - do NOT proceed automatically
# Only continue if user types "Y"
Every directory must have:
CLAUDE.md - Context-specific guidanceREADME.md - Human-readable documentationARCHIVED/ subdirectory (except ARCHIVED itself)Use workflow-utilities/scripts/directory_structure.py to create compliant directories.
✓ Load orchestrator first, then relevant skills per phase ✓ Always wait for "Y" confirmation ✓ Monitor context via /context command ✓ Save state and /init when context > 50% ✓ Update TODO file after each step ✓ Commit changes with descriptive messages ✓ Use workflow-utilities for shared utilities