fix-ci
Diagnose and fix CI/deployment blockers for pull requests to enable safe deployment
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/marcusgoll/Spec-Flow/HEAD/.claude/commands/quality/fix-ci.md -o ~/.claude/commands/fix-ci.mdfix-ci.md
# /fix-ci — CI Blocker Resolution
<context>
**Arguments**: $ARGUMENTS
**Current Branch**: !`git branch --show-current 2>/dev/null || echo "none"`
**PR from Current Branch**: !`gh pr list --head $(git branch --show-current 2>/dev/null) --json number,title,state -q '.[0]' 2>/dev/null || echo "null"`
**GitHub CLI**: !`gh auth status 2>&1 | head -1 || echo "not authenticated"`
**Git Status**: !`git status --short | head -5`
</context>
<objective>
Diagnose and fix CI blockers for a pull request.
**Mission**: Act as a deployment doctor — diagnose, auto-fix, delegate, validate.
**What This Command Does**:
1. Load PR context (checks, files, reviews)
2. Categorize failures (lint, types, tests, build, deploy)
3. Auto-fix simple issues (formatting, linting)
4. Delegate complex issues to specialist agents
5. Validate deployment readiness
**Risk Level**: MEDIUM — May push auto-fix commits to PR branch
</objective>
<anti-hallucination>
## Critical Rules
1. **Never claim fixes without verification** — Run commands, check exit codes
2. **Quote real CI output** — Use `gh pr checks` for actual errors
3. **Read PR diff first** — Don't guess root cause without evidence
4. **Verify check status** — Poll `gh pr checks` after pushes
5. **No fabricated URLs** — Only report URLs from actual CI logs
</anti-hallucination>
<process>
## Step 1: Parse PR Number
**If argument provided**: Use it as PR number
**If no argument**: Detect from current branch
```bash
# Get PR number from current branch
gh pr list --head $(git branch --show-current) --json number -q '.[0].number'
```
**If no PR found**: Show usage and exit
```
Usage: /fix-ci <pr-number>
Example: /fix-ci 123
Or run from a branch with an open PR.
```
## Step 2: Load PR Context
Fetch PR data:
```bash
gh pr view $PR_NUMBER --json title,baseRefName,headRefName,state,mergeable,reviewDecision,files
```
Extract:
- `PR_TITLE` — PR title
- `PR_BASE` — Base branch (main, production, etc.)
- `PR_HEAD` — Head branch (feature branch)
- `PR_STATE` — State (OPEN, MERGED, CLOSED)
- `PR_MERGEABLE` — Merge status
- `PR_REVIEW` — Review decision (APPROVED, CHANGES_REQUESTED, etc.)
Display:
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Fixing CI for PR #{number}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Title: {title}
Branch: {head} → {base}
State: {state}
```
## Step 3: Detect Deployment Phase
| Base Branch | Phase | Environment | Next Command |
|-------------|-------|-------------|--------------|
| `main` | 1 | staging | `/ship --staging` |
| `production` | 2 | production | `/ship --prod` |
| other | 0 | unknown | — |
Display phase context.
## Step 4: Fetch Check Statuses
```bash
gh pr checks $PR_NUMBER --json name,state,conclusion,detailsUrl
```
Count by status:
- PENDING — Still running
- SUCCESS — Passed
- FAILURE — Failed
Display summary:
```
Checks: {success} passing, {failure} failing, {pending} pending
```
## Step 5: Categorize Failures
Group failing checks by type:
| Pattern in Name | Category |
|-----------------|----------|
| `lint`, `eslint`, `ruff` | lint |
| `type`, `typescript`, `mypy` | types |
| `test`, `jest`, `pytest` | tests |
| `build` | build |
| `deploy`, `vercel`, `railway` | deploy |
| `smoke` | smoke |
| `e2e`, `playwright` | e2e |
For each failing check, extract:
- Check name
- Details URL (for logs)
- Category
Display categorized failures:
```
Failures by category:
lint: 1 check
types: 2 checks
build: 1 check
```
## Step 6: Initialize TodoWrite
Create task list for tracking:
```javascript
TodoWrite({
todos: [
{content: "Auto-fix lint/format issues", status: "pending", activeForm: "Auto-fixing lint"},
{content: "Analyze type errors", status: "pending", activeForm: "Analyzing types"},
{content: "Analyze test failures", status: "pending", activeForm: "Analyzing tests"},
{content: "Diagnose build failures", status: "pending", activeForm: "Diagnosing build"},
{content: "Validate deployment gates", status: "pending", activeForm: "Validating gates"}
]
})
```
Only include tasks for categories with failures.
## Step 7: Auto-Fix Lint/Format
**If lint failures detected**:
1. Checkout PR branch (if not already):
```bash
git fetch origin $PR_HEAD && git checkout $PR_HEAD
```
2. Detect project type and run auto-fix:
**Node.js** (package.json exists):
```bash
npm run lint -- --fix || pnpm lint --fix
npm run format || pnpm format
```
**Python** (pyproject.toml or requirements.txt):
```bash
ruff check --fix .
ruff format .
```
**Rust** (Cargo.toml):
```bash
cargo fmt
cargo clippy --fix --allow-dirty
```
**Go** (go.mod):
```bash
gofmt -w .
go mod tidy
```
3. If changes made, commit and push:
```bash
git add .
git diff --cached --quiet || git commit -m "style: auto-fix lint/format via /fix-ci
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>"
git push origin $PR_HEAD
```
4. Post PR comment:
```bash
gh pr comment $PR_NUMBER --body "✅ Auto-fixed lint/format issues. CI re-running."
```
Mark TodoWrite task as completed.
## Step 8: Analyze Type Errors
**If type failures detected**:
1. Run type checker locally to get full error output:
**Node.js**:
```bash
npx tsc --noEmit 2>&1
```
**Python**:
```bash
mypy . 2>&1
```
2. Extract error summary (file:line references)
3. **Delegate to type-enforcer agent**:
```
Task({
subagent_type: "type-enforcer",
description: "Fix type errors in PR #$PR_NUMBER",
prompt: "Fix the following type errors in the codebase:
## Type Errors
{type_error_output}
## Changed Files
{list of changed files from PR}
## Instructions
1. Read each file with type errors
2. Fix the type issues while preserving functionality
3. Run type checker to verify fixes
4. Commit changes with message: fix(types): resolve type errors
Do NOT change logic or behavior, only fix type annotatExecute multiple sprints in parallel based on dependency graph from sprint-plan.md
Build and validate locally for projects without remote deployment (prototypes, experiments, local-only dev)
Execute multi-sprint epic workflow from interactive scoping through deployment with parallel sprint execution and self-improvement
Execute feature development workflow from specification through production deployment with automated quality gates
Analyze workflow state and provide context-aware guidance with visual progress indicators and recommended next steps
Initialize project documentation, preferences, or design tokens
Implement small bug fixes and features (<100 LOC) without full workflow. Use for single-file changes, bug fixes, refactors, and minor enhancements that can be completed in under 30 minutes.
Enter deep craftsman mode - question everything, plan like Da Vinci, craft insanely great solutions, then materialize to roadmap