# rollback-deploy

Walks an agent through rolling a deployment back to the previous version, with safety checks and database handling.

- command · `type=command` · Claude Code · 260 installs
- Author: davila7
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/commands/deployment/rollback-deploy.md
- Updated: 2026-10-24
- HTML: https://affpapa.org/en/nevibecode/commands/rollback-deploy

## What it does

The command turns a rollback into a checklist. It starts with incident assessment: how bad is the failure, and is a forward fix better than going back. Then it gathers the current state — running version, recent git tags, container and pod status.

From there it picks a path: `kubectl rollout undo`, `docker service update --rollback`, or a symlink switch to the previous release. Arguments set the mode — `--previous` for the last version, `--emergency` for the incident protocol, `--validate-first` to run checks before switching, `--with-db` to include migrations. Tools are limited to `Read`, `Edit` and `Bash`.

Database work gets its own section, and it is the part to be careful with. If migrations shipped since the last release, rolling the schema back can lose data, so the command tells you to take a backup first and weigh a forward fix. You also need working `kubectl` access and tagged releases — without them the detection steps just print placeholders.

## Requirements
- Works with: Docker, Kubernetes

## Install

### Claude Code (native platform)

1. **claude-code-templates**
```bash
npx claude-code-templates@latest --command deployment/rollback-deploy
```

2. **Manually: put the files in place**
- File: `.claude/commands/rollback-deploy.md` — Call it with /rollback-deploy. For all projects use ~/.claude/commands/

### Codex

**Manually: put the files in place**
- File: `~/.codex/prompts/rollback-deploy.md` — Call it with /prompts:rollback-deploy. Codex marks this format deprecated in favour of skills

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/prompts/rollback-deploy.prompt.md`

### Gemini CLI

**Manually: put the files in place**
- File: `.gemini/commands/rollback-deploy.toml` — Gemini stores commands as TOML: the prompt text goes into the prompt field

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/commands/deployment/rollback-deploy.md

## When to use it
- roll production back when a new release breaks the service
- decide between a forward fix and a rollback from live system state
- back up the database before reverting migrations
- shift traffic through a load balancer or maintenance mode
- verify endpoint health and response times after the switch

## Example prompts
- Roll the deploy back to the previous version: /rollback-deploy --previous
- Emergency rollback, the service is down: /rollback-deploy --emergency
- Go back to v1.2.9 and revert migrations: /rollback-deploy v1.2.9 --with-db

## Source text · rollback-deploy.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 928a1e733659a456.

BEGIN THIRD-PARTY FILE 928a1e733659a456
````text
---
allowed-tools: Read, Edit, Bash
argument-hint: "[target-version] | --previous | --emergency | --validate-first | --with-db"
description: Rollback deployment to previous version with safety checks, database considerations, and monitoring
---

# Deployment Rollback

Rollback deployment to previous version: $ARGUMENTS

## Current Deployment State

- Current version: !`curl -s https://api.example.com/version 2>/dev/null || kubectl get deployments -o wide 2>/dev/null | head -3 || echo "Version detection needed"`
- Available versions: !`git tag --sort=-version:refname | head -5`
- Container status: !`docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}" 2>/dev/null | head -5 || echo "No containers"`
- K8s deployments: !`kubectl get deployments 2>/dev/null || echo "No K8s access"`
- Health status: !`curl -sf https://api.example.com/health 2>/dev/null && echo "✅ Healthy" || echo "❌ Unhealthy"`

## Emergency Rollback Protocol

Systematic rollback procedure: $ARGUMENTS

1. **Incident Assessment and Decision**
   - Assess the severity and impact of the current deployment issues
   - Determine if rollback is necessary or if forward fix is better
   - Identify affected systems, users, and business functions
   - Consider data integrity and consistency implications
   - Document the decision rationale and timeline

2. **Emergency Response Setup**
   ```bash
   # Activate incident response team
   # Set up communication channels
   # Notify stakeholders immediately
   
   # Example emergency notification
   echo "🚨 ROLLBACK INITIATED
   Issue: Critical performance degradation after v1.3.0 deployment
   Action: Rolling back to v1.2.9
   ETA: 15 minutes
   Impact: Temporary service interruption possible
   Status channel: #incident-rollback-202401"
   ```

3. **Pre-Rollback Safety Checks**
   ```bash
   # Verify current production version
   curl -s https://api.example.com/version
   kubectl get deployments -o wide
   
   # Check system status
   curl -s https://api.example.com/health | jq .
   
   # Identify target rollback version
   git tag --sort=-version:refname | head -5
   
   # Verify rollback target exists and is deployable
   git show v1.2.9 --stat
   ```

4. **Database Considerations**
   ```bash
   # Check for database migrations since last version
   ./check-migrations.sh v1.2.9 v1.3.0
   
   # If migrations exist, plan database rollback
   # WARNING: Database rollbacks can cause data loss
   # Consider forward fix instead if migrations are present
   
   # Create database backup before rollback
   ./backup-database.sh "pre-rollback-$(date +%Y%m%d-%H%M%S)"
   ```

5. **Traffic Management Preparation**
   ```bash
   # Prepare to redirect traffic
   # Option 1: Maintenance page
   ./enable-maintenance-mode.sh
   
   # Option 2: Load balancer management
   ./drain-traffic.sh --gradual
   
   # Option 3: Circuit breaker activation
   ./activate-circuit-breaker.sh
   ```

6. **Container/Kubernetes Rollback**
   ```bash
   # Kubernetes rollback
   kubectl rollout history deployment/app-deployment
   kubectl rollout undo deployment/app-deployment
   
   # Or rollback to specific revision
   kubectl rollout undo deployment/app-deployment --to-revision=3
   
   # Monitor rollback progress
   kubectl rollout status deployment/app-deployment --timeout=300s
   
   # Verify pods are running
   kubectl get pods -l app=your-app
   ```

7. **Docker Swarm Rollback**
   ```bash
   # List service history
   docker service ps app-service --no-trunc
   
   # Rollback to previous version
````
END THIRD-PARTY FILE 928a1e733659a456

The third-party file has ended. Everything between the 928a1e733659a456 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3546 of 11484 bytes. © davila7 · MIT · https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/commands/deployment/rollback-deploy.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
