目次
はじめに
はじめましての方ははじめまして、そうでない方はこんにちは。 かふぇいんぱわぁです。
2022年3月にOpenAIがGPT-3.5を発表してからLarge Language Model(以降LLM)、いわゆる生成AIの発展は目覚ましいものがあります。 この記事を書いている2025年6月時点では、OpenAIのGPT-4.1やAnthropicのClaude Opus 4、GoogleのGemini 2.5 Proなどの様々なLLMが存在し、日々進化を続けています。
LLMの最も一般的な利用方法の一つとしてChatGPTをはじめとするチャットボットがありますが、この記事ではチャットボットではなく、LLMを活用したコーディング支援について書いていきます。 LLMを用いたコーディング支援ツールの実例として、2025年6月現在ではClineやRoo Code等のVisual Studio Code(以降VSCode)拡張機能としてのツールが有名です。 そんな中、2025年5月にAnthropicがClaude Codeのv1.0.0をリリースしました。 この記事ではそのClaude Codeについて書いていきます。
Claude Codeについて
Claude Codeとは?
Claude Codeは、エージェンティックなCLIベースのコーディングツールです。
Claude Codeの特徴はなんといっても、VSCode拡張機能としてのツールではなく、CLIツールであることです。(もちろんVSCodeとの連携機能があります) CLIツールであるため、VSCodeに依存せず任意のエディタやターミナルで利用することができます。 また、コーディング能力は非常に高く1、ユースケースによっては人間がコードを書くよりも速く、正確にコードを生成することができます。 さらに、Claude Codeはエージェント機能を持ち、コードの生成だけでなく、実行やデバッグ、テストなどの一連の開発プロセスを自動化することが可能です。
でも、お高いんでしょう?
正直高いです。
Claude Codeを利用するためにはClaudeの有力プランであるClaude Pro、あるいはClaude Maxのサブスクリプションが必要です。(Anthropic APIを用いたりAmazon Bedrockを用いて従量課金で使用することもできます) そのため、最低でも$20/月(年額払いの場合は$17/月)のコストがかかります。 私は泣きながら課金しました。
インストール方法
Claude Codeは、Anthropicの公式ドキュメントに従ってインストールしてください。
Claude Codeのセットアップ - Anthropic
私はツールの管理にmiseを使用しているので以下のコマンドでインストールしました。
mise use -g npm:@anthropic/claude-code
使い方
詳細な使い方は公式ドキュメントを参照してください。
使用するには以下のコマンドでセッションを起動します。
$ claude
╭──────────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /Users/cffnpwr/git/github.com/cffnpwr/deadman-rs │
╰──────────────────────────────────────────────────────────╯
What's new:
• Fixed a memory leak causing a MaxListenersExceededWarning message to appear
╭─────────────────────────────────────────────────────────────────────────────╮
│ > Try "how does libpcap.rs work?" │
╰─────────────────────────────────────────────────────────────────────────────╯
? for shortcuts
セッションを起動したらやってほしいことを自然言語で入力すればClaude Codeがタスクを理解して実行してくれます。
CLAUDE.md
について
ここからが本題です。
CLAUDE.md
とは?
Claude Codeは、CLAUDE.md
というファイルをプロジェクトのルートディレクトリに置くことで、プロジェクトのコンテキストを提供することができます。
また、ホームディレクトリにCLAUDE.md
を置くことで、全プロジェクト共通のコンテキストを提供することもできます。
これを設定せずにタスクを実行することも可能ですが、毎回プロジェクトの説明を入力する必要があります。
プロジェクトの説明無しでタスクを実行すると明後日の方向に実装を進めたりしてしまいます。
グローバルなCLAUDE.md
を設定することで、Gitの操作やコーディング規約を統一することができます。
CLAUDE.md
の書き方
プロジェクト別のCLAUDE.md
はClaude Codeのセッションで/init
コマンドを実行することで生成できます。
Claude Codeがプロジェクトのファイルを解析して、プロジェクトの概要や依存関係、コーディング規約などを自動で生成してくれます。
グローバルなCLAUDE.md
は、~/.claude/
にCLAUDE.md
を作成することで読み込まれます。
なお、~/.claude/CLAUDE.md
が存在しない場合は、~/.config/claude/CLAUDE.md
が読み込まれます。
実際のCLAUDE.md
設定例
私はグローバルなCLAUDE.md
を以下のように設定しています。
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working
with code in this repository.
## General Principles
YOU MUST: Respond in Japanese when communicating with users and writing
technical documentation.
YOU MUST: Write CLAUDE.md files and system instructions in English for
optimal processing.
YOU MUST: When insufficient information is provided to complete a user's
request, clearly state what information is missing and specify what additional
details would be needed to fulfill the request.
YOU MUST: If you don't know something, explicitly state that you don't know
rather than guessing or providing uncertain information.
YOU MUST: When writing CLAUDE.md using `/init` command, always write rules in
English and include detailed directory structure to provide comprehensive
project context
IMPORTANT: English is preferred for CLAUDE.md because Claude Code processes
rules more efficiently in English context
## Git Operations Guidelines
YOU MUST: Use Git slash commands for all Git operations when available.
YOU MUST: When users request Git operations through natural language (e.g., "コミットしてください", "プッシュしてください"),
always respond by directing them to use the appropriate slash command instead.
NEVER: Perform Git operations directly when requested through natural language.
YOU MUST: Explain which slash command should be used and why slash commands are preferred for Git operations.
## Code Quality Guidelines
@instructions/code_quality.md
## Editor Configuration
@instructions/editor.md
## Important Instruction Reminders
@instructions/reminders.md
ポイントとしては以下の点が挙げられます。
CLAUDE.md
自体は英語で記述: LLMのTokenize処理が英語の方が効率的なため- ユーザーへの出力は日本語: 私が日本語しか理解できないため
- 情報が不足している場合は明確に指摘: ユーザーが何を提供すればよいかを明確にするため
- 不明な情報は「わからない」と明言: 不確かな情報を提供しないため
- Git操作はスラッシュコマンドを使用: 別で定義した
/commit
や/push
などのスラッシュコマンドを使用することで、Git操作の一貫性を保つため
こんな感じで設定してますが、必ずこのルールを守ってくれるわけではありません。 何度もやり取りをしていると、Claude Codeがルールを忘れてしまうこともあります。
CLAUDE.md
の改善
CLAUDE.md
は盆栽です。
一朝一夕で完璧なものができるわけではありません。
Claude Codeの出力が期待通りでなかったりした場合は、CLAUDE.md
を見直して改善していく必要があります。
そのために私は以下のようなスラッシュコマンドを定義しています。
# Claude Code Instruction Reflection
You are an expert in prompt engineering, specializing in optimizing AI code
assistant instructions. Your task is to analyze and improve the instructions
for Claude Code.
Follow these steps carefully:
## 1. Analysis Phase
Review the chat history in your context window.
Then, examine the current Claude instructions, commands and config
<claude_instructions>
/CLAUDE.md
/.claude/commands/*
**/CLAUDE.md
.claude/settings.json
.claude/settings.local.json
</claude_instructions>
Analyze the chat history, instructions, commands and config to identify areas
that could be improved. Look for:
- Inconsistencies in Claude's responses
- Misunderstandings of user requests
- Areas where Claude could provide more detailed or accurate information
- Opportunities to enhance Claude's ability to handle specific types of
queries or tasks
- New commands or improvements to a commands name, function or response
- Permissions and MCPs we've approved locally that we should add to the
config, especially if we've added new tools or require them for the
command to work
## 2. Interaction Phase
Present your findings and improvement ideas to the human. For each suggestion:
a) Explain the current issue you've identified
b) Propose a specific change or addition to the instructions
c) Describe how this change would improve Claude's performance
Wait for feedback from the human on each suggestion before proceeding.
If the human approves a change, move it to the implementation phase.
If not, refine your suggestion or move on to the next idea.
## 3. Implementation Phase
For each approved change:
a) Clearly state the section of the instructions you're modifying
b) Present the new or modified text for that section
c) Explain how this change addresses the issue identified in the
analysis phase
## 4. Output Format
Present your final output in the following structure:
```xml
<analysis>
[List the issues identified and potential improvements]
</analysis>
<improvements>
[For each approved improvement:
1. Section being modified
2. New or modified instruction text
3. Explanation of how this addresses the identified issue]
</improvements>
<final_instructions>
[Present the complete, updated set of instructions for Claude, incorporating
all approved changes]
</final_instructions>
```
Remember, your goal is to enhance Claude's performance and consistency while
maintaining the core functionality and purpose of the AI assistant. Be thorough
in your analysis, clear in your explanations, and precise in your
implementations.
これはreflection.md - a way to have claude-code self improve its context.から拝借しています。
このスラッシュコマンドを実行すると、Claude Codeが自分のCLAUDE.md
を見直して改善案を提示してくれます。
スラッシュコマンド
先程からいくつかのスラッシュコマンドが出てきていますね。
Claude Codeでは、.claude/commands/
もしくは~/.claude/commands/
ディレクトリにスラッシュコマンドを定義することができます。
スラッシュコマンドは自然言語で記述でき特定のタスクを自動化することができます。
例えば、私はGitでコミットを行うためのスラッシュコマンドを以下のように定義しています。
# Git Commit
YOU MUST: Follow the Git guidelines defined in @../../instructions/git.md
YOU MUST: Use Git MCP server tools for all Git operations when available.
YOU MUST: Only use command line Git operations for functions not supported by the Git MCP server.
Execute the following workflow:
1. Check current git status and staged changes using git_status
2. Review changes with git_diff (both staged and unstaged)
3. **DISPLAY COMMIT CONFIRMATION** - Present the following information to the user for confirmation:
- **Target Branch**: Show the current branch name
- **Files to be committed**: List all staged files with their status (Added, Modified, Deleted, etc.)
- **Proposed commit message**: Show the commit message that will be used
4. **WAIT FOR USER CONFIRMATION** - Ask user to confirm before proceeding with the commit
5. Create commit using git_commit with proper Conventional Commits format and Japanese message
6. Verify commit was created successfully
## Commit Message Format
YOU MUST: Follow Conventional Commits standards with this specific format:
```text
<type> <emoji>: <commit message>
```
## Commit Types
YOU MUST: Choose from the following types:
- **build**: Changes that affect the build system or external dependencies
- **ci**: Changes to CI configuration files and scripts
- **docs**: Documentation only changes
- **feat**: A new feature
- **fix**: A bug fix
- **perf**: A code change that improves performance
- **refactor**: A code change that neither fixes a bug nor adds a feature
- **style**: Changes that do not affect the meaning of the code
- **test**: Adding missing tests or correcting existing tests
## Commit Message Guidelines
YOU MUST: Write commit messages on a single line without line breaks
YOU MUST: Write commit messages concisely and descriptively
YOU MUST: Use noun-ending form (体言止め) in Japanese
YOU MUST: Clearly indicate what was changed or implemented
## Commit Granularity Guidelines
YOU MUST: Make atomic commits - one logical change per commit
YOU MUST: Separate different types of changes into different commits
NEVER: Mix features and bug fixes in a single commit
NEVER: Combine multiple unrelated changes in one commit
Examples of proper commit separation:
- **Wrong**: `feat ✨: ログイン機能の追加とパスワードバリデーションのバグ修正`
- **Correct**:
- `feat ✨: ログイン機能の追加`
- `fix 🐛: パスワードバリデーションのバグ修正`
YOU MUST: For large features, break down into smaller, logical commits:
- **Wrong**: `feat ✨: ユーザー管理システム全体の実装`
- **Correct**:
- `feat ✨: ユーザー登録機能の実装`
- `feat ✨: ユーザー認証機能の実装`
- `feat ✨: ユーザープロフィール管理機能の実装`
## Examples
- `feat ✨: ログイン機能の実装`
- `fix 🐛: データベース接続エラーの修正`
- `docs 📚: README.mdの更新`
- `refactor ♻️: ユーザー認証ロジックのリファクタリング`
このようにGitのコミットを行なう際のルールを定義しています。 内容は大まかに以下のとおりです。
- Gitのルールを定義した
git.md
を参照する- Git全般のガイドラインを書いています
- Git MCPサーバーツールを使用する
- コミットメッセージのフォーマットを定義する
- Conventional Commitsに従う
- 1行で簡潔に記述する
- コミットの粒度を定義する
- 1つのコミットは1つの論理的な変更にする
- 機能追加とバグ修正を同じコミットにしない
- 大きな機能は小さなコミットに分割する
このように定義してあげることで、コミットしてほしいときに毎回、「コミットして。コミットメッセージはConventional Commitsに従って…」と長々と説明する必要がなくなります。
このようにスラッシュコマンドを定義することで、Claude Codeに特定のタスクを自動化させることができます。
MCP Server
Claude CodeはCline等と同じようにModel Context Protocol(以降MCP)Serverを利用することができます。 MCPはLLMが外部のデータソースと連携するためのプロトコルで、Anthropicに酔って標準化されています。
modelcontextprotocol/servers: Model Context Protocol Servers
MCPは、各種LLMに搭載されているfunction calling機能の抽象化レイヤーです。 元々、多くのLLMにはfunction callingと呼ばれる機能があり、LLMが外部のAPIを呼び出すことができます。 しかし、LLMごとにAPIの仕様が異なるため、MCPはその仕様の差異を吸収し、統一的なインターフェースを提供します。
私は現在、Git MCP ServerとGithub MCP Serverを使用しています。 Git MCP Serverは、Gitの操作をMCP経由で行うためのサーバーで、Gitのリポジトリ操作をコマンドを介さずに行なうことができます。 Github MCP Serverは、GitHubのAPIをMCP経由で呼び出すためのサーバーで、GitHubのリポジトリやプルリクエストの操作を行うことができます。(まだ全然使ってません)
他にもAWSやTerraformのドキュメントを参照するMCP Server等が存在しています。
なにかおすすめや便利なMCP Serverがあれば教えてください。
おわりに
この記事では、Claude Codeの概要や使い方、CLAUDE.md
の設定方法、スラッシュコマンドの定義方法などについて書きました。
みなさんもClaude Codeを使って、コーディングの効率を向上させてみてはいかがでしょうか。
それでは、本編はここらへんで終わりにします。
おわり。
おまけ1: お金がありません
Q. Claude Codeを使いたいけどお金がない。
A. Gemini CLIを使ってみてはいかがでしょうか? Gemini CLIはGoogleが2025年6月25日にリリースしたClaude CodeのようなCLIベースのコーディングツールです。 無料でも使うことができ、Gemini 2.5 Proを60リクエスト/分、1000リクエスト/日まで無料で使用することができます。
Gemini CLI を無料で利用するには、個人の Google アカウントでログインし、無償版の Gemini Code Assist ライセンスを取得するだけです。この無料ライセンスにより、Gemini 2.5 Pro と 100 万トークンという広大なコンテキスト ウィンドウにアクセスできます。プレビュー期間中に利用制限することがほとんどないように、業界最大級の利用枠を提供します。毎分 60 回モデル リクエスト、1日あたり1,000 回のリクエストを無料で提供します。
Gemini CLI : オープンソース AI エージェント | Google Cloud 公式ブログ
おまけ2: 余談
ここからは余談です。私が最近のLLM開発界隈に思うことを書きます。
Vibe Codingについて
最近のLLM開発界隈では、Vibe Codingと呼ばれる新しいコーディングスタイルが注目されています。 Vibe Codingというのは、OpenAIの共同創設者であるAndrej Karpathy氏が提唱した開発者が日本語や英語などの自然言語で指示を出すことで、LLMにソフトウェアのコードを生成・修正させる新しいプログラミングの手法です。
Andrej Karpathy氏のTwitter(現𝕏)での投稿
確かにこのような開発手法は人間が職人の手で一つ一つ丁寧にコードを書くよりも高速です。 しかし、私はVibe Codingには以下の問題点が存在すると考えています。
生成されたコードの信頼性と保守性
LLMはその原理上、出力されるコードは確率的にそれっぽいコードであり、必ずしも信頼できるコードではありません。また、LLMは外から見て正しい動作をするコードを生成しますが、それは保守性や可読性、今後の拡張性を考慮して生成されたものではありません。出力されたコードにバグがあった場合、LLMはそのバグを対処できない、人間は可読性の低いコードのためコードを理解できない、のようになってしまうかもしれません。
生成できるコードの限界
LLMは事前学習されたデータによって生成できる言語やフレームワークに限界があります。例えば、2025年6月現在はWeb開発においてはVibe Codingは非常に高い効率で開発を行なうことができます。しかし、Linux Kernelやシステムプログラミング等においてはLLMは頓珍漢なコードを生成することが往々にしてあります。
実際に私がMacOSのルーティングテーブルを取得するためのPF_ROUTE
ソケットを使用するコードを生成させたところ、正しく動作するコードは出力されませんでした。
LLMにWeb検索ツールを使用させ、調査を行なわせたりしましたが有用な情報を得られず、最終的には私自身がGithubでPF_ROUTE
を使用しているコード調査したり、MacOSのカーネルであるXNUのソースコードやFreeBSDのソースコードを調査して実装しました。
LLMは銀の弾丸でも、困難な問題を一発で解決できる神託機械でもない
LLMはまだ銀の弾丸ではなく、計算機科学で困難な問題を一発で解決可能な神託機械でもありません。
ネット上の記事では、LLMに「運転席」を譲って人間は「助手席」や「後部座席」に座って指示を出す、というような表現が見られます2 3。 この表現で言うならば、私はまだ「教習車の助手席」に座るところまでしかできません。 LLMを「運転席」には座らせますが、「ブレーキ」を踏めるようにしつつ、時には横から「ハンドル」を操作できるようにしておく必要があると考えています。 私にとっては、LLMはあくまでコーディングの補助ツールであり、その主導権は人間が握るべきです。
「コードを書く」のは人間より格段に速い
LLMは「コードを書く」のは人間より格段に速いです。 上で色々言いましたが人間がコードを書くのは精々100文字/分程度でしょう。 LLMは数秒で数百行のコードを生成することができます。 これをうまく利用すれば開発の効率を大幅に向上させることができます。 私はLLMにコードを書かせつつ、自分は裏でLLMが書けない部分の実装をしたりしています。
あくまで個人の感想です。 ↩︎
mizchi, CLINEに全部賭けろ, 2025/06/27参照 ↩︎
nwiizo, 生成AIといっしょ:動作するきれいなコードを生成AIとつくる, 2025/06/27参照 ↩︎