😎

オレオレClaude Code初期設定プロンプト

に公開

和田様執筆によるこちらの記事の手法が非常にバイブコーディングの効率化につながることを知り、これを元にもう少し自分流にアレンジしたものです。
とても勉強になりました。この場をお借りして感謝申し上げます。

※以下はまだ未検証なのでメモ程度に見てください。

概要

このプロンプトは、Claude Codeを使用するプロジェクトに対して、体系的なドキュメント管理システムとコーディング規約を導入するための包括的な初期設定を行います。開発中に得られた知識を自動的に蓄積し、既存ドキュメントに反映させる仕組みを構築することで、プロジェクトの知識ベースを継続的に改善していきます。

主要機能一覧

1. 既存ドキュメントの探索・分析

  • プロジェクト内の全ドキュメントファイルを自動探索
  • .cursor/rules/(.mdcファイル)、docs/(.mdファイル)、ルートディレクトリの識別
  • 各ドキュメントの役割と目的の分析・整理
  • ファイル形式の適切な使い分けの確立

2. CLAUDE.mdへの運用ルール追加

  • 英語での包括的な運用ルールを追記
  • 参照すべきドキュメントリストの自動生成
  • ドキュメント更新の提案タイミングとフォーマット定義
  • 承認プロセスの確立(提案→プレビュー→承認→更新)

3. デグレ防止の徹底システム

  • 絶対的なルールとして既存機能の保護を設定
  • 修正前の影響範囲特定と確認プロセスの義務化
  • 既存テストの実行とユーザー確認の強制
  • 不明な場合の停止・確認ルールの設定

4. TDD(テスト駆動開発)の厳格な適用

  • 必須として3段階のTDDフローを定義
    • フェーズ1:モック・テスト作成(レッドフェーズ)
    • フェーズ2:ロジック実装(グリーンフェーズ)
    • フェーズ3:総合検証・リグレッションテスト
  • 各段階での具体的なチェックポイントと手順の明文化

5. インタラクティブなドキュメント更新システム

  • 開発中の発見を自動的にドキュメント化する仕組み
  • ユーザー承認制による安全な更新プロセス
  • 既存フォーマットの踏襲とスタイル保持
  • 機密情報の自動除外機能

6. ドキュメント構造の最適化提案

  • プロジェクトに不足しているドキュメントの自動識別
  • 推奨ドキュメント構造の提案
  • Cursor連携用の.mdcファイルの併用作成
  • ドキュメントの肥大化防止と適切な分割管理

7. 品質管理とガバナンス

  • 100行を超えるドキュメントの自動分割提案
  • 更新履歴の日付付き管理
  • プロジェクト固有の慣習・スタイルガイドの尊重
  • 英語での統一されたドキュメント作成

8. 動作確認とテスト機能

  • 設定完了後の動作確認メッセージ表示
  • テスト用エラーでの提案フロー確認機能
  • ユーザーとのインタラクティブな動作テスト

9. 設定記録と追跡管理

  • setup-log.mdによる初期設定の完全な記録
  • 実行内容、作成ファイル、設定日時の詳細な記録
  • 英語での統一された記録フォーマット

特徴的な設計思想

デュアルファイル戦略

  • docs/.mdファイル:プロジェクトドキュメント(詳細説明、背景、手順)
  • .cursor/rules/.mdcファイル:Cursor向け規約(具体的ルール、チェックポイント)

ゼロトレランス方針

  • デグレーション:既存機能の破壊を絶対に許可しない
  • TDD違反:テスト駆動開発からの逸脱を許可しない
  • 未承認更新:ユーザー承認なしのファイル変更を許可しない

継続的改善メカニズム

  • エラー解決時の自動知識蓄積
  • 効率的パターン発見時の自動ドキュメント化
  • 既存情報の陳腐化検出と更新提案

対象ユーザー

  • Claude Codeを使用する開発者・チーム
  • プロジェクトの知識管理を体系化したい組織
  • コード品質とドキュメント品質の両方を重視する開発環境
  • CursorエディタとClaude Codeの連携を最大化したいユーザー

このシステムにより、開発プロジェクトは一貫した品質基準のもとで、継続的に知識を蓄積・改善していくことができます。

以下プロンプト

# Claude Code 初期設定プロンプト

以下の手順で、このプロジェクトにインタラクティブなドキュメント更新システムを導入してください。

## 1. 既存ドキュメントの探索

まず、プロジェクト内の既存ドキュメントを探索してください:

- `.cursor/rules/` ディレクトリ内のすべての.mdcファイル(Cursorのコーディング規約専用)
- `docs/` ディレクトリ内のすべての.mdファイル(プロジェクトドキュメント)
- ルートディレクトリの*.mdファイル(README.md、CONTRIBUTING.mdなど)
- その他プロジェクト固有のドキュメントディレクトリ

見つかったドキュメントをリストアップし、それぞれの役割を簡潔に説明してください。

**重要**: 
- `.cursor/rules/`以下は.mdcファイル形式のみとし、Cursorエディタのコーディング規約に限定する
- プロジェクトドキュメントは`docs/`ディレクトリに.mdファイルとして作成する

## 2. CLAUDE.mdへの追記

CLAUDE.mdファイルに以下の内容を**英語で**追記してください。既にCLAUDE.mdが存在する場合は、既存の内容を保持したまま、以下のセクションを追加してください。

```markdown
## 📚 Interactive Documentation Update System

This project adopts a systematic approach to manage knowledge gained during development and reflect it in existing documentation.

### Documents to Reference

Always check the following documents before starting any work:

[Generate document list based on exploration results]

Example:
- `.cursor/rules/coding-standards.mdc` - Cursor coding standards
- `docs/architecture.md` - Architecture design guidelines
- `docs/troubleshooting.md` - Troubleshooting guide

### 🚫 CRITICAL: Regression Prevention

**ABSOLUTE RULE: PREVENT ANY REGRESSION**

Claude Code must NEVER:
- Remove existing functionality without explicit user approval
- Modify code outside the intended scope
- Delete or alter working features during fixes
- Make changes that break existing tests

**Before ANY modification:**
1. Identify ALL existing functionality that might be affected
2. Create/run tests to verify current behavior
3. Explicitly confirm with user what should remain unchanged
4. Document what will NOT be modified in the implementation plan

**If unsure about impact:** STOP and ask for clarification rather than risk regression.

### 🧪 Test-Driven Development (TDD) - MANDATORY

**ALL development MUST follow strict TDD principles:**

#### Phase 1: Mock & Test Creation
1. **Create function mocks** with:
   - Clear function signatures
   - Expected input/output types
   - TODO list of implementation steps
2. **Write comprehensive tests** covering:
   - Happy path scenarios
   - Edge cases
   - Error conditions
3. **Verify all tests FAIL** (red phase)

#### Phase 2: Implementation
1. **Implement logic step by step** following the TODO list
2. **Run tests frequently** during implementation
3. **Ensure all tests PASS** (green phase)

#### Phase 3: Verification
1. **Run complete test suite**
2. **Verify NO regressions** in existing functionality
3. **Confirm ALL new tests pass**

**NO EXCEPTIONS**: This TDD flow must be strictly followed for every development task.

### Update Rules

#### Proposal Timing
Propose documentation updates in the following situations:
1. **After resolving errors or issues**
2. **When discovering efficient implementation patterns**
3. **When establishing new API/library usage patterns**
4. **When existing documentation is found outdated/incorrect**
5. **When discovering frequently referenced information**
6. **After completing code review corrections**

#### Proposal Format
💡 Documentation Update Proposal: [Situation description]
【Update Content】 [Specific additions/modifications]
【Update Candidates】
[File path 1] - [Reason]
[File path 2] - [Reason]
New file creation - [Reason]

Where should this be added? (Select number or skip)

#### Approval Process
1. User selects update destination
2. Display actual update content preview
3. User provides final approval (yes/edit/no)
4. Update file after approval

### Integration with Existing Documentation

- Follow existing format and style conventions
- Reference related existing content when applicable
- Include update history with dates (YYYY-MM-DD format)
- **ALL additions to CLAUDE.md and related files MUST be in English**

### Important Constraints

1. **Never update files without user approval**
2. **Only add content - never delete or modify existing content without explicit permission**
3. **Never record sensitive information (API keys, passwords, etc.)**
4. **Follow project conventions and style guides**
5. **Prevent any regression in existing functionality**
6. **Strictly follow TDD principles**

### Document Management

To prevent CLAUDE.md from becoming too large, split files according to these criteria:

- **When exceeding 100 lines**: Propose splitting related content into separate files
- **Recommended split structure**:
  - `docs/update-system.md` - Update system rules
  - `docs/project-specific.md` - Project-specific configurations
  - `docs/references.md` - List of reference documents
  - `docs/tdd-guidelines.md` - TDD implementation guidelines
  - `docs/regression-prevention.md` - Regression prevention checklist
- **Keep only overview and links in CLAUDE.md**: Move details to individual files
```

## 3. 推奨ドキュメント構造の提案

既存のドキュメント構造を分析した上で、不足している可能性のあるドキュメントを提案してください:

```
📁 ドキュメント構造の提案:

現在のプロジェクトに以下のドキュメントを追加することを推奨します:

[探索結果に基づいて、不足しているドキュメントを提案]

例:
1. `docs/patterns.md` - 実装パターンとベストプラクティス
   → 効率的なコードパターンを蓄積
   + `.cursor/rules/patterns.mdc` - Cursor向けコーディングパターン規約
2. `docs/troubleshooting.md` - トラブルシューティングガイド
   → エラーと解決策を体系化
3. `docs/dependencies.md` - 依存関係とAPI使用例
   → 外部ライブラリの使用方法を記録
4. `docs/remote-integration.md` - リモートリポジトリ連携
   → Git操作のベストプラクティス、ブランチ戦略、PR/MRテンプレート、CI/CD設定等を記録
5. `docs/tdd-guidelines.md` - TDD実装ガイドライン
   → テスト駆動開発の具体的な手順とベストプラクティス
   + `.cursor/rules/tdd-standards.mdc` - Cursor向けTDD規約
6. `docs/regression-prevention.md` - デグレ防止チェックリスト
   → 既存機能の保護に関するガイドライン
   + `.cursor/rules/regression-prevention.mdc` - Cursor向けデグレ防止規約

**重要**: Cursorエディタと情報を共有する必要がある内容については、対応する.mdcファイルも作成してください。
- `docs/`の.mdファイル: プロジェクトドキュメント(詳細な説明、背景、手順等)
- `.cursor/rules/`の.mdcファイル: Cursor向け規約(コーディング時の具体的なルール、チェックポイント等)

これらのファイルを作成しますか?(作成する番号を選択: "1,2" or "all" or "skip")
```

選択されたファイルに対して、初期テンプレートを**英語で**作成してください。**Cursorとの情報共有が必要な内容については、対応する.mdcファイルも併せて作成してください。**

## 4. 動作確認

設定完了後、以下のメッセージを表示してください:

```
✅ ドキュメント自動更新システムの設定が完了しました!

【設定内容】
- CLAUDE.mdに運用ルールを英語で追記
- デグレ防止の徹底ルールを追加
- TDD原則の厳格な適用ルールを追加
- [作成したドキュメントのリスト]

【今後の動作】
1. 作業中に新しい発見があった際、更新提案を行います
2. あなたの承認を得てから、ドキュメントを更新します
3. 既存のドキュメント形式を踏襲し、知識を体系的に蓄積します
4. デグレを絶対に防ぎ、TDD原則を厳格に守ります

動作テストをしますか?(テスト用のエラーを発生させて、提案フローを確認できます)
```

## 5. 初期設定の記録

最後に、`docs/`ディレクトリにsetup-log.mdを作成し、実行した初期設定を**英語で**記録してください:

```markdown
# Documentation Auto-Update System Setup Log

## Setup Date
[YYYY-MM-DD HH:MM]

## Executed Tasks
1. Existing document exploration
   - [List of found files]
2. CLAUDE.md additions (in English)
   - Document reference list
   - Update rules
   - Approval process
   - Regression prevention rules
   - TDD guidelines
3. Newly created documents
   - [List of created files]

## Key Features Added
- Strict regression prevention measures
- Mandatory TDD workflow enforcement
- English-only documentation updates
- Proper file organization (.mdc for Cursor rules, .md for project docs)

## Notes
[Additional remarks if any]
```

---

以上の手順を実行し、各ステップでユーザーの確認を取りながら進めてください。特に**デグレ防止**と**TDD原則の厳守**については妥協せず、厳格に適用してください。

参照

Discussion