CClaude Code Catalog
全ガイド

Claude Codeのためのプロンプトエンジニアリング

入門 8 min

Claude Codeの出力品質は、プロンプトの品質に正比例します。このガイドでは、一貫した結果を生み出す明確で効果的なプロンプトの書き方を教えます。優れたプロンプトの構造、構造化された出力を得るテクニック、反復的な改善戦略、そして最も一般的なタスクのための再利用可能なプロンプトテンプレートライブラリの構築方法を学びます。

プロンプト生産性テンプレートワークフロー

効果的なプロンプトの構造

An effective Claude Code prompt has three components: context, task, and constraints. Context tells Claude what it is working with, including the relevant files, frameworks, and patterns. The task specifies exactly what you want done. Constraints define quality requirements like 'include error handling,' 'use TypeScript,' or 'follow our existing patterns.' Specificity is the single biggest factor in prompt quality. Compare 'fix the bug' with 'fix the null reference error in src/services/UserService.ts when calling getUserById with an undefined id, and add a guard clause that returns a 404 response.' The second prompt gives Claude everything it needs to produce a correct fix on the first attempt. Avoid ambiguity by using concrete references. Instead of 'update the component,' say 'update the UserProfile component in src/components/UserProfile.tsx.' Instead of 'make it faster,' say 'optimize the database query in getRecentOrders to use an index on created_at instead of a full table scan.' The more precise your language, the more precise Claude's output.
# Weak prompt (vague, missing context) claude "add a login feature" # Strong prompt (specific context, task, constraints) claude "add a login form to src/app/login/page.tsx that: - uses our existing AuthContext from src/contexts/AuthContext - includes email and password fields with zod validation - shows inline error messages below each field - calls the /api/auth/login endpoint on submit - redirects to /dashboard on success - follows our existing form pattern in src/app/register/page.tsx"

構造化された出力の取得

Claude Code can produce output in any format you specify, but you need to ask for it explicitly. When you need JSON, markdown tables, specific file structures, or formatted reports, state the desired format in your prompt. Claude will match the structure precisely when given a clear example. For code generation, specifying the output structure prevents Claude from making assumptions about file organization. Tell it exactly where new files should go, what naming convention to follow, and what exports to include. This eliminates the back-and-forth of reorganizing generated code after the fact. When asking for analysis or review, request the output in a structured format that you can act on. A prompt like 'list all type safety issues as a markdown table with columns: file, line, issue, severity, suggested fix' produces output that is immediately actionable, compared to a prose paragraph that buries findings in text.
# Request specific output format claude "analyze src/api/ for error handling gaps. Output as JSON array: [{ "file": "path", "line": number, "issue": "description", "severity": "high|medium|low", "fix": "suggested code change" }]" # Specify file structure for generation claude "create a new feature module for notifications: src/features/notifications/ index.ts (public exports) types.ts (TypeScript interfaces) NotificationList.tsx (main component) useNotifications.ts (data fetching hook) notifications.test.ts (unit tests) Follow the pattern used in src/features/auth/"

反復的な改善

Great results often come from iteration, not from a single perfect prompt. Start with a reasonable first prompt, evaluate the output, and refine. Claude Code retains full conversation context, so each follow-up builds on the previous work without starting over. The most effective refinement pattern is specific feedback. Instead of 'that is not quite right,' say exactly what needs to change: 'the validation is correct, but move the error messages to a constants file at src/constants/errors.ts and use the error codes from our ErrorCode enum.' This tells Claude exactly what to keep and what to change. Another powerful technique is incremental building. Start with the core functionality, verify it works, then layer on additional features. 'First, create the basic CRUD endpoint. Good. Now add input validation with zod. Good. Now add pagination support with cursor-based navigation.' Each step is small enough to verify and builds on confirmed-working code.
# Iteration 1: core functionality claude "create a UserService class with getUserById and createUser methods" # Iteration 2: add validation claude "add zod input validation to both methods. Use the User schema from src/types/user.ts" # Iteration 3: add error handling claude "wrap both methods in try-catch. Throw AppError with appropriate HTTP status codes" # Iteration 4: add tests claude "write unit tests covering success cases, validation failures, and not-found scenarios" # Targeted refinement claude "the tests look good, but use our test factory from tests/factories/user.ts instead of inline test data"

再利用可能なプロンプトテンプレート

Building a library of prompt templates for recurring tasks is one of the highest-leverage investments you can make with Claude Code. Templates ensure consistency across sessions and team members, and they encode your organization's quality standards into every AI interaction. Store templates in a dedicated directory in your repo, such as .claude/prompts/. Each template should be a markdown file with placeholders for variable parts. This makes templates discoverable, version-controlled, and easy to share across the team. Start by documenting templates for your five most common tasks. New API endpoint, new React component, code review checklist, test generation, and bug fix investigation are good starting points. As you discover prompt patterns that consistently produce high-quality results, add them to your library. Over time, this becomes a reusable knowledge base that captures your team's best practices for AI-assisted development.
# .claude/prompts/new-api-endpoint.md Create a new API endpoint at src/app/api/[resource]/route.ts: ## Requirements - HTTP methods: [GET, POST, PUT, DELETE] - Input validation using zod schemas in src/schemas/ - Authentication via middleware (use withAuth wrapper) - Error responses follow our ApiError format - Include rate limiting for public endpoints ## Output - Route handler file - Zod schema file - Unit test file - Update to API docs --- # Usage: reference the template in your prompt claude "follow the template in .claude/prompts/new-api-endpoint.md to create a /api/products endpoint with GET (list+filter) and POST (create)"

実行プレビュー

Claude Codeのためのプロンプトエンジニアリング

Claude Codeのためのプロンプトエンジニアリングについて

Claude Codeガイドは、Claude Codeの特定の側面をマスターするための詳細なステップバイステップガイドです。Claude Codeのためのプロンプトエンジニアリングは入門レベルのガイドで、日常のワークフローでClaude Codeを最大限に活用するためのベストプラクティス、実践的なテクニック、実用的なヒントを紹介します。

関連ガイド