用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tools-only/X-Skills --skill ai-output-validation命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Index of Build Systems Skills
Coordination patterns for distributed dataflow systems including barriers, epochs, and distributed snapshots
Windowing, sessionization, time-series aggregation, and late data handling for streaming systems
基于 SOC 职业分类
正在显示 SKILL.md
| title | Production Safety Rules |
| description | Non-negotiable safety rules for teams deploying Claude Code in production environments |
| tags | ["security","guide","devops"] |
Audience: Teams deploying Claude Code in production environments. For solo learners: See Getting Started instead.
6 non-negotiable rules for production teams:
| Project Type | Use These Rules? | Why |
|---|---|---|
| Learning / Tutorials | ❌ No | Too restrictive for exploration |
| Solo prototypes | ❌ No | Overhead not worth it |
| Small teams (2-3), staging env | ⚠️ Partial | Rules 1, 3, 6 only |
| Production apps, multi-dev teams | ✅ Yes | All 6 rules |
| Regulated industries (HIPAA, SOC2) | ✅ Yes + add compliance rules | Critical safety |
Changing ports breaks:
Real incident: Backend port changed from 3000 → 8080 during refactor. All developers lost a day re-configuring local envs. Staging deployment failed silently because nginx proxy still pointed to 3000.
Never modify backend/frontend ports without explicit team permission.
Option A: Permission deny in settings.json
{
"permissions": {
"deny": [
"Edit(docker-compose.yml:*ports*)",
"Edit(package.json:*PORT*)",
"Edit(.env.example:*PORT*)",
"Edit(vite.config.ts:*port*)"
]
}
}
Option B: Pre-commit hook
# .claude/hooks/PreToolUse.sh
if [[ "$TOOL" == "Edit" ]]; then
FILE=$(echo "$INPUT" | jq -r '.tool.input.file_path')
CONTENT=$(echo "$INPUT" | jq -r '.tool.input.new_string')
if [[ "$FILE" =~ (docker-compose|vite.config|package.json) ]] && \
[[ "$CONTENT" =~ (port|PORT):[[:space:]]*[0-9] ]]; then
echo "⚠️ BLOCKED: Port modification detected in $FILE"
echo "Ports must remain stable across team. Request permission first."
exit 2
fi
fi
Option C: CLAUDE.md constraint
## Port Configuration
**CRITICAL**: Ports are locked for team coordination.
Current ports:
- Frontend (Vite): 5173
- Backend (Express): 3000
- Database: 5432
To change ports:
1. Create RFC document in `/docs/rfcs/`
2. Get team approval (3+ reviewers)
3. Update all environments simultaneously
4. Notify team 48h in advance
| Scenario | Behavior |
|---|---|
| Adding NEW service | OK (doesn't break existing) |
| Changing test env port | OK (isolated from dev/prod) |
| Port conflict on machine | Ask user to resolve locally (.env.local) |
Accidental deletions in production = data loss.
Real incidents:
DELETE FROM users WHERE id = 123 → Forgot WHERE → All users deletedDROP TABLE sessions during cleanup → Production table droppedAlways backup before destructive operations.
Destructive operations:
DELETE FROM (without LIMIT 1)DROP TABLETRUNCATEALTER TABLE ... DROP COLUMNOption A: Pre-tool hook with backup enforcement
# .claude/hooks/PreToolUse.sh
#!/bin/bash
INPUT=$(cat)
TOOL=$(echo "$INPUT" | jq -r '.tool.name')
if [[ "$TOOL" == "Bash" ]]; then
COMMAND=$(echo "$INPUT" | jq -r '.tool.input.command')
# Detect destructive database operations
if [[ "$COMMAND" =~ (DROP TABLE|DELETE FROM|TRUNCATE|ALTER.*DROP) ]]; then
echo "🚨 BLOCKED: Destructive database operation detected"
echo ""
echo "Required steps:"
echo "1. Create backup: pg_dump -U user dbname > backup_\$(date +%Y%m%d_%H%M%S).sql"
echo "2. Verify backup size is reasonable"
echo "3. Re-run after backup confirmation"
exit 2
fi
fi
exit 0
Option B: Migration safety wrapper
# scripts/safe-migrate.sh
#!/bin/bash
set -e
echo "🔍 Pre-migration checks..."
# 1. Check environment
if [[ "$NODE_ENV" == "production" ]]; then
echo "❌ BLOCKED: Use migration service for production"
exit 1
fi
# 2. Create backup
BACKUP_FILE="backups/pre-migration-$(date +%Y%m%d_%H%M%S).sql"
mkdir -p backups
pg_dump $DATABASE_URL > "$BACKUP_FILE"
echo "✅ Backup created: $BACKUP_FILE"
# 3. Run migration
echo "🚀 Running migration..."
npm run prisma:migrate:dev
# 4. Verify
echo "🔍 Verifying database state..."
npm run prisma:validate
echo "✅ Migration complete. Backup: $BACKUP_FILE"
Option C: CLAUDE.md protocol
## Database Operations
### Destructive Operations Protocol
**NEVER run these without backup**:
- DELETE, DROP, TRUNCATE, ALTER...DROP
**Required steps**:
1. Announce in #dev-ops Slack channel
2. Create backup: `./scripts/backup-db.sh`
3. Verify backup: `ls -lh backups/` (should be >0 bytes)
4. Execute in staging FIRST
5. Wait 24h for issues
6. Execute in production with on-call engineer present
**Emergency rollback**:
```bash
psql $DATABASE_URL < backups/[latest].sql
### MCP Database Safety
If using MCP database servers (Postgres, MySQL, etc.):
```json
{
"mcpServers": {
"database": {
"command": "npx",
"args": ["@modelcontextprotocol/server-postgres"],
"env": {
"POSTGRES_URL": "postgres://readonly:***@dev-db.example.com:5432/appdb"
},
"comment": "READ-ONLY user for safety"
}
}
}
Critical: Use read-only database users for MCP. See Data Privacy Guide.
Claude Code sometimes "half-asses" features when context runs low:
TODO comments for core featuresReal incidents:
throw new Error("Not implemented")// TODO: Add actual logic hereNever ship half-implemented features. If you start, you finish to working state.
Option A: CLAUDE.md constraint
## Feature Implementation Standards
### NON-NEGOTIABLE
1. **No TODOs for core functionality**
- TODOs allowed ONLY for future enhancements
- Core features must be complete and working
2. **No mock implementations**
- No `throw new Error("Not implemented")`
- No fake data generators in production code paths
3. **Complete error handling**
- Every async call has try/catch
- Every user input is validated
- Every API call has timeout and retry logic
4. **Downgrade = Delete the feature entirely**
- If you can't fix properly, remove the feature
- Document why in commit message
- Create issue for proper implementation
### Validation
Before accepting changes, verify:
- [ ] No `TODO` in modified files (except future enhancements)
- [ ] No `throw new Error("Not implemented")`
- [ ] No commented-out code without explanation
- [ ] All new functions have error handling
Option B: Pre-commit git hook
# .git/hooks/pre-commit
#!/bin/bash
# Check staged files for "half-assing" patterns
STAGED=$(git diff --cached --name-only --diff-filter=ACM)
for FILE in $STAGED; do
if [[ "$FILE" =~ \.(ts|tsx|js|jsx|py)$ ]]; then
# Check for TODOs in core logic (not tests)
if ! [[ "$FILE" =~ test|spec ]]; then
if git diff --cached "$FILE" | grep -E "^\+.*TODO.*implement|^\+.*Not implemented"; then
echo "❌ COMMIT BLOCKED: TODO/Not implemented in $FILE"
echo " Complete the feature or remove it entirely."
exit 1
fi
fi
# Check for mock placeholders
if git diff --cached "$FILE" | grep -E "^\+.*(MOCK_DATA|fakeData|placeholder)"; then
echo "⚠️ WARNING: Mock data detected in $FILE"
echo " Ensure this is intentional for staging/dev only."
fi
fi
done
exit 0
Option C: Output evaluator command
# Before committing
/validate-changes
# This runs the output-evaluator agent (see examples/agents/output-evaluator.md)
# which scores changes on:
# - Correctness (10/10)
# - Completeness (10/10) ← Detects half-assing
# - Safety (10/10)
Claude might modify infrastructure configs without understanding production implications:
.env.example → breaks onboardingInfrastructure modifications require explicit team permission.
Files to protect:
docker-compose.yml, Dockerfile.env.example (templates, NOT personal .env.local)kubernetes/, k8s/, terraform/, helm/.github/workflows/, .gitlab-ci.yml)Option A: Permission deny
{
"permissions": {
"deny": [
"Edit(docker-compose.yml)",
"Edit(Dockerfile)",
"Edit(.env.example)",
"Edit(terraform/**)",
"Edit(kubernetes/**)",
"Edit(.github/workflows/**)",
"Edit(prisma/schema.prisma)"
]
}
}
Option B: CLAUDE.md rule
## Infrastructure Changes
You are **FORBIDDEN** from modifying these without explicit permission:
- `docker-compose.yml`, `Dockerfile`
- `.env.example` (template for new developers)
- `terraform/`, `kubernetes/` (infrastructure as code)
- `.github/workflows/` (CI/CD pipelines)
- `prisma/schema.prisma` (database schema)
**If infrastructure change is needed**:
1. Ask user: "This requires infrastructure change. Should I create an RFC?"
2. Create RFC document in `docs/rfcs/YYYYMMDD-<title>.md`
3. Do NOT modify files until RFC approved
Note: Personal .env.local files are OK to modify (they're gitignored).
Adding dependencies without team approval:
Real incidents:
moment.js (200KB) when date-fns (tiny) already in projectlodash when project uses ramdaNo new dependencies without explicit approval.
Option A: Permission deny on package managers
{
"permissions": {
"deny": [
"Bash(npm install *)",
"Bash(npm i *)",
"Bash(pnpm add *)",
"Bash(yarn add *)",
"Bash(pip install *)",
"Bash(poetry add *)"
],
"allow": [
"Bash(npm install)",
"Bash(pnpm install)",
"Bash(pip install -r requirements.txt)"
]
}
}
Option B: CLAUDE.md protocol
## Dependency Management
### Immutable Stack Rule
**You are FORBIDDEN from adding new dependencies** (`npm install <package>`).
**If new dependency is needed**:
1. Check if existing dependency solves it:
- Date manipulation? Use existing `date-fns`
- HTTP requests? Use existing `axios`
- State management? Use existing `zustand`
2. If genuinely needed, ASK:
- "I need [package] for [reason]. Existing alternatives: [X, Y]. Should I add it?"
3. Wait for explicit approval
4. User will run: `npm install <package>` manually
**Allowed without asking**:
- `npm install` (installs existing package.json deps)
- Dev dependencies for testing (`-D` flag after approval)
Option C: Pre-tool hook
# .claude/hooks/PreToolUse.sh
if [[ "$TOOL" == "Bash" ]]; then
COMMAND=$(echo "$INPUT" | jq -r '.tool.input.command')
# Block dependency installation
if [[ "$COMMAND" =~ (npm|pnpm|yarn)[[:space:]]+(install|add|i)[[:space:]]+[a-zA-Z] ]]; then
echo "🚨 BLOCKED: New dependency installation"
echo ""
echo "Dependencies must be approved by team lead."
echo "Create PR with RFC explaining:"
echo "1. Why this dependency is needed"
echo "2. Alternatives considered"
echo "3. Bundle size impact"
echo "4. License compatibility"
exit 2
fi
# Allow: npm install (no args), npm install -g, pnpm install
if [[ "$COMMAND" =~ ^(npm|pnpm|yarn)[[:space:]]+install$ ]]; then
exit 0
fi
fi
Claude introduces new patterns inconsistent with codebase:
class components when project is functional Reactlodash when project uses ramdafetch when project standardized on axiosConform to existing codebase conventions. Check before implementing.
Option A: CLAUDE.md conventions
## Code Conventions
### Tech Stack (DO NOT DEVIATE)
**Frontend**:
- React 18 with **function components + hooks** (NO class components)
- State: Zustand (NOT Redux, Context)
- HTTP: axios (NOT fetch)
- Styling: Tailwind CSS (NOT styled-components, emotion)
- Forms: React Hook Form + Zod
**Backend**:
- Node.js + Express
- Database: Prisma ORM (NOT raw SQL, TypeORM)
- Auth: JWT via jose library
- Validation: Zod schemas
**Testing**:
- Unit: Vitest (NOT Jest)
- E2E: Playwright (NOT Cypress)
### Import Patterns
**Always use**:
```typescript
import { useState } from 'react' // ✅ Named imports
import axios from 'axios' // ✅ Default import
Never use:
import React from 'react' // ❌ Deprecated pattern
import * as axios from 'axios' // ❌ Namespace import
src/
features/ ← Group by feature (NOT by type)
auth/
components/
hooks/
api/
shared/ ← Shared utilities
components/
hooks/
UI changes MUST use existing design system:
src/shared/components/ for existing componentstailwind.config.jscolors.ts palette ONLYtypography.config.jsBefore creating new component:
rg "Button" src/shared/components/
**Option B: Pre-implementation analysis**
```markdown
## Before Implementing
**ALWAYS** run these checks:
1. **Pattern check**:
```bash
# How does codebase handle X?
rg "import.*useState" src/ # Check React patterns
rg "axios\." src/ # Check HTTP patterns
rg "prisma\." src/ # Check DB patterns
# Does component already exist?
find src/shared/components -name "*Button*"
find src/shared/components -name "*Modal*"
**Option C: Automated validation**
```bash
# .claude/hooks/PostToolUse.sh
#!/bin/bash
if [[ "$TOOL" == "Write" ]] || [[ "$TOOL" == "Edit" ]]; then
FILE=$(echo "$INPUT" | jq -r '.tool.input.file_path')
# Check for pattern violations
if [[ "$FILE" =~ \.(tsx?)$ ]]; then
CONTENT=$(cat "$FILE")
# Violation: class components in React
if echo "$CONTENT" | grep -q "class.*extends.*Component"; then
echo "⚠️ WARNING: Class component detected in $FILE"
echo " Project uses function components. Consider refactoring."
fi
# Violation: wrong HTTP library
if echo "$CONTENT" | grep -q "import.*fetch\|window.fetch"; then
echo "⚠️ WARNING: fetch() detected in $FILE"
echo " Project uses axios. Use: import axios from 'axios'"
fi
fi
fi
When AI succeeds 99% of the time, traditional human verification becomes fragile:
The paradox: As AI reliability increases, human review quality decreases.
Real incidents:
Source: Alan Engineering Team (Charles Gorintin, Maxime Le Bras), Feb 2026
Build automated safety systems instead of relying on human vigilance.
When AI reliability crosses ~95%, shift from manual review to automated guardrails.
| Anti-Pattern | Better Approach |
|---|---|
| Manual review for every AI output | Automated test suites + selective review |
| Trust because "it worked last time" | Verification contracts (tests, types, lints) |
| Human as sole error detector | Guardrails that fail fast (CI/CD gates) |
| "Spot-check" strategy for high-frequency AI ops | Comprehensive automated validation |
| Reviewer fatigue = lower standards over time | Consistent automated quality bars |
Option A: Automated Guardrail Stack
# .github/workflows/ai-safety.yml
name: AI Output Validation
on: [pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Type safety
run: npm run typecheck # Catch type errors AI missed
- name: Lint rules
run: npm run lint # Enforce code standards
- name: Unit tests
run: npm run test # Verify behavior contracts
- name: E2E tests
run: npm run test:e2e # Catch integration failures
- name: Security audit
run: npm audit # Detect vulnerable dependencies
Option B: Verification Contracts in CLAUDE.md
## Verification Protocol
### NEVER rely on human review alone
**Automated verification required**:
1. **Type safety**: `npm run typecheck` must pass (zero errors)
2. **Tests**: `npm run test` coverage ≥ 80% for new code
3. **Lint**: `npm run lint` must pass (zero warnings)
4. **Security**: `npm audit` must show zero high/critical vulnerabilities
5. **Performance**: Lighthouse score ≥ 90 for affected pages
**Human review is for**:
- Architecture decisions
- UX/design choices
- Business logic validation
- Edge cases automation can't catch
**Human review is NOT for**:
- Syntax errors (use linters)
- Type errors (use TypeScript)
- Performance regressions (use benchmarks)
- Security issues (use automated scanners)
Option C: Pre-merge checklist (automated)
# .claude/hooks/PreCommit.sh
#!/bin/bash
echo "🔍 Running automated verification (Verification Paradox defense)..."
# 1. Type safety
npm run typecheck || { echo "❌ Type errors detected"; exit 1; }
# 2. Lint
npm run lint || { echo "❌ Lint errors detected"; exit 1; }
# 3. Tests
npm run test || { echo "❌ Tests failing"; exit 1; }
# 4. Security
npm audit --audit-level=high || { echo "❌ Security vulnerabilities detected"; exit 1; }
echo "✅ All automated checks passed"
echo "💡 Human review can now focus on architecture/UX/business logic"
| Scenario | Behavior |
|---|---|
| AI writes perfect code 99.9% | STILL run automation (paradox applies even at 99.9%) |
| Time pressure, "just ship it" | Automation is non-negotiable (fast ≠ skip safety) |
| Trivial changes (typo fix) | Run automation (typos can break prod) |
| Emergency hotfix | Automation REQUIRED (stress = higher error rate) |
Old model (pre-AI):
New model (AI-assisted):
Solution: Automate the boring verification (syntax, types, tests), reserve human attention for creative/strategic review.
# Before multi-file changes
/plan
# Claude enters read-only mode, explores codebase
# Identifies patterns, conventions, existing implementations
# Proposes plan following project conventions
# You review before execution
These rules integrate with existing git workflows:
# .git/hooks/pre-commit
#!/bin/bash
# Run safety checks
./.claude/hooks/production-safety-check.sh
# If blocked, commit fails
exit $?
Add validation step:
# .github/workflows/pr-validation.yml
name: PR Validation
on: [pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check for half-assing
run: |
if git diff origin/main...HEAD | grep -E "TODO.*implement|Not implemented"; then
echo "❌ PR contains incomplete features"
exit 1
fi
- name: Check for unauthorized deps
run: |
git diff origin/main...HEAD -- package.json | grep -E '^\+.*"[^"]+": "[^"]+"' || exit 0
echo "⚠️ New dependencies detected. Review required."
Solution: Adapt based on your team size and stage.
| Team Size | Recommended Rules |
|---|---|
| 1-2 devs | Rules 1, 3, 6 only |
| 3-10 devs | Rules 1, 3, 5, 6 |
| 10+ devs or production | All 6 rules |
Solution: Rules are working! Options:
Grant temporary permission:
# In CLAUDE.md
## Temporary Override (expires 2026-01-25)
For this feature only: infrastructure changes allowed.
Reason: Setting up new microservice.
Create exception:
{
"permissions": {
"allow": ["Edit(docker-compose.dev.yml)"],
"deny": ["Edit(docker-compose.prod.yml)"]
}
}
Review if rule is appropriate:
Solution: Commit to repo, not personal config.
# Shared team rules
/project/.claude/settings.json # Committed
/project/CLAUDE.md # Committed
# Personal overrides
/project/.claude/settings.local.json # Gitignored
/project/.claude/CLAUDE.md # Gitignored
Team settings take precedence, but individuals can opt-in to stricter rules.
| Rule | Severity | Breaking this causes |
|---|---|---|
| 1. Port Stability | 🔴 Critical | Team downtime, deployment failures |
| 2. Database Safety | 🔴 Critical | Data loss, customer impact |
| 3. Feature Completeness | 🟡 High | Production bugs, tech debt |
| 4. Infrastructure Lock | 🟠 High | Downtime, security issues |
| 5. Dependency Safety | 🟡 Medium | Bundle bloat, license issues |
| 6. Pattern Following | 🟢 Low | Code inconsistency, maintenance burden |
| Method | Strictness | Setup Time | Best For |
|---|---|---|---|
| Permission deny | 100% (blocks) | 2 min | Critical rules (1, 2, 4) |
| Pre-tool hooks | 100% (blocks) | 10 min | Custom logic, team-specific |
| CLAUDE.md rules | ~70% (Claude respects) | 5 min | Conventions, guidelines |
| Post-tool warnings | ~30% (warns only) | 5 min | Best practices, suggestions |
| Git hooks | 100% (blocks commits) | 15 min | Final safety net before push |
Allow staging changes, block production:
{
"permissions": {
"allow": ["Edit(docker-compose.dev.yml)"],
"deny": ["Edit(docker-compose.prod.yml)"]
}
}
Require confirmation for sensitive ops:
{
"permissions": {
"ask": ["Bash(rm -rf *)", "Bash(DROP TABLE *)"]
}
}
Temporary override with expiry:
## Temporary Override (expires 2026-02-01)
Infrastructure changes allowed for migration project.
After expiry: revert to standard rules.
Version: 1.0.0 Last Updated: 2026-01-21 Changelog: Initial version based on community-validated production patterns