Claude Codeスキル:AIコーディングアシスタントのためのカスタムワークフローを構築する
Claude Codeには汎用のAIアシスタントが搭載されています。スキルを使うことで専門的にカスタマイズできます。スキルとは、特定のタスク(Kubernetesへのデプロイ、データベースマイグレーションの作成、プルリクエストのレビュー、チームのコーディング規約の遵守など)をClaude Codeに教えるマークダウンファイルのことです。
「Reactコンポーネントを書いて」と「デザインシステムに従い、カスタムフックを使い、適切なエラーバウンダリとアクセシビリティ属性を備えたReactコンポーネントを書いて」の違いがスキルです。
スキルとは何か
スキルは.claude/commands/(プロジェクト単位)または~/.claude/commands/(グローバル)に置かれるマークダウンファイルです。Claude Codeで/skill-nameと入力すると、そのファイルの内容が指示として会話に挿入されます。
.claude/
commands/
deploy.md # /deploy
review-pr.md # /review-pr
write-test.md # /write-test
これだけです。特別な構文もコンパイルもSDKも不要。単に「どうやって何かをするか」を記述したマークダウンです。
最初のスキルを書く
実用的な例として、チームのコミットメッセージ規約を強制するスキルを作ってみましょう。
.claude/commands/commit.mdを作成します:
# Commit Workflow
## Steps
1. Run `git diff --staged` to see what's being committed
2. Analyze the changes and categorize: feat, fix, refactor, docs, test, chore
3. Write a commit message following our convention:
- Format: `type(scope): description`
- Scope is the package or module name
- Description is imperative mood, lowercase, no period
- Body explains WHY, not WHAT
4. If changes touch multiple scopes, create separate commits
5. Run `git commit -m "message"` with the generated message
## Rules
- Never use `--no-verify` to skip hooks
- Never amend published commits
- If tests fail in pre-commit, fix the issue first
## Examples
- `feat(billing): add stripe webhook handler`
- `fix(auth): handle expired refresh tokens`
- `refactor(api): extract rate limiter to shared package`
これで/commitは「変更をコミットして」といった曖昧な指示ではなく、構造化されたワークフローをClaude Codeに提供します。
スキルのデザインパターン
チェックリストパターン
複数の検証ステップがあるタスクに最適です。
# Pre-Deploy Checklist
Before deploying, verify each item:
- [ ] `pnpm typecheck` passes
- [ ] `pnpm test` passes
- [ ] No console.log statements in production code
- [ ] Environment variables documented in .env.example
- [ ] Database migrations are reversible
- [ ] API changes are backward compatible
If any check fails, stop and report the issue. Do not proceed with deployment.
ディシジョンツリーパターン
状況に応じて対応が変わるタスクに最適です。
# Bug Fix Workflow
1. Reproduce the bug (find or write a failing test)
2. Identify the root cause:
- If it's a type error → fix the type definition at the source
- If it's a race condition → add proper locking/sequencing
- If it's a missing validation → add schema validation at the boundary
- If it's a logic error → fix and add regression test
3. Verify the fix doesn't break existing tests
4. Write a test that would have caught this bug
テンプレートパターン
一貫した出力を生成するのに最適です。
# New API Endpoint
Create a new API endpoint following our conventions:
## File Structure
- Route handler: `apps/api/src/routes/{resource}/{action}.ts`
- Schema: `apps/api/src/schemas/{resource}.ts`
- Test: `apps/api/src/routes/{resource}/__tests__/{action}.test.ts`
## Required Elements
- Zod schema for request validation
- Authentication middleware
- Rate limiting
- Structured error responses using errorResponse()
- Success responses using successResponse()
- OpenAPI documentation comments
コミュニティスキルのインストール
Claude Codeのエコシステムには成長中のコミュニティスキルライブラリがあります。以下でインストールできます:
npx add-skill username/repo-name -y
人気のスキルコレクション:
coreyhaines31/marketingskills(29のマーケティング/SEOスキル)hedging8563/lemondata-api-skill(LemonData API統合)
インストールしたスキルは~/.claude/commands/に配置され、すべてのプロジェクトで利用可能です。
プロジェクトスキルとグローバルスキル
| 場所 | スコープ | ユースケース |
|---|---|---|
.claude/commands/ |
このプロジェクトのみ | プロジェクトの規約、デプロイワークフロー |
~/.claude/commands/ |
すべてのプロジェクト | 個人の好み、一般的なツール |
プロジェクトスキルはリポジトリにコミットしてチーム全体で共有しましょう。グローバルスキルは個人のワークフロー向けです。
応用:フック付きスキル
スキルは特定のイベントで実行されるシェルコマンド(フック)を参照して自動化を強制できます:
# Pre-Commit Check
Before any commit, the following hooks run automatically:
- `pre-commit`: runs typecheck + lint
- `post-commit`: updates changelog
If a hook fails, investigate the error output and fix the issue.
Do not use --no-verify to bypass hooks.
フック自体は.claude/settings.jsonで設定します:
{
"hooks": {
"pre-commit": "pnpm typecheck && pnpm lint-staged"
}
}
効果的なスキルのためのヒント
ファイルパスや命名規則を具体的に示しましょう。「コンポーネントを作る」では曖昧です。「
src/components/ui/にPascalCase命名でコンポーネントを作る」は実行可能です。正しい出力例を含めましょう。Claude Codeは抽象的なルールより例から学びます。
やってはいけないことも定義しましょう。「
any型を使わない」は「適切な型を使う」より強制力があります。スキルは焦点を絞って作成しましょう。ワークフローごとに1スキル。200行の全部入りスキルより、40行のタスク別スキル5つのほうが有用です。
スキルにバージョンをつけましょう。規約が変わればスキルも更新します。古いスキルは旧パターンを強制するので無いより悪いです。
実際の効果
スキルを導入したチームは一貫した改善を報告しています:
- レビュー前に規約が強制されるためコードレビューのサイクルが短縮される
- 新人もベテランと同じ指針を得られるためオンボーディング時間が短縮される
- AI生成コードの品質が向上する。AIがプロジェクト標準の明確な文脈を持つため
投資は小さく(最初の数スキル作成に30分程度)、効果は使うたびに積み重なります。
AIを使って、自分のルールで導く開発を。lemondata.ccはAI搭載開発ツールのAPI基盤を提供します。
