プロンプトテンプレート — 毎日のAIタスクを再利用する
毎回ゼロからAIに説明するのをやめる — コードレビュー・デバッグ・リファクタリング・テスト・ドキュメントのテンプレート。
AI エージェントを1週間使うと、毎日同じ種類のリクエストを繰り返していることに気づきます — 「このコードをレビューして」「このバグをトレースして」「テストを書いて」。毎回コンテキストを説明し直す代わりに、再利用可能なプロンプトテンプレート は時間を節約し、一貫性を高め、出力の品質を上げる。
プロンプトの品質は速度ではなく構造にあると考える。以前はその場で思いついた言葉でリクエストしていた。いまでは役割・入力・出力形式・制約を明示した構造こそが一貫した高品質の出力を生むためだとわかっているので、テンプレートに投資する価値がある。
このガイドでは5つの日常テンプレート(コードレビュー・デバッグ・リファクタリング・テスト・ドキュメント)とその保存方法を解説する。
TL;DR
- テンプレート = コンテキスト + タスク + 出力形式 + 制約
- 保存場所:
~/.prompts/または chezmoi管理 - マクロツール: Raycast Snippets、Cursor
@docs、Claude Code スラッシュコマンド - 良いテンプレートの4要素: 役割 / 入力 / 出力形式 / 禁止事項
1. 良いプロンプトの4要素
プレースホルダーは [...] で表記(MDX/JSXの競合を避けるため)。
You are a [role].
Context: [context]
Task: [what to do]
Output format: [how to respond]
Constraints:
- [prohibition 1]
- [prohibition 2]
4つの明確なセクションにより、モデルが対処すべきことと省くべきことを明確に分離できる。
2. テンプレート1 — コードレビュー
You are a senior code reviewer for [language] projects.
Context:
- Code under review: [paste code or @file]
- Project conventions: [link or paste relevant style guide / .cursorrules]
- Reviewer focus: [correctness | security | performance | readability]
Task: Review the code. Identify:
- Bugs or logic errors (severity: critical / major / minor)
- Security issues (input validation, secrets, auth)
- Performance concerns (only if obvious O(n^2) or memory)
- Style violations against project conventions
- Suggestions for clarity
Output format: SUMMARY: [one-paragraph overall verdict] [CRITICAL] (line N): [issue] -> [fix] [MAJOR] ... [MINOR] ... [STYLE] ... [SUGGESTION] ...
Constraints:
- Do not rewrite the entire file. Point and suggest.
- Do not nitpick style if .cursorrules don't enforce it.
- If no issues found at a level, omit that section.
使い方
Cursor サイドチャット — @code-review.md + @src/auth/login.ts + focus: security。
Claude Code: テンプレートを .claude/commands/review.md に保存し、/review src/auth/login.ts で呼び出す(スラッシュコマンド)。
3. テンプレート2 — バグデバッグ
You are a debugging assistant.
Context:
- Error message: [paste full stacktrace]
- Code where it occurs: [paste minimal repro or @file]
- What I tried: [hypotheses ruled out]
- Expected behavior: [what should happen]
Task:
- Identify the most likely root cause (not just symptoms)
- Suggest a fix
- Suggest a test to prevent regression
Output format: ROOT CAUSE: [one sentence] EXPLANATION: [2-3 paragraphs of why] FIX: [patched code] REGRESSION TEST: [test code]
Constraints:
- Do not guess. If you need more info (logs, full file), ask.
- If 2+ hypotheses are equally likely, present both with discriminating signals.
- Do not just say "try X" — explain the model.
「What I tried」セクションが重要 — すでに試して除外したことをモデルが再提案するのを防ぐ。
4. テンプレート3 — リファクタリング
You are a refactoring assistant for [language].
Context:
- Current code: [paste or @file]
- Pain point: [readability | duplication | testability | performance]
- Constraints:
- Must preserve public API
- Must not break existing tests
Task: Refactor while preserving behavior. Show:
- The refactored code
- Diff vs original
- Tradeoffs of this approach vs at most 1 alternative
Output format: REFACTOR: [new code] DIFF:
- Removed: [what]
- Added: [what]
- Renamed: [old -> new] TRADEOFF: [this approach]: [pros/cons] [alternative]: [pros/cons] RECOMMENDATION: [which and why]
Constraints:
- Do not change behavior. If you think behavior should change, flag it separately.
- Keep test compatibility — show how existing tests still pass.
- Don't introduce new dependencies without explicit ask.
5. テンプレート4 — テスト作成
You are a test writer for [language] (Vitest, Jest, Pytest, etc.).
Context:
- Code to test: [paste or @file]
- Existing test style: [paste sample test or @file]
- Coverage focus: [happy path | edge cases | failure modes | all]
Task: Write tests that:
- Cover the happy path
- Cover at least 3 edge cases (boundary values, empty input, error cases)
- Are deterministic (no flaky time/network without mock)
- Follow the existing test style
Output format: a single test file in [language].
Constraints:
- Use the same assertion library as existing tests
- Mock external dependencies (don't hit real network/DB)
- Keep each test focused (one assertion topic per test)
- Name tests descriptively: "returns X when Y"
- Do NOT write tests that just mirror implementation. Test behavior.
6. テンプレート5 — ドキュメント
You are a technical writer.
Context:
- Code: [paste or @file]
- Audience: [beginner | intermediate | expert]
- Doc type: [README section | JSDoc | tutorial | reference]
Task: Write documentation that:
- States the purpose in 1 sentence
- Shows minimal usage example
- Lists parameters/returns with types
- Notes edge cases or gotchas (if any)
Output format: markdown or specific JSDoc/TypeDoc format.
Constraints:
- No filler. Be direct.
- Code examples must be runnable / pasteable
- If the API is complex, link to deeper reference rather than dumping
- For library/framework specifics, prefer official terminology
7. 保存 / 管理
オプションA — Claude Code スラッシュコマンド
テンプレートを ~/.claude/commands/review.md に保存。CLI: /review src/foo.ts でsystem promptが自動注入される。
オプションB — Cursor @docs
Cursor → Settings → Features → Docs → Add → URL/ローカルパス。チャット内で @my-review-template を使用。
オプションC — Raycast Snippets
mac/productivityのRaycast Snippets経由:
- Snippetを追加: テンプレート全体を貼り付け
- キーワード:
!review - 任意のテキストフィールドで
!review→ 展開
オプションD — シンプルなディレクトリ + エイリアス
各テンプレートを ~/.prompts/ に .md ファイルとして保存。.zshrc:
alias prompt='ls ~/.prompts'
prompt → 一覧 → cat ~/.prompts/review.md | pbcopy → どこにでも貼り付け。
chezmoi 統合
~/.prompts/ をdotfilesのchezmoiツリーに追加。新しいマシンでもすぐに使える。
8. テンプレートの進化
最初のテンプレートは品質70%だ。使いながら改善してください:
- 結果がよく長くなる → 「N行以内に収める」または「差分のみ出力」を追加
- AI が脱線し続ける → 制約を強化(具体的な禁止事項)
- コンテキストが足りない → 「試したこと」のような明示的な入力スロットを追加
- 出力が一貫しない → 出力形式に具体例を示す
- 保守的すぎる → 「全ての選択肢でなく、最善の選択肢を推奨して」
フェーズ終了後に1行メモを残してください。1年続けると、テンプレートが資産になる。
9. アンチパターン
抽象的すぎる
❌ 「良いコードレビュアーになってください。」 ✅ 「あなたはシニアレビュアーだ。バグ / セキュリティ / スタイルを特定してください。形式Xで出力。」
目標が曖昧
❌ 「これを改善して。」 ✅ 「これをより読みやすくして。動作は変えないで。差分を見せて。」
出力形式がない
モデルごとに異なる形式を出力するため、比較や自動化が難しくなる。
長すぎる — 「保険」制約
「あとXも。それとYも。Zを忘れずに。」→ モデルが優先順位を失う。重要な3〜5つに絞りましょう。
常に日本語
英語のコードベースで日本語プロンプトはトークン効率が下がる。コードコンテキストが英語なら、英語プロンプトの方が良い結果を生む。
確認
- テンプレートありvsなしで同じコードをレビュー — 一貫性/完全性を比較
- 新しいマシンでchezmoiを適用 →
~/.prompts/が即座に使える - Raycast
!reviewトリガー → どこでも展開 - Claude Code
/review file.ts→ 同じ応答形式 - 1週間使った後、週に1つテンプレートを進化させる(1行メモ)
トラブルシューティング
AI がテンプレートを無視する
- 長いテンプレートはモデルが途中で指示を忘れる。200行以内に収めましょう
- 最重要の制約を最後に再掲する(再近性バイアス)
- Cursor
@docsはコンテキストを圧縮することがある — エッセンスを先頭に置く
スラッシュコマンドが動かない
- Claude Code:
~/.claude/commands/foo.mdのファイル名/場所を確認 - Cursor: スラッシュコマンドはモデルに依存する
出力形式が崩れる
明示的な形式例を示す。「この正確な形式を使って:」のような強い表現。
回答が長すぎる
「最大N行。」または「差分のみ、説明なし。」
言語が混在する
プロンプトと出力言語の両方を指定。「日本語で回答して。」または「英語で回答して。」
参考リンク
- Claude Code セットアップ — スラッシュコマンドの登録
- Cursor セットアップ —
@docsと .cursorrules - マルチエージェントワークフロー — 引き継ぎもテンプレートの一種
- Dotfiles管理 — マシン間でテンプレートを共有
- Anthropic プロンプトエンジニアリング
変更履歴
- 2026-05-12: 初版。5つのテンプレート + 4つの保存オプション + 進化 + 5つのアンチパターン + 5つのトラブルシューティング。