🛠️ HierarchicalエージェントMemory
ClaudeのAIが情報を処理する際のコストを抑える
📺 まず動画で見る(YouTube)
▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
Scoped CLAUDE.md memory system that reduces context token spend. Creates directory-level context files, tracks savings via dashboard, and routes agents to the right sub-context.
🇯🇵 日本人クリエイター向け解説
ClaudeのAIが情報を処理する際のコストを抑える
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o hierarchical-agent-memory.zip https://jpskill.com/download/2963.zip && unzip -o hierarchical-agent-memory.zip && rm hierarchical-agent-memory.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/2963.zip -OutFile "$d\hierarchical-agent-memory.zip"; Expand-Archive "$d\hierarchical-agent-memory.zip" -DestinationPath $d -Force; ri "$d\hierarchical-agent-memory.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
hierarchical-agent-memory.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
hierarchical-agent-memoryフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
💬 こう話しかけるだけ — サンプルプロンプト
- › Hierarchical Agent Memory を使って、最小構成のサンプルコードを示して
- › Hierarchical Agent Memory の主な使い方と注意点を教えて
- › Hierarchical Agent Memory を既存プロジェクトに組み込む方法を教えて
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
階層型エージェントメモリ (HAM)
AIコーディングエージェントが、プロンプトごとにプロジェクト全体を再読み込みする代わりに、各ディレクトリのチートシートを利用できるようにするスコープ付きメモリシステムです。ルートの CLAUDE.md にはグローバルコンテキスト(約200トークン)が、サブディレクトリの CLAUDE.md ファイルにはスコープ付きコンテキスト(それぞれ約250トークン)が保持され、.memory/ レイヤーには決定、パターン、および未確認の推論のための受信トレイが保存されます。
このスキルを使用するタイミング
- Claude Code セッション全体で入力トークンコストを削減したい場合にご利用ください。
- プロジェクトに3つ以上のディレクトリがあり、エージェントが同じファイルを繰り返し読み込んでいる場合にご利用ください。
- モノリシックな CLAUDE.md 1つではなく、ディレクトリスコープのコンテキストが必要な場合にご利用ください。
- トークン節約、セッション履歴、コンテキストの状態を視覚化するダッシュボードが必要な場合にご利用ください。
- 新しいプロジェクトをセットアップし、初日から構造化されたエージェントメモリが必要な場合にご利用ください。
仕組み
ステップ1: セットアップ ("go ham")
プロジェクトのプラットフォームと成熟度を自動検出し、メモリ構造を生成します。
project/
├── CLAUDE.md # ルートコンテキスト (~200トークン)
├── .memory/
│ ├── decisions.md # アーキテクチャ決定記録
│ ├── patterns.md # 再利用可能なパターン
│ ├── inbox.md # 確認待ちの推論項目
│ └── audit-log.md # 監査履歴
└── src/
├── api/CLAUDE.md # api/ のスコープ付きコンテキスト
├── components/CLAUDE.md
└── lib/CLAUDE.md
ステップ2: コンテキストルーティング
ルートの CLAUDE.md には、エージェントにどのサブコンテキストをロードするかを正確に伝えるルーティングセクションが含まれています。
## Context Routing
→ api: src/api/CLAUDE.md
→ components: src/components/CLAUDE.md
→ lib: src/lib/CLAUDE.md
エージェントはルートを読み込み、すぐに該当するサブディレクトリのコンテキストをロードします。推測は不要です。
ステップ3: ダッシュボード ("ham dashboard")
localhost:7777 でウェブダッシュボードを起動し、以下を視覚化します。
- トークン節約量(HAM-on と HAM-off セッションの比較)
- 日ごとのトークンとコストの傾向
- ディレクトリごとのセッション内訳
- コンテキストファイルの状態(CLAUDE.md の欠落/陳腐化/継承カバレッジ)
- ルーティングの遵守状況(エージェントがルーティングマップに従う頻度)
- 炭素/エネルギー推定値
コマンド
| トリガー | 動作内容 |
|---|---|
go ham |
HAM をセットアップ — プラットフォームを自動検出し、CLAUDE.md ファイルを生成します |
ham savings |
トークンとコストの節約レポートを表示します |
ham dashboard |
対話型ウェブダッシュボードを起動します |
ham audit |
メモリファイルの健全性チェックを行います |
ham insights |
セッションデータから実用的な洞察を生成します |
ham route |
ルートの CLAUDE.md にコンテキストルーティングセクションを追加/更新します |
ham carbon |
エネルギーと炭素効率のデータを表示します |
例
例1: 初回セットアップ
User: go ham
Agent: HAM setup complete. Created 8 files.
- CLAUDE.md (root)
- .memory/decisions.md
- .memory/patterns.md
- .memory/inbox.md
- src/api/CLAUDE.md
- src/components/CLAUDE.md
- src/lib/CLAUDE.md
- src/utils/CLAUDE.md
Baseline captured in .memory/baseline.json
Run "HAM savings" to see your token and cost savings.
例2: 節約量の確認
User: ham savings
Agent:
Before HAM: ~7,500 tokens/prompt
After HAM: ~450 tokens/prompt
Savings: 7,050 tokens (94%)
Monthly projection (1,500 prompts):
Sonnet: ~$31.73 saved
Opus: ~$158.63 saved
ベストプラクティス
- ルートの CLAUDE.md は60行/250トークン以下に保ってください。
- サブディレクトリの CLAUDE.md ファイルはそれぞれ75行以下に保ってください。
- 2週間ごとに
ham auditを実行して、陳腐化または欠落しているコンテキストファイルを検出してください。 - 新しいディレクトリを追加した後は
ham routeを使用して、ルーティングを最新の状態に保ってください。 .memory/inbox.mdを定期的に確認し、推論された項目を承認または拒否してください。
制限事項
- トークン推定は、実際のトークナイザーではなく、約4文字=1トークンの近似値を使用しています。
- ベースラインの節約比較は、典型的なエージェントの動作に基づいた推定値です。
- ダッシュボードには Node.js 18+ が必要で、
~/.claude/projects/からセッションデータを読み込みます。 - コンテキストルーティングの検出は、セッション JSONL ファイル内の CLAUDE.md の読み込み順序に依存します。
- サブディレクトリの CLAUDE.md コンテンツは自動更新されません。これらは手動で、または
ham auditを介して維持する必要があります。 - 炭素推定は、リアルタイムのエネルギーデータではなく、地域のグリッド平均を使用しています。
関連スキル
agent-memory-systems— 一般的なエージェントメモリのアーキテクチャパターンagent-memory-mcp— MCPベースのメモリ統合
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Hierarchical Agent Memory (HAM)
Scoped memory system that gives AI coding agents a cheat sheet for each directory instead of re-reading your entire project every prompt. Root CLAUDE.md holds global context (~200 tokens), subdirectory CLAUDE.md files hold scoped context (~250 tokens each), and a .memory/ layer stores decisions, patterns, and an inbox for unconfirmed inferences.
When to Use This Skill
- Use when you want to reduce input token costs across Claude Code sessions
- Use when your project has 3+ directories and the agent keeps re-reading the same files
- Use when you want directory-scoped context instead of one monolithic CLAUDE.md
- Use when you want a dashboard to visualize token savings, session history, and context health
- Use when setting up a new project and want structured agent memory from day one
How It Works
Step 1: Setup ("go ham")
Auto-detects your project platform and maturity, then generates the memory structure:
project/
├── CLAUDE.md # Root context (~200 tokens)
├── .memory/
│ ├── decisions.md # Architecture Decision Records
│ ├── patterns.md # Reusable patterns
│ ├── inbox.md # Inferred items awaiting confirmation
│ └── audit-log.md # Audit history
└── src/
├── api/CLAUDE.md # Scoped context for api/
├── components/CLAUDE.md
└── lib/CLAUDE.md
Step 2: Context Routing
The root CLAUDE.md includes a routing section that tells the agent exactly which sub-context to load:
## Context Routing
→ api: src/api/CLAUDE.md
→ components: src/components/CLAUDE.md
→ lib: src/lib/CLAUDE.md
The agent reads root, then immediately loads the relevant subdirectory context — no guessing.
Step 3: Dashboard ("ham dashboard")
Launches a web dashboard at localhost:7777 that visualizes:
- Token savings (HAM-on vs HAM-off sessions)
- Daily token and cost trends
- Per-directory session breakdown
- Context file health (missing/stale/inherited CLAUDE.md coverage)
- Routing compliance (how often the agent follows the routing map)
- Carbon/energy estimates
Commands
| Trigger | What it does |
|---|---|
go ham |
Set up HAM — auto-detect platform, generate CLAUDE.md files |
ham savings |
Show token and cost savings report |
ham dashboard |
Launch the interactive web dashboard |
ham audit |
Health check on memory files |
ham insights |
Generate actionable insights from session data |
ham route |
Add/update Context Routing section in root CLAUDE.md |
ham carbon |
Show energy and carbon efficiency data |
Examples
Example 1: First-time setup
User: go ham
Agent: HAM setup complete. Created 8 files.
- CLAUDE.md (root)
- .memory/decisions.md
- .memory/patterns.md
- .memory/inbox.md
- src/api/CLAUDE.md
- src/components/CLAUDE.md
- src/lib/CLAUDE.md
- src/utils/CLAUDE.md
Baseline captured in .memory/baseline.json
Run "HAM savings" to see your token and cost savings.
Example 2: Checking savings
User: ham savings
Agent:
Before HAM: ~7,500 tokens/prompt
After HAM: ~450 tokens/prompt
Savings: 7,050 tokens (94%)
Monthly projection (1,500 prompts):
Sonnet: ~$31.73 saved
Opus: ~$158.63 saved
Best Practices
- Keep root CLAUDE.md under 60 lines / 250 tokens
- Keep subdirectory CLAUDE.md files under 75 lines each
- Run
ham auditevery 2 weeks to catch stale or missing context files - Use
ham routeafter adding new directories to keep routing current - Review
.memory/inbox.mdperiodically — confirm or reject inferred items
Limitations
- Token estimates use ~4 chars = 1 token approximation, not a real tokenizer
- Baseline savings comparisons are estimates based on typical agent behavior
- Dashboard requires Node.js 18+ and reads session data from
~/.claude/projects/ - Context routing detection relies on CLAUDE.md read order in session JSONL files
- Does not auto-update subdirectory CLAUDE.md content — you maintain those manually or via
ham audit - Carbon estimates use regional grid averages, not real-time energy data
Related Skills
agent-memory-systems— general agent memory architecture patternsagent-memory-mcp— MCP-based memory integration