4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Claude Code】`/init`コマンドで`CLAUDE.md`作る時って何のファイル読んでるの?

Last updated at Posted at 2025-06-05

開発中のプロジェクトでClaude Codeを使用していきたいと思い、/initコマンドを実行してみました。

Let's Init!

プロジェクトのルートディレクトリで$ claudeコマンドを実行したら、以下のような出力が返ってくると思います。

╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code!                         │
│                                                   │
│   /help for help, /status for your current setup  │
│                                                   │
│   cwd: /Users/testuser/code/TEST/test             │
│                                                   │
│   ─────────────────────────────────────────────── │
│                                                   │
│   Overrides (via env):                            │
│                                                   │
│   • Prompt caching: off                           │
╰───────────────────────────────────────────────────╯

 Tips for getting started:

 1. Run /init to create a CLAUDE.md file with instructions for Claude
 2. Use Claude to help with file analysis, editing, bash commands and git
 3. Be as specific as you would with another engineer for the best results

以下の入力ボックスに、/initを入力して叩いてみます。

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ >                                                                                                                                                                                                                                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
  ? for shortcuts

すると、以下のような出力が返ってきました。

> /init is analyzing your codebase… 

⏺ Certainly, I'll analyze the codebase and create a CLAUDE.md file with the requested information. First, I'll check if there's an existing CLAUDE.md file and gather information from other relevant files.

⏺ Search(pattern: "CLAUDE.md")
  ⎿  Found 0 files

⏺ Search(pattern: "README.md")
  ⎿  Found 1 file (ctrl+r to expand)

⏺ Search(pattern: ".cursor/rules/*")
  ⎿  Found 0 files

⏺ Search(pattern: ".github/copilot-instructions.md")
  ⎿  Found 0 files

⏺ It appears there's no existing CLAUDE.md file, but there is a README.md file. I'll read the README.md file to gather important information.

⏺ Read(README.md)
  ⎿  Read 83 lines (ctrl+r to expand)

⏺ Based on the information from the README.md, I'll create a CLAUDE.md file with the relevant information. I'll use the Write tool to create the file.

⏺ Write(CLAUDE.md)
  ⎿  Wrote 109 lines to CLAUDE.md
     # CLAUDE.md
     This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
     ## Environment Setup
     The project uses Docker for development. Here are the steps to set up the environment:
     1. Clone the repository:
        ```
     … +99 lines (ctrl+r to expand)

⏺ I have created the CLAUDE.md file with the requested information. The file includes:

  1. Environment setup instructions
  2. Technology stack details
  3. Common development commands
  4. Git hooks setup and configuration
  5. Important notes about the project structure and best practices

  The file is prefixed with the specified text and focuses on providing guidance specific to this repository without including generic development practices or made-up information.

  Is there anything else you'd like me to add or modify in the CLAUDE.md file?

一個一個見ていきましょう。

解説

最初の文章

⏺ Certainly, I'll analyze the codebase and create a CLAUDE.md file with the requested information. First, I'll check if there's an existing CLAUDE.md file and gather information from other relevant files.

DeepLに投げるとこんな感じで翻訳してくれました。

確かに、私はコードベースを分析して、要求された情報を含むCLAUDE.mdファイルを作成する。まず、既存のCLAUDE.mdファイルがあるかどうかをチェックし、他の関連ファイルから情報を集める。

ファイル探し

CLAUDE.mdが存在しているか確認

⏺ Search(pattern: "CLAUDE.md")
  ⎿  Found 0 files

README.mdが存在しているか確認

⏺ Search(pattern: "README.md")
  ⎿  Found 1 file (ctrl+r to expand)

Cursorのルールファイルが存在しているか確認

RubyMineで実行したけど、Cursorの設定も読み込んでくれるのかな?ということは、エディタ特有のルールじゃなくて、PC全体でルールを統一できるってことか。(自分にとっては好都合かも)

⏺ Search(pattern: ".cursor/rules/*")
  ⎿  Found 0 files

Github Copilotのルールファイルが存在しているか確認

これもCursorの時と同じですね。

⏺ Search(pattern: ".github/copilot-instructions.md")
  ⎿  Found 0 files

途中の文章

⏺ It appears there's no existing CLAUDE.md file, but there is a README.md file. I'll read the README.md file to gather important information.

DeepLの翻訳してもらうとこんな感じ。

CLAUDE.mdファイルは存在しないようだが、README.mdファイルはある。README.mdファイルを読んで重要な情報を集めることにする。

よろしくだぜっ!

README.mdを読む

⏺ Read(README.md)
  ⎿  Read 83 lines (ctrl+r to expand)

READMEスカスカじゃん...

途中の文章2

⏺ Based on the information from the README.md, I'll create a CLAUDE.md file with the relevant information. I'll use the Write tool to create the file.

DeepLに翻訳してもらうとこんな感じ。

README.mdの情報を元に、関連情報を記載したCLAUDE.mdファイルを作成してみる。ファイルの作成にはWriteツールを使う。

CLAUDE.md作れー!

⏺ Write(CLAUDE.md)
  ⎿  Wrote 109 lines to CLAUDE.md
     # CLAUDE.md
     This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
     ## Environment Setup
     The project uses Docker for development. Here are the steps to set up the environment:
     1. Clone the repository:
        ```
     … +99 lines (ctrl+r to expand)

99行書いてくれたっぽい!

最後の文章

⏺ I have created the CLAUDE.md file with the requested information. The file includes:

  1. Environment setup instructions
  2. Technology stack details
  3. Common development commands
  4. Git hooks setup and configuration
  5. Important notes about the project structure and best practices

  The file is prefixed with the specified text and focuses on providing guidance specific to this repository without including generic development practices or made-up information.

  Is there anything else you'd like me to add or modify in the CLAUDE.md file?

翻訳すると、、、

CLAUDE.mdファイルを作成しました。このファイルには

  1. 環境設定の指示
  2. 技術スタックの詳細
  3. 一般的な開発コマンド
  4. Gitフックのセットアップと設定
  5. プロジェクトの構造とベストプラクティスに関する重要な注意事項

  このファイルには指定のテキストを先頭に付け、一般的な開発プラクティスやでっち上げの情報を含めず、このリポジトリに特化したガイダンスを提供することに重点を置いています。

  CLAUDE.mdファイルに追加・修正してほしいことはありますか?

実際に、ルートディレクトリにCLAUDE.mdが作成されていました!

CLAUDE.mdって何のために使うの?

Claudeさんに聞いてみました。

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > What do you use Claude.md for?                                                                                                                                                                                                                 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

回答は以下です。

⏺ CLAUDE.md is used to provide guidance and important information to Claude Code (claude.ai/code) when working with the code in this repository. It serves as a quick reference for:

  1. Environment setup instructions
  2. Technology stack details
  3. Common development commands
  4. Project-specific configurations and practices

  This file helps future instances of Claude Code to quickly understand the project structure, setup process, and important development workflows, allowing for more efficient and accurate assistance with the codebase.

翻訳すると、

⏺ CLAUDE.mdは、このリポジトリにあるコードを扱う際に、クロード・コード(claude.ai/code)にガイダンスと重要な情報を提供するために使用されます。クイックリファレンスとしての役割を果たします:

  1. 環境設定の指示
  2. 技術スタックの詳細
  3. 一般的な開発コマンド
  4. プロジェクト固有の設定とプラクティス

  このファイルは、Claude Code の将来のインスタンスが、プロジェクトの構造、セットアッププロセス、重要な開発ワークフローをすばやく理解するのに役立ち、コードベースのより効率的で正確な支援を可能にします。

なるほど。開発支援を効率よくかつ、正確に行うために作成されて使われるのか。CLAUDE.mdにアプリケーションの仕様を記載しておけば、より良い支援が受けられるというわけですね!

Claude Codeにコードを読んで仕様書を作ってもらった

Claude Codeで以下のようなリクエストを出しました。

メーカー管理機能についてどのような仕様になっているかの説明書をマークダウンファイルで作ってください。

返ってきた出力は以下です。

⏺ Search(pattern: "**/*maker*.rb")
  ⎿  Found 10 files (ctrl+r to expand)

⏺ これらのファイルの中から、主要な情報を含むと思われるファイルを読み取ります。

⏺ Read(app/models/maker.rb)
  ⎿  Read 11 lines (ctrl+r to expand)

⏺ Read(app/controllers/makers_controller.rb)
  ⎿  Read 87 lines (ctrl+r to expand)

⏺ Read(db/migrate/20241108053246_create_makers.rb)
  ⎿  Read 13 lines (ctrl+r to expand)

⏺ これらの情報を元に、メーカー管理機能の仕様説明書を作成します。

⏺ Write(メーカー管理機能仕様.md)
  ⎿  Wrote 66 lines to メーカー管理機能仕様.md
     # メーカー管理機能仕様
     ## 概要
     メーカー管理機能は、デバイスやその他の機器のメーカー情報を管理するための機能です。この機能により、ユーザーはメーカーの追加、編集、削除、および一覧表示を行うことができます。
     ## データモデル
     ### Maker
     - `id`: 整数(主キー)
     - `maker`: 文字列(必須)
     … +56 lines (ctrl+r to expand)

⏺ メーカー管理機能の仕様説明書をマークダウンファイルで作成し、/Users/testuser/code/TEST/test/メーカー管理機能仕様.mdに保存しました。この文書には以下の内容が含まれています:

  1. 概要
  2. データモデル
  3. 関連
  4. 機能(一覧表示、詳細表示、作成、編集、削除)
  5. バリデーション
  6. セキュリティ
  7. 注意事項
  8. 将来の改善点

  この仕様書は、現在の実装に基づいて作成されています。開発チームや他の関係者がメーカー管理機能について理解を深めるのに役立つでしょう。必要に応じて、この文書を更新または拡張することをお勧めします。

ファイル指定していないのに、良きに計らってコードを読んでくれましたね。

作られたファイルは以下です。

# メーカー管理機能仕様

## 概要
メーカー管理機能は、デバイスやその他の機器のメーカー情報を管理するための機能です。この機能により、ユーザーはメーカーの追加、編集、削除、および一覧表示を行うことができます。

## データモデル

### Maker
- `id`: 整数(主キー)
- `maker`: 文字列(必須)
- `note`: テキスト(最大1000文字)
- `created_user_id`: 整数(作成者のユーザーID)
- `updated_user_id`: 整数(最終更新者のユーザーID)
- `created_at`: タイムスタンプ
- `updated_at`: タイムスタンプ

## 関連
- `devices`: 1対多の関係(メーカーは複数のデバイスを持つ)
- `change_warehouse_orders`: 1対多の関係(メーカーは複数の倉庫変更オーダーを持つ)

## 機能

### 1. メーカー一覧表示
- ルート: GET `/makers`
- 全てのメーカーを一覧表示します。
- DataTablesを使用して、AJAXベースの動的な一覧表示を行います。

### 2. メーカー詳細表示
- ルート: GET `/makers/:id`
- 特定のメーカーの詳細情報を表示します。

### 3. 新規メーカー作成
- ルート: GET `/makers/new`(フォーム表示)
- ルート: POST `/makers`(作成処理)
- 新しいメーカーを作成します。
- 作成者と更新者のIDは現在のユーザーIDが自動的に設定されます。

### 4. メーカー編集
- ルート: GET `/makers/:id/edit`(フォーム表示)
- ルート: PATCH/PUT `/makers/:id`(更新処理)
- 既存のメーカー情報を編集します。
- 更新者のIDは現在のユーザーIDが自動的に設定されます。

### 5. メーカー削除
- ルート: DELETE `/makers/:id`
- 指定されたメーカーを削除します。
- 関連するデバイスや倉庫変更オーダーも同時に削除されます(依存関係の設定による)。

## バリデーション
- `maker`フィールドは必須です。
- `note`フィールドは最大1000文字までです。

## セキュリティ
- 入力されたデータはサニタイズされ、安全にHTMLのエスケープが解除されます。

## 注意事項
- メーカーを削除する際は、関連するデバイスや倉庫変更オーダーも削除されるため、慎重に行う必要があります。
- メーカー名(`maker`フィールド)は一意である必要があります(ただし、現在のモデル定義では明示的に指定されていません)。

## 将来の改善点
1. メーカー名の一意性制約の追加
2. ソフトデリート機能の実装(物理削除ではなく論理削除)
3. メーカー情報の変更履歴の追跡
4. メーカー情報へのアクセス権限の細分化

この仕様書は現在の実装に基づいています。将来の要件変更や機能拡張に応じて更新する必要があります。

実装者としては、かなり正確に読んでくれているなぁという印象です。すごいね、Claude Code!

おまけ

今回費やしたコスト

1ドル未満!

> /cost 
  ⎿  Total cost:            $0.84
     Total duration (API):  1m 43.0s
     Total duration (wall): 36m 11.9s
     Total code changes:    175 lines added, 0 lines removed
     Token usage by model:
        claude-3-5-sonnet:  262.5k input, 3.2k output, 0 cache read, 0 cache write

以上

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?