AIニュース最前線
最新ニュースAI日報Hacker日報週報動画AIツールトレンド企業

AIニュース最前線

世界中のAI最新情報を日本語で毎時更新

最新ニュース日報トレンド企業プレミアムRSS
© 2026 ainew.jp特定商取引法に基づく表記
ニュース一覧元記事を開く
Claude Blog·2026年6月19日 04:01·約13分で読める

Claude Code の操作:CLAUDE.md ファイル、スキル、フック、ルール、サブエージェントなど

#LLM#Claude Code#Anthropic#Agent Orchestration#Software Development
TL;DR

Anthropic は Claude Code の制御機能を強化し、設定ファイルや自動化機能の拡張を発表した。

AI深層分析2026年6月18日 18:06
4
重要/ 5段階
深度40%
4
関連度30%
5
実用性20%
4
革新性10%
3

キーポイント

1

構造化設定ファイルの導入

CLAUDE.md ファイルを導入することで、開発者がプロジェクト固有のルールやコンテキストを一元管理できるようになった。

2

高度な自動化機能の拡張

スキル(Skills)、フック(Hooks)、およびサブエージェント(Subagents)のサポートにより、複雑なワークフローの自動化が可能となった。

3

開発者体験の向上

これらの新機能により、AI コーディングアシスタントがより文脈を理解し、大規模かつ構造化されたプロジェクトでの実用性が飛躍的に向上する。

影響分析・編集コメントを表示

影響分析

今回の発表は、AI コーディングアシスタントのガバナンスと制御可能性において重要な転換点となる。開発者が AI の振る舞いを細かく定義・自動化できるようになることで、大規模プロジェクトにおける実装リスクが低減し、生産性が劇的に向上する可能性がある。

編集コメント

Claude Code の制御機能が大幅に強化され、実務レベルでの複雑な開発タスクへの対応が可能となりました。特にサブエージェントや設定ファイルの導入は、AI エージェントの実用化に向けた重要な一歩です。

Rules

Rules は、Claude に特定の制約や規約を与える .claude/rules/ ディレクトリ内の Markdown ファイルです。

スコープ指定のないルールは CLAUDE.md と同様に動作し、セッション開始時に常に読み込まれ、コンパクション時にも再注入されます。これにより、現在のタスクに関連しない場合でも文脈が読み込まれてトークンが無駄になる可能性があります。

パススコープ付きのルールを使用すると、paths フィールドを追加して関連する際にのみルール指示を読み込むことができます。

例えば、src/api/** にスコープされたルールは、ドキュメント専用のセッション中は文脈に含まれません。Claude がその src/api/ ディレクトリ内のファイルを読み取る場合にのみ読み込まれます。

具体的な記述例は以下の通りです:


paths:

  • "src/api/**"
  • "**/*.handler.ts"

すべての API ハンドラーは、処理前に Zod を使用して入力を検証する必要があります。ヒント: 「マイグレーションは追加のみ」といったファイル固有の制約は、パス:フロントマターに配置されたルールとして記述するのが最も適しています。コードベースの複数の(ただしすべてではない)箇所にまたがる横断的な関心事やファイルに関する指示の場合は、ネストされた CLAUDE.md ファイルよりも、パススコープ付きのルールを使用してください。

Skills

Skills は .claude/skills/ に配置され、Claude が動的に読み込む指示、スクリプト、リソースのフォルダです。各スキルには、名前、説明、本文を含む SKILL.md ファイルが存在します。

セッション開始時に読み込まれるのは名前と説明のみであり、フルボディは Claude がスラッシュコマンド(/code-review)を介してスキルを呼び出すか、タスクの自動マッチングによって呼び出した際に読み込まれます。

image
image

スキルはシステムプロンプトを介してトリガーされます。例えば、/code-review は組み込みのスキルであり、現在の差分(diff)を検証し、ファイルを編集せずにその結果を報告します。このスキルはプレイブックを定義しており、Claude はこれを呼び出すたびに同じ構造化されたアプローチに従います。

コンパクション(圧縮)時に、Claude Code はすべての呼び出されたスキルにわたる合計予算の範囲内で、呼び出されたスキルを再注入します。セッション中に多くのスキルを呼び出した場合、最も古いものが最初に除外されます。

ヒント: デプロイワークフロー、リリースチェックリスト、レビュープロセスなど、手順的な指示は CLAUDE.md ではなく、スキルの内部に記述すべきです。

Claude Code には標準でスキルが搭載されていますが、独自のカスタムスキルを作成することも可能です。当社の Claude 向けスキルの構築に関する完全ガイド でその方法を確認できます。

サブエージェント

サブエージェント は、特定のサイドタスク用の孤立したアシスタントを定義する .claude/agents/ ディレクトリ内のマークダウンファイルです。各ファイルは YAML フロントマター(名前、説明、およびモデルやツールアクセスに関するオプションフィールド)で始まり、その後に続く本文がサブエージェントのシステムプロンプトとなります。

サブエージェントはスキルと同様に、名前、説明、ツールリストがセッション開始時に読み込まれますが、エージェント本体内のより大きなコンテキストは自動的に呼び出されません。Claude は Agent ツールを介してサブエージェントを呼び出し、プロンプト文字列を渡します。

image
image

Claude Code のコンテキストウィンドウには、セッションに関する Claude が知っているすべての情報が保持されます。インタラクティブなタイムライン では、何がいつ読み込まれるかが解説されています。サブエージェント本体内のより大きな指示用コンテキストが自動的に呼び出されないだけでなく、親会話に全く入力されることもありません。

その後、サブエージェントは独自の新しいコンテキストウィンドウで実行され、メインセッションに戻ってくるのはサブエージェントの最終メッセージ(多くの下位タスクの結果を集約したもの)とメタデータのみです。

このパターンはスケーラブルです:サブエージェントは最大 5 レベルまでネスト可能であり、動的ワークフロー が各サブエージェントアーキテクチャの詳細を指定することなく、数十から数百のバックグラウンドエージェントをオーケストレートします。オーケストレーション計画と中間結果は Claude のコンテキストウィンドウではなくスクリプト変数に保存されるため、指示の忠実性を失うことなくスケールが可能になります。

ヒント: この分離性が、スキルではなくサブエージェントを利用する主な理由の一つです。深い検索やログ分析のパス、依存関係監査などの中継結果がメインの会話に混入し、後で参照されなくなるようなサイドタスクを行う場合はサブエージェントを使用してください。一方、各ステップを確認して制御したい手順をメインスレッド内で実行させたい場合はスキルを使用します。

フック

フックは、ユーザーが定義したコマンド、HTTP エンドポイント、または LLM プロンプトであり、ファイル編集、ツール呼び出し、セッション開始といった Claude のライフサイクル内の特定イベント で発火することで、Claude の動作に対してより決定論的な制御を提供します。

image
image

フックが発火する可能性のある Claude Code セッション内のイベントマップ。フックは settings.json、管理ポリシー設定、またはスキル/エージェントのフロントマターに登録します。

フックにはいくつかの種類があります:コマンド、HTTP、mcp_tool、プロンプト、およびエージェントです。すべてのフックは決定論的にトリガーされますが、最初の 3 つ(コマンド、HTTP、mcp_tool)は決定論的に実行されるのに対し、後者の 2 つ(プロンプトとエージェント)は出力を決定するためにルールセットではなく Claude の判断を使用します。

フックは、設定や指示がメインのコンテキストウィンドウの外側に存在するため、コンテキストコストが低くなります。ハーンは、フックの種類に応じて、ハンドラー(コマンド、HTTP、MCP ツール)を実行するか、別々のウィンドウ(プロンプト、エージェント)を使用してモデル呼び出しを行います。

一部のフックでは、出力がメインのコンテキストウィンドウに保存される場合があります。例えば、ブロッキングフックの標準エラーはコンテキスト内に保存され、Claude がその呼び出しが拒否された理由を理解できるようにします。

ただし、設定で明示的に返さない限り、ほとんどのフックの出力がメインウィンドウに保存されることはありません。PreCompact イベントを使用して、コンパクション前にチャット履歴を別のファイルにバックアップした場合、Claude はどのファイルにチャット履歴が保存されたかを認識できません。

このため、これらのフックタイプは CLAUDE.md、ルール、スキルとは根本的に異なります。詳細については、当社の投稿「フックの設定方法」をご覧ください。

ヒント: 決定論的に行うべきこと(編集後のリンター実行、完了時の Slack への投稿、実行前の特定コマンドのブロックなど)にはフックを使用してください。PreToolUse フックは任意のツール呼び出しを検査し、コード 2 を返して拒否することができます。

これらは Claude に読み込まれてコンテキストに含まれる指示ではなく、ハーンが実行するコードであるため、コンテキストコストが低くなります。

出力スタイル

出力スタイル は、.claude/output-styles/ ディレクトリ内のファイルであり、システムプロンプトに指示を注入するものです。これらは圧縮されず、セッション開始時に毎回読み込まれ、セッション内の最初の要求以降はキャッシュされるため、中程度のコンテキストコストがかかります。

システムプロンプト上に位置するため、出力スタイルはこれまで紹介した手法の中で最も高い指示従順性を持ち、慎重に使用する必要があります。

出力スタイルの変更は、デフォルトの出力スタイルを置き換えます(ただし、スタイルのフロントマターで keep-coding-instructions: true を設定している場合は除きます)。

Claude Code においてこれは、Claude がソフトウェアエンジニアリングタスクの支援を行っていることを示す指示や、セキュリティへの懸念への対応方法、作業完了前にテストを実行するなどの検証習慣など、他の重要なデフォルト指示をすべて削除することになります。デフォルトでは、カスタム出力スタイルはこれらすべての指示をドロップし、Claude Code はソフトウェアエンジニアアシスタントというよりも一般的なアシスタントとして振る舞うようになります。

ヒント: カスタム出力スタイルを作成する前に、組み込みのスタイルを確認してください。Proactive(積極的)、Explanatory(説明的)、および Learning(学習)は、スタイルファイルの維持を必要とせず、自律性、ティーチングモード、共同コーディングという最も一般的なニーズをカバーしています。

システムプロンプトの追加

出力スタイルを変更する代替手段として、append-system-prompt(システムプロンプト追加)フラグがあります。出力スタイルファイルを変更すると Claude の動作に予期せぬ大きな影響を与える可能性がある一方、この追加フラグは元のシステムプロンプトに対して単に加算されるのみです。Claude の役割自体を変更するのではなく、デフォルトの役割に対して指示を追加するだけです。

また、これは呼び出し時に渡され、セッション間でファイルとして永続化されるものではなく、その呼び出し時のみに適用されます。

他の方法で指示を渡す場合に比べて、システムプロンプトを追加するとコンテキストコストが高くなる可能性があります。入力トークン数が増加しますが、セッション内の最初の要求以降はプロンプトキャッシングによりこのコストが軽減されます。また、Claude により詳細または長いスタイルを使用するよう指示すると、出力トークン数も増加します。

ヒント: システムプロンプトの追加は、特定のコーディング規約、出力フォーマット、またはドメイン固有の知識を追加する場合に最も適しています。この方法で提供される指示が多くなるほど、遵守度合いが低下するという限界効果があることを念頭に置いてください。特に、指示同士が矛盾する場合はその傾向が強まります。

Claude Code カスタマイズのためのクイックヒント

もしあなたが以下のいずれかの状況にあると感じるなら、指示を別の場所に配置することを検討してください:

「X のたびに Y を行う」を CLAUDE.md に記載する。 編集のたびに prettier を実行する、完了時に Slack に投稿するなど、確実に発生させるべき動作がある場合は、settings.json でフックを使用してください。モデルがフォーマッターを実行することを選択するのは、フォーマッターが自動的に実行されることとは異なります。

「決してこれを行わない」を CLAUDE.md に記載しない。 絶対に起こしてはならない事柄がある場合、指示はそのための適切なツールではありません。Claude は通常その指示に従いますが、圧力下にあるとき、セッションが長い場合や状況が曖昧な場合、あるいはタスクの一部としてアクセスされたファイル内のプロンプトインジェクションによって、モデルがプロンプトされたルールに従わない可能性があります。真のガードレールは決定論的である必要があり、その強制手段は hooks と permissions です。PreToolUse フックでは呼び出しを検査し、コード 2 で終了してブロックすることができます。Managed settings はさらに先を行きます:これらは管理者によってデプロイされ、ユーザーのローカル設定で上書きできず、組織全体にわたる決定論的なガードレールを強制するための唯一の方法です。

CLAUDE.md に 30 行の手順を記載しない。 手順はスキル(skills)に属します。CLAUDE.md は、Claude が常に保持すべき事実(ビルドコマンド、モノリポジトリのレイアウト、チームの慣習など)のためのものです。デプロイメントの実行手順やセキュリティレビューのチェックリストは .claude/skills/ に置くべきです。これらは呼び出されたときにのみ本文が読み込まれます。

パスを指定しない API 固有のルール。もしルールが src/api/** のみに適用される場合、パスでスコープを限定することで、無関係な作業中にコンテキストから除外できます。スコープを指定しないルールは、機械的には CLAUDE.md ファイルに内容を記述したものと同一です:常に読み込まれ、常にトークンを消費します。

個人用設定をプロジェクトレベルの CLAUDE.md ファイルに書き込むこと。ファイルベースの方法には、どのリポジトリにいるかに関わらず、すべての Claude Code セッションで読み込まれるユーザーレベルの対応策が存在します。個人用設定にはローカルファイルを使用してください(常に意味のあるコミットメッセージを使用すること)。チーム全体向けだが特定のコードベースに固有の設定は、プロジェクトレベルのファイルに記述してください。

はじめに

環境の構成から並列セッションでのスケーリングまで、Claude Code を最大限に活用するためのより多くのヒントやパターンは、Claude Code のベストプラクティスドキュメントで見つけることができます。

これらのいくつかを動作させたら、スキル、サブエージェント、フック、出力スタイルなどを プラグイン としてバンドルし、チームメンバーやプロジェクト間で一貫したセットアップを共有できるようにすることもできます。

原文を表示

Rules

Rules are markdown files in .claude/rules/ that give Claude specific constraints or conventions.

Unscoped rules behave like CLAUDE.md in that they are always loaded at session start and get re-injected on compaction. This can waste tokens by loading context even when it's not relevant for the task at hand.

Path-scoped rules allow you to load rule instructions only when they are relevant by adding a paths field that controls when they load.

For example: a rule scoped to src/api/** stays out of context during a docs-only session. It would only be loaded whenever Claude reads files within that src/api/ directory.

Here’s what that looks like:

code
---
paths:
  - "src/api/**"
  - "**/*.handler.ts"
---
All API handlers must validate input with Zod before processing.

Tip: A file-specific constraint, like "migrations are append-only," fits best as a rule placed in your paths: frontmatter. Reach for a path scoped rule over a nested CLAUDE.md file when the instruction regards a cross-cutting concern or file that appears in multiple (but not all) corners of the codebase.

Skills

Skills live in .claude/skills/ as folders of instructions, scripts, and resources that Claude loads dynamically. Each skill has a SKILL.md file with a name, description, and body.

Only the name and description load at session start; the full body loads when Claude invokes the skill, either through a slash command (/code-review) or by auto-matching the task.

Skills are triggered via your system prompt.
Skills are triggered via your system prompt.

For example, /code-review is a built-in skill that reviews your current diff and reports its findings without editing files. The skill defines the playbook so Claude follows the same structured approach every time you invoke it.

On compaction, Claude Code re-injects invoked skills up to a total budget across all invoked skills. If you’ve invoked many skills during a session, the oldest ones drop first.

Tip: Instructions that are procedural, like deploy workflows, release checklists, or review processes, belong in a skill rather than in CLAUDE.md.

Claude Code ships with skills, but you can also write your own custom skills. Our complete guide to building skills for Claude shows you how.

Subagents

Subagents are markdown files in .claude/agents/ that define isolated assistants for specific side tasks. Each file uses YAML frontmatter (name, description, plus optional fields for model and tool access) followed by a body that becomes that subagent's system prompt.

Subagents are similar to skills in that the name, description, and tool list load at session start, but the larger context within the body of the agent doesn’t auto-invoke. Claude calls them via the Agent tool, passing in a prompt string.

Claude Code’s context window holds everything Claude knows about your session. The [interactive timeline hereClaude Code’s context window holds everything Claude knows about your session. The [interactive timeline here walks through what loads and when. ](https://cdn.prod.website-files.com/68a44d4040f98a4adf2207b6/6a340f852d1f938ab86755a2_914c1942.png)

Not only does the larger instructional context within the body of the subagent not auto-invoke, it never enters the parent conversation at all.

The subagent then runs in its own fresh context window, and the only thing that returns to your main session is the subagent’s final message (often the aggregated result of many subtasks) plus metadata.

This pattern scales: subagents can nest up to five levels deep, and dynamic workflows orchestrate tens to hundreds of background agents without requiring you to specify each detail of the subagent architecture. The orchestration plan and intermediate results live in script variables rather than in Claude’s context window, which enables scale without losing instructional fidelity.

Tip: That isolation is one of the main reasons to reach for a subagent instead of a skill. Use a subagent when a side task like deep search, a log analysis pass, or a dependency audit would clutter your main conversation with intermediate results you won't reference again. Use a skill when you want the procedure to play out inside the main thread so you can see and steer each step.

Hooks

Hooks are user-defined commands, HTTP endpoints, or LLM prompts that provide more deterministic control over Claude’s behavior by firing on specific events in Claude’s lifecycle like file edits, tool calls, or session start.

A map of events in a Claude Code session when a hook can fire.
A map of events in a Claude Code session when a hook can fire.

You register hooks in settings.json, managed policy settings, or skill/agent frontmatter.

There are several types of hooks: command, HTTP, mcp_tool, prompt, and agent. All hooks are deterministically triggered. The first three execute deterministically while the latter two, prompt and agent, use Claude’s judgment rather than a set of rules to determine the output.

Hooks have low context costs because the configuration or instruction lives outside the main context window. The harness runs the handler (command, http, mcp_tool) or makes model calls with separate windows (prompt, agent) depending on the hook type.

Some hooks may have the output saved to the main context window. For example, a blocking hook's standard error is saved within context so Claude knows why the call was denied.

But most hooks won’t have the output saved to the main window unless the configuration explicitly returns it. If you backed up your chat history into another file for later reference before compaction using the PreCompact event, Claude wouldn’t know which file had the chat history saved.

This makes these hook types fundamentally different from CLAUDE.md, rules, and skills. You can learn more in our post how to configure hooks.

Tip: Use hooks for anything that should happen deterministically: running linters after edits, posting to Slack on completion, or blocking specific commands before they execute. A PreToolUse hook can inspect any tool call and exit code 2 to deny it.

They have low context cost because they are code that the harness runs rather than instructions to Claude that get loaded into context.

Output styles

Output styles are files in .claude/output-styles/ that inject instructions into the system prompt. They never get compacted, load at the start of every session, and are cached after the first request within a session, meaning they have a moderate context cost.

Because they sit in the system prompt, output styles carry the highest instruction-following weight of any method that we've covered so far and should be used judiciously.

Changes to the output style will replace the default output style (unless you set keep-coding-instructions: true in the style's frontmatter).

In Claude Code, this would remove instructions that tell Claude it is helping users with software engineering tasks and contains other critical default instructions such as:

  • How to scope changes;
  • When to add or omit code comments;
  • What to do about security concerns; and
  • Verification habits like running tests before declaring work complete.

By default, a custom output style drops all of this and Claude Code becomes more of a general assistant than a software engineer assistant.

Tip: Before writing a custom output style, check the built-in styles. Proactive, Explanatory, and Learning cover the most common needs (autonomy, teaching mode, collaborative coding) without you having to maintain a style file.

Appending the system prompt

An alternative to modifying output styles is the append-system-prompt flag. Whereas modifying output style files can have large, unintended changes to Claude’s behavior, the append flag is only additive to the original system prompt. It doesn’t modify Claude’s role; it just adds instructions to its default role.

It is also passed at invocation time, and only applies to that invocation, rather than persisted as a file across sessions.

Appending the system prompt can have a higher context cost compared to other methods of passing instructions. It increases input tokens, though prompt caching reduces this cost after the first request in a session. Instructing Claude to use a more verbose or longer style also increases output tokens.

Tip: Appending the system prompt is best for adding specific coding standards, output formatting, or domain-specific knowledge. Keep in mind that appending the system prompt has diminishing returns for adherence. Generally, the more instructions you provide using this method, the less strictly Claude will follow them, particularly if any contradict.

Quick tips for Claude Code customization

If you find yourself doing one of the following, you may want to consider an alternative location for your instructions:

"Every time X, always do Y" in CLAUDE.md. If the behavior should happen reliably, like running prettier after every edit or posting to Slack on completion, use a hook in settings.json instead. The model choosing to run a formatter is different from the formatter running automatically.

“Never do this” in CLAUDE.md. When there's something that absolutely must not happen, an instruction is the wrong tool. Claude will follow the instruction most of the time, but when under pressure, in a long session or an ambiguous situation, or due to a prompt injection in a file accessed as part of the task, the model can fail to follow a prompted rule. A real guardrail needs to be deterministic, and the enforcement methods are hooks and permissions. A PreToolUse hook can inspect a call and exit with code 2 to block it. Managed settings go further: they are admin-deployed, cannot be overridden by a user's local config, and are the only way to enforce a deterministic, organization-wide guardrail.

A 30-line procedure in CLAUDE.md. Procedures belong in skills. CLAUDE.md is for facts Claude should hold all the time: build commands, monorepo layout, team conventions. A deployment runbook or a security review checklist should live in .claude/skills/, where the body loads only when invoked.

An API-specific rule without paths. If a rule only applies to src/api/**, scoping it with paths: keeps it out of context during unrelated work. An unscoped rule is mechanically identical to putting the content in CLAUDE.md: always loaded, always costing tokens.

Writing personal preferences to a project-level CLAUDE.md file. All file-based methods have a user-level counterpart loaded for every Claude Code session regardless of which repo you’re in. Use local files for personal preferences (always use semantic commit messages). Keep project-level files for preferences that are team-wide but specific to a given codebase.

Getting started

You can find more tips and patterns for getting the most out of Claude Code, from configuring your environment to scaling across parallel sessions, in our best practices for Claude Code documentation.

Once you have a few of these working, you can bundle many of them (skills, subagents, hooks, output styles) as a plugin to share a coherent setup across teammates or projects.

この記事をシェア

関連記事

TLDR AI★42026年6月19日 09:00

Claude Code がアーティファクト機能をサポート

Anthropic は Claude Code に「アーティファクト」機能を追加し、PR の解説やシステム説明などの作業セッションをライブで共有可能な視覚ページに変換しました。この機能は自動更新やバージョン履歴をサポートし、チームと企業向けベータ版として提供されています。

TechCrunch AI★42026年6月20日 01:01

米国がアンソロピックの「Fable 5」発売を禁止、しかし市場は動じず

米国政府は国家安全保障上の懸念から、アマゾンの研究者らがガードレール回避手法を発見したとして、アンソロピックに対し最新モデル「Fable 5」と「Mythos 5」の販売差し止めを命じた。サイバーセキュリティ研究者らはこの措置が危険だとする公開書簡に署名し、同社も他モデルでも同様の抜け道が存在すると指摘している。

The Zvi★42026年6月19日 23:34

Claude Fable 5 と Mythos 5 の能力に関する記事

Anthropic は、Claude Fable 5 が米政府から不正アクセス(ジャイルブレイク)の懸念によりリリース後わずか3日で利用停止を命じられたと報じています。この措置により、多くのユーザーが失った機能への愛着を表明しています。

今日のまとめ

AI日報で今日の重要ニュースをまとめ読み

ニュース一覧に戻る元記事を読む