safe-edit
Automatically backs up files, saves diffs, uses agents/skills, and ensures modular code (<200 lines) before any implementation. Use this skill for ALL code changes to ensure safe, reversible, and clean implementations.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o safe-edit.zip https://jpskill.com/download/18886.zip && unzip -o safe-edit.zip && rm safe-edit.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/18886.zip -OutFile "$d\safe-edit.zip"; Expand-Archive "$d\safe-edit.zip" -DestinationPath $d -Force; ri "$d\safe-edit.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
safe-edit.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
safe-editフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 2
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Safe Edit スキル
概要
安全で、元に戻せる、クリーンなコード実装のための包括的なワークフロー自動化です。このスキルは、すべてのコード変更がベストプラクティスに従うことを保証します。自動バックアップ、差分追跡、エージェントの活用、モジュラーアーキテクチャの強制などです。
使用する場面
コード実装の前に、必ずこのスキルを有効化してください。
- ファイルの変更(作成、更新、削除)
- 機能実装
- バグ修正
- リファクタリング
- UI/UX の変更
- API の変更
- データベーススキーマの更新
ユーザーによるトリガー(自動アクティベーション):
- 明示的なバックアップの言及がない実装リクエスト
- "implement", "add", "create", "fix", "update", "change"
- コード関連のタスク全般
コアワークフロー
フェーズ 1: 実装前の分析
1. タスクの複雑さと範囲を分析する
2. 影響を受けるファイルとモジュールを特定する
3. エージェント/スキルが役立つか確認する
4. モジュラーアーキテクチャを計画する(200行を超える場合)
5. 追跡用の TODO リストを作成する
フェーズ 2: バックアップと安全性
1. .backups/ にタイムスタンプ付きバックアップを作成する
2. git diff を生成する(/tmp/diffs/ に保存)
3. ロールバックコマンドを文書化する
4. バックアップの整合性を検証する
フェーズ 3: 実装
1. 適切なエージェント/スキルを使用する
2. モジュラーチャンクで実装する(200行未満)
3. 既存のパターンに従う
4. TODO の進捗を更新する
フェーズ 4: 検証
1. 最終差分を生成する
2. 型チェックを実行する(TypeScript の場合)
3. ビルドをテストする(該当する場合)
4. 変更点を文書化する
バックアップ管理
ディレクトリ構造
.backups/
├── YYYY-MM-DD/
│ ├── HH-MM-SS_{filename}.backup
│ └── HH-MM-SS_{filename}.backup
└── ROLLBACK_GUIDE.md
/tmp/diffs/
├── YYYY-MM-DD_HH-MM-SS_{description}.patch
└── latest.patch
バックアップの命名規則
形式: {timestamp}_{original_path_with_underscores}.backup
例:
2025-10-24_13-45-30_app_pricing_page.tsx.backup
2025-10-24_13-45-30_components_editor_EditorContainer.tsx.backup
差分の命名規則
形式: YYYY-MM-DD_HH-MM-SS_{feature_description}.patch
例:
2025-10-24_13-45-30_add-footer-links.patch
2025-10-24_14-20-15_pricing-policy-update.patch
自動モジュール化
ファイルが200行を超える場合
検出:
- 実装前の行数をカウントする
- 変更後の最終的なサイズを予測する
- 200行に近づいている場合は警告する
アクションプラン:
- コンポーネントの責務を分析する
- 抽出可能なロジックを特定する
- モジュラー構造を作成する
- 別々のファイルに実装する
- インポート/エクスポートを更新する
リファクタリング例:
Original: EditorContainer.tsx (450 lines)
↓
Modularized:
- EditorContainer.tsx (180 lines) - メインレイアウト
- hooks/useEditorState.ts (80 lines) - 状態管理
- hooks/useKeyboardShortcuts.ts (60 lines) - キーボードロジック
- actions/ttsActions.ts (70 lines) - TTS 操作
- actions/mediaActions.ts (60 lines) - メディア操作
エージェントとスキルの活用
自動エージェント選択
分析タスク:
Explore- コードベースの探索general-purpose- 複雑な分析
実装タスク:
frontend-developer- UI コンポーネントbackend-api-developer- API エンドポイントdatabase-architect- スキーマ設計ux-ui-designer- デザイン仕様
スキル統合:
supabase-manager- データベース操作safe-edit(このスキル) - すべての実装
決定マトリックス
| タスクタイプ | エージェント/スキル | 理由 |
|---|---|---|
| UI コンポーネント | frontend-developer | デザインシステム + 実装 |
| API エンドポイント | backend-api-developer | ベストプラクティス + パターン |
| DB スキーマ | database-architect | 正規化 + インデックス作成 |
| バグ分析 | Explore | 詳細な分析 + 推論 |
| ファイル変更 | safe-edit (常に) | バックアップ + ロールバックの安全性 |
実装ルール
ルール 1: 常に最初にバックアップする
# ANY ファイル変更の前に
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
backup_dir=".backups/$(date +%Y-%m-%d)"
mkdir -p "$backup_dir"
cp "path/to/file" "$backup_dir/${timestamp}_${file_slug}.backup"
ルール 2: 常に差分を保存する
# 変更の前と後
mkdir -p "/tmp/diffs"
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
git diff path/to/file > "/tmp/diffs/${timestamp}_${description}.patch"
cp "/tmp/diffs/${timestamp}_${description}.patch" "/tmp/diffs/latest.patch"
ルール 3: ファイルサイズを確認する
# 実装の前に
lines=$(wc -l < "path/to/file")
if [ $lines -gt 200 ]; then
echo "⚠️ ファイルが200行を超えています - モジュール化を計画します"
# モジュール化戦略を実行
fi
ルール 4: 利用可能な場合はエージェントを使用する
// 複雑な UI 作業の場合
Task({
subagent_type: "frontend-developer",
description: "Implement component",
prompt: "Detailed requirements..."
})
// 分析の場合
Task({
subagent_type: "Explore",
description: "Analyze codebase",
prompt: "Find patterns and structure..."
})
ルール 5: 進捗を追跡する
// 複数ステップのタスクには常に TODO リストを作成する
TodoWrite({
todos: [
{ content: "Backup files", status: "in_progress", activeForm: "Backing up files" },
{ content: "Implement feature", status: "pending", activeForm: "Implementing feature" },
{ content: "Verify changes", status: "pending", activeForm: "Verifying changes" }
]
})
ロールバック手順
方法 1: バックアップからの復元
# バックアップを見つける
ls -lt .backups/$(date +%Y-%m-%d)/
# 復元する
cp .backups/2025-10-24/13-45-30_app_pricing_page.tsx.backup app/pricing/page.tsx
方法 2: パッチの逆適用
# 逆パッチを適用する
cd /path/to/your/project
patch -R app/pricing/page.tsx < /tmp/diffs/2025-10-24_13-45-30_feature.patch
方法 3: Git リセット
# 変更がステージングされているがコミットされていない場合
git restore app/pricing/page.tsx
# コミットされているがプッシュされていない場合
git reset --hard HEAD~1
自動化チェックリスト
実装の前に、このスキルは自動的に以下を実行します。
- [ ] 追跡用の TODO リストを作成します
- [ ] 影響を受けるすべてのファイルを
.backups/YYYY-MM-DD/にバックアップします - [ ] 変更前の差分を
/tmp/diffs/に保存します - [ ] ファイルサイズをチェックし、必要に応じてモジュール化を計画します
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Safe Edit Skill
Overview
Comprehensive workflow automation for safe, reversible, and clean code implementations. This skill ensures every code change follows best practices: automatic backups, diff tracking, agent utilization, and modular architecture enforcement.
When to Use
ALWAYS activate this skill before ANY code implementation:
- Any file modification (create, update, delete)
- Feature implementation
- Bug fixes
- Refactoring
- UI/UX changes
- API changes
- Database schema updates
User triggers (automatic activation):
- Any implementation request without explicit backup mention
- "implement", "add", "create", "fix", "update", "change"
- Any code-related task
Core Workflow
Phase 1: Pre-Implementation Analysis
1. Analyze task complexity and scope
2. Identify affected files and modules
3. Check if agents/skills can help
4. Plan modular architecture (if >200 lines)
5. Create TODO list for tracking
Phase 2: Backup & Safety
1. Create timestamped backup in .backups/
2. Generate git diff (save to /tmp/diffs/)
3. Document rollback commands
4. Verify backup integrity
Phase 3: Implementation
1. Use appropriate agents/skills
2. Implement in modular chunks (<200 lines)
3. Follow existing patterns
4. Update TODO progress
Phase 4: Verification
1. Generate final diff
2. Run type checking (if TypeScript)
3. Test build (if applicable)
4. Document changes
Backup Management
Directory Structure
.backups/
├── YYYY-MM-DD/
│ ├── HH-MM-SS_{filename}.backup
│ └── HH-MM-SS_{filename}.backup
└── ROLLBACK_GUIDE.md
/tmp/diffs/
├── YYYY-MM-DD_HH-MM-SS_{description}.patch
└── latest.patch
Backup Naming Convention
Format: {timestamp}_{original_path_with_underscores}.backup
Examples:
2025-10-24_13-45-30_app_pricing_page.tsx.backup
2025-10-24_13-45-30_components_editor_EditorContainer.tsx.backup
Diff Naming Convention
Format: YYYY-MM-DD_HH-MM-SS_{feature_description}.patch
Examples:
2025-10-24_13-45-30_add-footer-links.patch
2025-10-24_14-20-15_pricing-policy-update.patch
Automatic Modularization
When File Exceeds 200 Lines
Detection:
- Count lines before implementation
- Predict final size after changes
- Warn if approaching 200 lines
Action Plan:
- Analyze component responsibilities
- Identify extractable logic
- Create modular structure
- Implement in separate files
- Update imports/exports
Example Refactoring:
Original: EditorContainer.tsx (450 lines)
↓
Modularized:
- EditorContainer.tsx (180 lines) - Main layout
- hooks/useEditorState.ts (80 lines) - State management
- hooks/useKeyboardShortcuts.ts (60 lines) - Keyboard logic
- actions/ttsActions.ts (70 lines) - TTS operations
- actions/mediaActions.ts (60 lines) - Media operations
Agent & Skill Utilization
Automatic Agent Selection
Analysis Tasks:
Explore- Codebase explorationgeneral-purpose- Complex analysis
Implementation Tasks:
frontend-developer- UI componentsbackend-api-developer- API endpointsdatabase-architect- Schema designux-ui-designer- Design specs
Skill Integration:
supabase-manager- Database operationssafe-edit(this skill) - All implementations
Decision Matrix
| Task Type | Agent/Skill | Why |
|---|---|---|
| UI Component | frontend-developer | Design system + implementation |
| API Endpoint | backend-api-developer | Best practices + patterns |
| DB Schema | database-architect | Normalization + indexing |
| Bug Analysis | Explore | Deep analysis + reasoning |
| File Changes | safe-edit (always) | Backup + rollback safety |
Implementation Rules
Rule 1: Always Backup First
# Before ANY file modification
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
backup_dir=".backups/$(date +%Y-%m-%d)"
mkdir -p "$backup_dir"
cp "path/to/file" "$backup_dir/${timestamp}_${file_slug}.backup"
Rule 2: Always Save Diff
# Before and after changes
mkdir -p "/tmp/diffs"
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
git diff path/to/file > "/tmp/diffs/${timestamp}_${description}.patch"
cp "/tmp/diffs/${timestamp}_${description}.patch" "/tmp/diffs/latest.patch"
Rule 3: Check File Size
# Before implementation
lines=$(wc -l < "path/to/file")
if [ $lines -gt 200 ]; then
echo "⚠️ File exceeds 200 lines - planning modularization"
# Execute modularization strategy
fi
Rule 4: Use Agents When Available
// For complex UI work
Task({
subagent_type: "frontend-developer",
description: "Implement component",
prompt: "Detailed requirements..."
})
// For analysis
Task({
subagent_type: "Explore",
description: "Analyze codebase",
prompt: "Find patterns and structure..."
})
Rule 5: Track Progress
// Always create TODO list for multi-step tasks
TodoWrite({
todos: [
{ content: "Backup files", status: "in_progress", activeForm: "Backing up files" },
{ content: "Implement feature", status: "pending", activeForm: "Implementing feature" },
{ content: "Verify changes", status: "pending", activeForm: "Verifying changes" }
]
})
Rollback Procedures
Method 1: Backup Restore
# Find backup
ls -lt .backups/$(date +%Y-%m-%d)/
# Restore
cp .backups/2025-10-24/13-45-30_app_pricing_page.tsx.backup app/pricing/page.tsx
Method 2: Patch Reversal
# Apply reverse patch
cd /path/to/your/project
patch -R app/pricing/page.tsx < /tmp/diffs/2025-10-24_13-45-30_feature.patch
Method 3: Git Reset
# If changes are staged but not committed
git restore app/pricing/page.tsx
# If committed but not pushed
git reset --hard HEAD~1
Automation Checklist
Before ANY implementation, this skill automatically:
- [ ] Creates TODO list for tracking
- [ ] Backs up all affected files to
.backups/YYYY-MM-DD/ - [ ] Saves pre-change diff to
/tmp/diffs/ - [ ] Checks file sizes and plans modularization if needed
- [ ] Evaluates if agents/skills can help
- [ ] Implements changes following best practices
- [ ] Saves post-change diff to
/tmp/diffs/ - [ ] Verifies TypeScript types (if applicable)
- [ ] Tests build (if applicable)
- [ ] Documents rollback commands
- [ ] Reports completion with verification evidence
Quick Commands
# View recent backups
ls -lt .backups/$(date +%Y-%m-%d)/
# View recent diffs
ls -lt /tmp/diffs/ | head -10
# Restore from backup
cp .backups/YYYY-MM-DD/HH-MM-SS_file.backup original/path
# Apply reverse diff
patch -R path/to/file < /tmp/diffs/YYYY-MM-DD_HH-MM-SS_desc.patch
# Check file sizes
find . -name "*.tsx" -o -name "*.ts" | xargs wc -l | sort -nr | head -20
# Clean old backups (keep 7 days)
find .backups/ -type f -mtime +7 -delete
Related Files
.backups/- Backup storage/tmp/diffs/- Diff storage.claude/skills/safe-edit/SKILL.md- This file.claude/skills/safe-edit/README.md- User documentation
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (7,339 bytes)
- 📎 README.md (8,295 bytes)