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

contextprism

v1.0.0

Published

High-performance AST codebase context distiller and token optimizer for AI coding agents

Downloads

156

Readme

ContextPrism (prism)

ContextPrism distills codebases into high-density AST skeletons for AI coding agents (Claude Code, Cursor, Codex, OpenCode, Antigravity).

Instead of sending full implementation bodies, loop iterations, and boilerplate to LLM context windows, ContextPrism extracts interfaces, type definitions, class schemas, exported function signatures, and docstrings.

                    ┌─────────────────────────┐
                    │     Raw Codebase        │
                    │   (100,000+ tokens)     │
                    └───────────┬─────────────┘
                                │
                        [ ContextPrism ]
                        (AST Distillation)
                                │
                    ┌───────────▼─────────────┐
                    │    Distilled Context    │
                    │   (~15,000 tokens)      │
                    │   - 70% to 85% Savings  │
                    │   - 100% Type Contracts │
                    └─────────────────────────┘

Key Features

  • Multi-Language AST Distillation: Native parsers for TypeScript, JavaScript, Python, Go, Rust, and generic C-family languages.
  • Token Budget Allocator: Specify --budget 8000 to dynamically compress non-target files while keeping focused files at full fidelity.
  • Multi-Format Context: Generate Anthropic/Gemini XML <codebase>, standard Markdown, compact plain text, or structured JSON.
  • Built-in Model Context Protocol (MCP): Run prism mcp to connect directly with Cursor, Claude Desktop, and Antigravity.
  • AST-Enriched Git Diffs: Run prism diff to pair git diffs with structural signatures of modified files.
  • Local Web Visualizer: Run prism ui to launch an interactive dashboard with live code comparison and token metrics.

Installation

Run directly with npx or install globally:

# Direct execution without install
npx contextprism pack

# Global install
npm install -g contextprism

Quick Start

1. Pack Codebase into an AI Context Prompt

# Default XML format for Claude or Gemini
prism pack

# Save to file
prism pack -o context.xml

# Set a strict 10,000 token budget
prism pack --budget 10000 -o prompt.xml

# Focus on specific files while skeletonizing the rest
prism pack --focus src/auth/login.ts -o prompt.xml

# Export as Markdown
prism pack -f markdown -o context.md

2. View Token Footprint Tree

prism tree

Output:

├── src/
│   ├── ast/
│   │   ├── extractor.ts [222 tokens] (skeleton)
│   │   └── ts-parser.ts [163 tokens] (skeleton)
│   ├── core/
│   │   ├── budgeter.ts [408 tokens] (skeleton)
│   │   └── scanner.ts [720 tokens] (skeleton)
Total: 34 files, 15.0k distilled tokens (33.6k raw)

3. Inspect a Single File Skeleton

prism ast src/ast/ts-parser.ts

Output:

// ContextPrism AST Skeleton: src/ast/ts-parser.ts
// Tokens: 163 tokens (was 1.8k tokens, -91%)

import ts from 'typescript';
export interface TsSkeletonOptions {
    preserveDocstrings?: boolean;
    preserveImports?: boolean;
    preservePrivateMembers?: boolean;
}
export function extractTsSkeleton(code: string, fileName = 'source.ts', options: TsSkeletonOptions = {}): string { /* ... */ }

4. Benchmark Token Savings

prism bench

Output:

┌────────────────────────┬─────────────┬─────────────┬──────────────┬─────────────┐
│ Compression Mode       │ Total Size  │ Est. Tokens │ Token Saving │ Claude Cost │
├────────────────────────┼─────────────┼─────────────┼──────────────┼─────────────┤
│ 1. Raw Source Code     │    101.7 KB │ 33.6k tokens │           0% │   $0.100668 │
│ 2. Light (No Comments) │    101.6 KB │ 33.5k tokens │           0% │   $0.100542 │
│ 3. AST Skeleton        │     45.0 KB │ 15.0k tokens │          55% │   $0.045045 │
│ 4. Types & Interfaces  │     26.4 KB │ 9.1k tokens │          73% │   $0.027291 │
└────────────────────────┴─────────────┴─────────────┴──────────────┴─────────────┘

5. Launch Interactive Web Dashboard

prism ui

Opens a local web interface at http://localhost:4100 with real-time token gauges, side-by-side AST comparison, and one-click context generation.


MCP Server Configuration

Add ContextPrism as a tool server in your claude_desktop_config.json, Cursor, or Antigravity MCP settings:

{
  "mcpServers": {
    "context-prism": {
      "command": "npx",
      "args": ["-y", "contextprism", "mcp"]
    }
  }
}

Exposed MCP Tools

| Tool | Parameters | Description | | :--- | :--- | :--- | | prism_get_codebase_context | directory, budget_tokens, focus_files, mode, format | Returns AST-distilled codebase context | | prism_get_file_skeleton | file_path, mode | Returns structural skeleton of a single file | | prism_get_file_tree | directory | Returns token-annotated project directory tree |


Programmatic API

You can use ContextPrism directly in your own scripts:

import { scanDirectory, applyTokenBudget, packageCodebase, extractTsSkeleton } from 'contextprism';

// 1. Scan directory
const files = scanDirectory('./src');

// 2. Distill with token budget
const budgetResult = applyTokenBudget(files, {
  budgetTokens: 8000,
  defaultLevel: 'skeleton',
  focusFiles: ['src/index.ts']
});

// 3. Format as XML prompt
const xmlPrompt = packageCodebase(budgetResult, { format: 'xml' });
console.log(xmlPrompt);

Supported File Types

| Language | Extracted AST Elements | | :--- | :--- | | TypeScript / JS | Interfaces, type aliases, enums, class structures, method signatures, exports, JSDoc | | Python | Classes, method signatures, decorators, type hints, docstrings, top-level constants | | Go | Package headers, struct definitions, interfaces, function signatures | | Rust | Structs, enums, traits, impl blocks, method signatures | | JSON | Structure schemas, compacted large arrays, key maps | | Generic (C/C++, Java, PHP, C#) | Class headers, method signatures, public declarations |


Development

# Clone repository
git clone https://github.com/mewsyy/context-prism.git
cd context-prism

# Install dependencies
npm install

# Run tests
npm test

# Build package
npm run build

License

MIT