npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pyramid-context

v0.1.1

Published

Multi-resolution codebase context for AI coding agents

Readme

pyramid-context

Multi-resolution codebase context for AI coding agents.

Generate a pyramid of context at three zoom levels — a scannable L0 index in your agent config, L1 summaries on disk, and L2 detail files per module — so AI agents can understand your entire codebase without wasting context tokens.

Based on StrongDM's pyramid summaries pattern for AI agent codebase comprehension. See Prior Art for details.

Quick Start

npx pyramid-context

This scans ./src, generates L0/L1/L2 context, and injects the L0 index into AGENTS.md.

How It Works

| Level | Detail | Location | Purpose | |-------|--------|----------|---------| | L0 | 2-3 word tag per file | AGENTS.md / CLAUDE.md | Scan the whole codebase at a glance | | L1 | One sentence per file | .context/L1.md | Decide which files to read deeper | | L2 | Exports, imports, deps | .context/{path}.md | Understand a module without reading source |

L2 files are generated per source file (e.g. .context/analyzers/typescript.ts.md), so agents can pull only the modules they need into context rather than loading the whole codebase.

Commit .context/ to git — the generated context is useful for anyone (human or AI) reading the codebase. Re-run pyramid-context when source changes to keep it fresh.

Install

npm install -g pyramid-context    # global
npm install -D pyramid-context    # devDependency
npx pyramid-context               # one-shot

Usage

# Generate pyramid (default: scans ./src)
pyramid-context

# Custom source directory
pyramid-context --src lib

# Explicit target file
pyramid-context --target AGENTS.md

# Language filter
pyramid-context --lang ts,js

# Use LLM for better descriptions
pyramid-context --llm

# Check if pyramid is stale (for CI / hooks)
pyramid-context --check

# Dry run
pyramid-context --dry-run

# Initialize project
pyramid-context init

Configuration

Optional .pyramidrc.json:

{
  "src": ["src", "lib"],
  "targets": ["AGENTS.md", "CLAUDE.md"],
  "exclude": ["**/*.test.ts", "**/*.spec.ts"],
  "contextDir": ".context",
  "llm": {
    "enabled": true,
    "provider": "anthropic",
    "apiKeyEnv": "ANTHROPIC_API_KEY",
    "model": "claude-haiku-4-5-20251001"
  }
}

LLM Configuration

When --llm is passed (or llm.enabled is set in config), pyramid-context calls an LLM to generate higher-quality L0 tags and L1 summaries. Without an API key it silently falls back to heuristic analysis.

| Field | Default | Description | |-------|---------|-------------| | llm.provider | "anthropic" | "anthropic" or "openai" | | llm.apiKeyEnv | "ANTHROPIC_API_KEY" | Environment variable holding the API key. Restricted to ANTHROPIC_API_KEY, OPENAI_API_KEY, LITELLM_API_KEY. | | llm.model | "claude-haiku-4-5-20251001" | Model ID to use | | llm.baseUrl | (provider default) | Custom API base URL |

LLM results are cached in the manifest — unchanged files won't be re-sent on subsequent runs.

L0 Format

A single pipe-delimited line optimized for minimal tokens:

[Codebase Map]|root:./src|L1:.context/L1.md|L2:.context/{path}.md|agent/{loop.ts:goal poller,runner.ts:LLM tool loop}|tools/{bash.ts:shell exec,wiki.ts:shared wiki}

For a 30-file project, the entire L0 index fits in ~300 tokens.

Language Support

| Language | Extensions | Export Detection | Import Detection | |----------|-----------|-----------------|-----------------| | TypeScript | .ts, .tsx | export function/class/interface/type/const | from '...' | | JavaScript | .js, .jsx, .mjs, .cjs | export, module.exports | from '...', require() | | Python | .py | Top-level def, class, __all__ | import, from ... import | | Go | .go | Capitalized names | import "..." | | Rust | .rs | pub fn/struct/enum/trait | use ... |

Hook Integration

Claude Code

{
  "hooks": {
    "Stop": [{
      "hooks": [{
        "type": "command",
        "command": "npx pyramid-context --check && exit 0 || npx pyramid-context"
      }]
    }]
  }
}

Git Pre-Commit

npx pyramid-context --check 2>/dev/null || npx pyramid-context
git add AGENTS.md CLAUDE.md .context/ 2>/dev/null

Programmatic API

import { generatePyramid, injectIntoFile } from 'pyramid-context'

const pyramid = await generatePyramid({
  src: ['src'],
  languages: ['typescript'],
})

// pyramid.files — array of { path, l0, l1, l2, hash }
// pyramid.l0Index — pipe-delimited string
// pyramid.l1Content — markdown string
// pyramid.staleCount — number of changed files

Porting to Other Languages

The full specification lives in SPEC.md — it describes every output format, algorithm, and edge case in enough detail to reimplement pyramid-context in any language.

The fastest way to port it: give SPEC.md to an AI coding agent and ask it to implement the spec in your language of choice.

Here is a specification for a codebase context generator.
Please implement it in [Python/Go/Rust/etc].

<paste SPEC.md contents>

The spec is self-contained — it covers the output formats (L0/L1/L2), the analyzer regex patterns for each language, the injection algorithm, the manifest format, and the security considerations. No knowledge of this TypeScript implementation is needed.

Prior Art

| Tool | Approach | Limitation | |------|----------|------------| | Vercel @next/codemod agents-md | Pipe-delimited docs index | Next.js-specific | | Aider .aider.repo-map | AST-based repo map | Aider-specific, requires tree-sitter | | StrongDM pyramid summaries | Multi-resolution LLM summaries | Internal technique, not packaged |

pyramid-context combines the best ideas: Vercel's surgical injection + StrongDM's multi-resolution pyramid + universal agent support + automatic code analysis.

License

MIT