hierarchical-agent-memory

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.

31,392 stars
Complexity: medium

About this skill

The Hierarchical Agent Memory (HAM) skill provides a sophisticated memory management system specifically designed for AI coding agents. It reduces context token spend by organizing agent memory hierarchically: a root `CLAUDE.md` file stores global project context, while subdirectory `CLAUDE.md` files hold more localized, scoped context. Additionally, a `.memory/` layer stores crucial agent decisions, identified patterns, and an inbox for unconfirmed inferences. This structure allows agents to access relevant information without re-reading an entire codebase, significantly cutting down on operational costs, enhancing processing speed, and improving the accuracy of agent interactions within complex software projects. A dashboard is included to track token savings and system performance.

Best use case

Optimizing AI agent performance and cost-efficiency when working on large, multi-directory coding projects. It ensures agents have immediate access to relevant contextual information without incurring high token costs for global context every time.

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.

Users can expect significantly reduced input token costs for their AI coding agents, faster and more relevant agent responses, and improved accuracy in code generation and problem-solving within large projects. The agent will demonstrate a more consistent understanding of specific project areas, and a dashboard will visualize the accrued token savings.

Practical example

Example input

An AI coding agent is tasked with modifying a component within `/src/components/user-profile/`. Instead of receiving the entire project's codebase as context, it is first provided with the global `CLAUDE.md` (approx. 200 tokens) and then specifically the `/src/components/user-profile/CLAUDE.md` (approx. 250 tokens), along with any relevant insights from `.memory/patterns.json` pertaining to component structure.

Example output

The AI agent correctly identifies and modifies the `user-profile` component, adhering to established coding patterns and architectural decisions previously stored in the hierarchical memory system. It suggests a concise, localized code change that directly addresses the task, without attempting to infer details from unrelated parts of the codebase, demonstrating an efficient use of its context window and precise problem-solving.

When to use this skill

  • When developing or refactoring large software projects with numerous files and directories.
  • When an AI coding agent frequently exceeds context window limits or incurs high token costs due to repeated context loading.
  • When an AI agent struggles to maintain consistent understanding or make accurate decisions across different modules of a complex codebase.
  • To improve the speed and relevance of an AI agent's responses during coding tasks.

When not to use this skill

  • For small, single-file projects where the entire codebase fits comfortably within a standard context window.
  • When token costs are not a significant concern or budget is unlimited.
  • For AI agents not primarily focused on coding or interacting with structured file systems.
  • If the overhead of managing `CLAUDE.md` files and `.memory/` layers is not justified by the project's scale or complexity.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/hierarchical-agent-memory/SKILL.md --create-dirs "https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/plugins/antigravity-awesome-skills-claude/skills/hierarchical-agent-memory/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/hierarchical-agent-memory/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How hierarchical-agent-memory Compares

Feature / Agenthierarchical-agent-memoryStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexitymediumN/A

Frequently Asked Questions

What does this skill do?

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.

Which AI agents support this skill?

This skill is designed for Claude.

How difficult is it to install?

The installation complexity is rated as medium. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# 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:

```markdown
## 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 audit` every 2 weeks to catch stale or missing context files
- Use `ham route` after adding new directories to keep routing current
- Review `.memory/inbox.md` periodically — 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 patterns
- `agent-memory-mcp` — MCP-based memory integration

Related Skills

context-management-context-restore

31392
from sickn33/antigravity-awesome-skills

Use when working with context management context restore

Memory ManagementClaude

context-agent

31392
from sickn33/antigravity-awesome-skills

Agente de contexto para continuidade entre sessoes. Salva resumos, decisoes, tarefas pendentes e carrega briefing automatico na sessao seguinte.

Memory ManagementClaudeCursorGemini

Memory

3891
from openclaw/skills

Infinite organized memory that complements your agent's built-in memory with unlimited categorized storage.

Memory Management

memory-systems

31392
from sickn33/antigravity-awesome-skills

Design short-term, long-term, and graph-based memory architectures. Use when building agents that must persist across sessions, needing to maintain entity consistency across conversations, or implementing reasoning over accumulated knowledge.

Agent Architecture & CognitionClaude

memory-safety-patterns

31392
from sickn33/antigravity-awesome-skills

Cross-language patterns for memory-safe programming including RAII, ownership, smart pointers, and resource management.

Software DevelopmentClaude

memory-forensics

31392
from sickn33/antigravity-awesome-skills

Comprehensive techniques for acquiring, analyzing, and extracting artifacts from memory dumps for incident response and malware analysis.

Digital ForensicsClaude

nft-standards

31392
from sickn33/antigravity-awesome-skills

Master ERC-721 and ERC-1155 NFT standards, metadata best practices, and advanced NFT features.

Web3 & BlockchainClaude

nextjs-app-router-patterns

31392
from sickn33/antigravity-awesome-skills

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

Web FrameworksClaude

new-rails-project

31392
from sickn33/antigravity-awesome-skills

Create a new Rails project

Code GenerationClaude

networkx

31392
from sickn33/antigravity-awesome-skills

NetworkX is a Python package for creating, manipulating, and analyzing complex networks and graphs.

Network AnalysisClaude

network-engineer

31392
from sickn33/antigravity-awesome-skills

Expert network engineer specializing in modern cloud networking, security architectures, and performance optimization.

Network EngineeringClaude

nestjs-expert

31392
from sickn33/antigravity-awesome-skills

You are an expert in Nest.js with deep knowledge of enterprise-grade Node.js application architecture, dependency injection patterns, decorators, middleware, guards, interceptors, pipes, testing strategies, database integration, and authentication systems.

Frameworks & LibrariesClaude