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

context-masker

v1.2.2

Published

Bidirectional reversible desensitization middleware for coding agents

Readme

Context Masker

A bidirectional reversible desensitization middleware for coding agents.

What it does

Context Masker intercepts sensitive data before LLM API calls and restores it after, preventing sensitive information leakage when using external LLM APIs.

Agent Tool Output → [Mask] → LLM API → [Restore] → Agent

Features

  • Regex-based detection - Fast, deterministic detection of sensitive data
  • Informative placeholders - LLM sees <<EMAIL:0***>> instead of actual emails
  • Reversible masking - Original values restored in LLM responses
  • CLI & Library - Use as command-line tool or import as TypeScript library
  • Configurable categories - Enable/disable PII, credentials, infrastructure patterns
  • Session-scoped storage - TTL-based mapping expiration
  • Tool integration - Works with Claude Code, OpenCode, Cursor, Hermes, and more
  • Logging & metrics - Track masking statistics and performance
  • Custom patterns - Add your own detection rules

Supported patterns

| Category | Patterns | |----------|----------| | PII | Email, phone, SSN, IPv4, credit card | | Credentials | API keys, AWS secrets, passwords, OAuth tokens, JWTs, GitHub/Stripe/Slack tokens, private keys (RSA, EC, DSA, OpenSSH) | | Infrastructure | Database URLs |

Installation

npm install context-masker

Quick start

As a library

import { createContextMasker } from 'context-masker';

const masker = createContextMasker();

// Mask before sending to LLM
const { masked } = masker.mask('Email: [email protected], DB: postgres://admin:pass@host/db');
// masked: "Email: <<EMAIL:0***>>, DB: <<DATABASE_URL:0***>>"

// Restore after receiving LLM response
const restored = masker.restore('Contact <<EMAIL:0***>> at <<DATABASE_URL:0***>>');
// restored: "Contact [email protected] at postgres://admin:pass@host/db"

As a CLI

# Mask sensitive data
context-masker mask 'Email: [email protected], DB: postgres://admin:pass@host/db'
# Output: Email: <<EMAIL:0***>>, DB: <<DATABASE_URL:0***>>

# Restore placeholders
context-masker restore 'Contact <<EMAIL:0***>> at <<DATABASE_URL:0***>>'
# Output: Contact [email protected] at postgres://admin:pass@host/db

# Wrap a command to auto-mask output
context-masker wrap env | grep -i password

# Clear session
context-masker clear

Tool integration

Claude Code / OpenCode

# Add to ~/.bashrc or ~/.zshrc
alias claude='context-masker wrap claude'

Cursor / Windsurf

Add to .cursorrules:

When handling tool outputs containing sensitive data (API keys, passwords, 
database URLs, emails), use context-masker to mask them before sending to 
LLM APIs.

Hermes / Windsurf

# agent.config.yml
tools:
  - name: shell
    preUse: "context-masker mask"
    postUse: "context-masker restore"

Generic integration

# Pipe tool output through masker
tool_output=$(your-command)
masked=$(context-masker mask "$tool_output")
# Send $masked to LLM

Configuration

Create config/default.toml:

enabled = ["pii", "credentials", "infrastructure"]
sessionTTL = 300000  # 5 minutes

[patterns]
pii = { email = true, phone = true, ssn = true, ipv4 = true, credit_card = true }
credentials = { api_key = true, aws_secret = true, password = true, jwt = true }
infrastructure = { database_url = true }

Note: The [patterns.*] booleans are currently documentation only. Per-pattern enable/disable is controlled at runtime via patternFlags in the config object.

API Reference

createContextMasker(config?)

Creates a new masker instance.

const masker = createContextMasker({
  enabled: ['pii', 'credentials'],  // Categories to detect
  sessionTTL: 300000,               // Session TTL in ms
  logging: true,                    // Enable debug logging
  patternFlags: {                   // Per-pattern enable/disable
    pii: { credit_card: false },
  },
  customPatterns: [                 // Add custom patterns
    {
      name: 'custom_id',
      regex: '\\bID-[0-9]{6}\\b',
      category: 'pii',
    }
  ]
});

masker.mask(text)

Masks sensitive data in text.

const { masked, mappings } = masker.mask(text);
// masked: string - Text with numbered placeholders
// mappings: Map<string, string> - Placeholder to original value mapping
// e.g., "<<EMAIL:0***>>" → "[email protected]"

masker.restore(text)

Restores placeholders to original values.

const restored = masker.restore(text);

masker.clear()

Clears the session store.

masker.clear();

masker.loadMappings(entries)

Loads pre-existing placeholder-to-original mappings into the session store.

masker.loadMappings({ '<<EMAIL:0***>>': '[email protected]' });

masker.getMetrics()

Returns masking statistics.

const metrics = masker.getMetrics();
// {
//   totalCalls: 10,
//   totalMasked: 25,
//   totalRestored: 20,
//   detectionsByType: { email: 10, api_key: 8, ... },
//   averageProcessingTime: 0.5
// }

masker.addCustomPattern(pattern)

Adds a custom detection pattern.

masker.addCustomPattern({
  name: 'internal_id',
  regex: '\\bINT-[0-9]{8}\\b',
  category: 'pii',
});

masker.removeCustomPattern(name)

Removes a custom pattern by name.

masker.removeCustomPattern('internal_id');

masker.setLogging(enabled)

Enable or disable debug logging.

masker.setLogging(true);

masker.resetMetrics()

Reset all metrics to zero.

masker.resetMetrics();

License

MIT