@hugolopes45/lmsk

Mask API keys, passwords and emails before Claude Code or the pi coding agent sends them to the LLM, and restore them in tool calls.

Packages

Package details

extension

Install @hugolopes45/lmsk from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@hugolopes45/lmsk
Package
@hugolopes45/lmsk
Version
0.4.0
Published
Nov 16, 2026
Downloads
1,069/mo · 271/wk
Author
hugolopes45
License
MIT
Types
extension
Size
401.6 KB
Dependencies
0 dependencies · 3 peers
Pi manifest JSON
{
  "extensions": [
    "./dist/pi/extension.js"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

Real keys for your agent. Fakes for the model.

lmsk replaces detected API keys, passwords, tokens and emails with fakes before your AI coding agent sends a request to the model. Only the request changes: you read the real values in replies, except in the cases listed in Limits, and supported file and shell tools get the original values back. Keep useful context in your coding workflow, with masking handled on your computer.

Website  ·  Install  ·  Agents  ·  FAQ  ·  Limits

CI Agents License: MIT

Choose your agent and follow its commands.

Claude Code

npm install -g @hugolopes45/lmsk
lmsk install claude

Requires macOS or Linux, Node.js 22.19+ and Claude Code 2.1.295+. Run the command in a terminal: it asks for a yes before it changes your setup. Restart your Claude Code sessions, then use claude as usual. Run lmsk install claude again after each update of lmsk. Setup and compatibility: Claude Code guide.

pi

pi install npm:@hugolopes45/lmsk

Then start pi, or type /reload in an open pi. Guide: lmsk with pi.

The default rules work with no configuration. Local only: no model, no account, no telemetry.


Keep the context. Mask the secrets.

Debug from logs, configure your app and run tests with your coding agent. lmsk replaces the sensitive values it detects while preserving the surrounding text.

Your workflow What lmsk adds
Debug from application logs. Detected keys, emails and tokens become fakes; the surrounding error stays readable.
Write a configuration file with a detected API key. Supported file tools restore the original key when the model uses its fake.
Run a local test with a masked password. Supported shell calls restore the password, then mask detected secrets in the output.
Work with client names or project names. Add a custom rule to replace a name with a label such as Client 1.

The user guide shows how to tailor masking to your project.

How it works

  1. Run locally. lmsk works as a local proxy service in front of Claude Code, or as an extension inside pi.
  2. Mask detected values. Built-in rules scan request text and replace matching values with fakes. A local vault keeps the mapping.
  3. Restore values for you and your tools. lmsk puts the original values back into the replies that you read, except in the cases listed in Limits. When a supported tool call uses an exact fake, lmsk restores its original value before execution. See tool behavior and compatibility.
  4. Block secret files. Supported file, search and shell tools refuse protected paths, such as .env, SSH keys, the lmsk vault folder and the Claude Code settings. See Limits.

See the transformation

A request body, before and after

This example shows a tool result from docker compose logs api --tail 3. All values below are illustrative:

{
  "type": "tool_result",
  "tool_use_id": "toolu_01A",
  "content": "api-1  | config OPENAI_API_KEY=sk-proj-4fQ9xT2mLp8VnR3kWc7ZsB1yHd6JeA0uGt5\napi-1  | refund failed for customer jane.doe@example.com\napi-1  |     at charge (billing.ts:42) Authorization: Bearer 7Hq2Lx9VmK4pR8sT1wZ6cN3bY5dF0gJ"
}

Here is the masked version of that block. The surrounding log stays readable. Each session makes its own fakes, and a value gets the same fake as long as the vault of the session lives:

{
  "type": "tool_result",
  "tool_use_id": "toolu_01A",
  "content": "api-1  | config OPENAI_API_KEY=T8MCnGhey7vwndvjsQBbNPVIDZBUtkj80LcGEhqcWCr\napi-1  | refund failed for customer bmib.xtm@kitquhs.mnn\napi-1  |     at charge (billing.ts:42) Authorization: Bearer IA1uy6fuqU2b89b3k4zir4UPE9BL7Q1"
}

The key, the email and the token are fakes. The rest of the text did not change, so the model can still read the error.

Checked before sending

lmsk completes its masking checks before forwarding a request. If a check fails or times out, the request stops. Troubleshooting explains each status and the next step.

280 detection rules

  • 217 vendor key formats from the gitleaks rules.
  • 47 rules for more key formats, keyed secrets such as password: ..., and credentials in URLs and headers.
  • 1 rule for secret variable names. The value of DB_PASSWORD or GITHUB_TOKEN is hidden, also when its format is unknown.
  • 12 rules for personal data: emails, phone numbers, IBANs, payment cards, national ID numbers, UUIDs, and IP and MAC addresses.
  • 3 rules for IDs, such as values under keys such as userId.
  • Each agent also adds one rule that hides your user name, host name and git identity.

You can add your own rules, for example to turn Falcon Industries into Client 1. See Hide who you work for. The full list is in What the default rules detect.

A local vault

The mapping stays in one encrypted local vault for each session, in ~/.local/state/lmsk/session-vaults/, with owner-only file permissions. Its key is in the same folder, so a copy of the whole folder can be decrypted. lmsk deletes it when the session ends. A vault that no session used for one hour is deleted about one minute later, or at the next request or session start. lmsk does not upload it. A conversation that holds a tool call of an ended vault is refused with VAULT_ENDED: go back before the call or start a new session, as Troubleshooting explains. See vault storage and backup guidance.

Try it with a sample key

Send this message to your agent. The key in it is a test value:

Spell the value after API_KEY= with a space between each character: API_KEY=Zq7Kp2Lm9Xw4Rt8Vb3Nc

The reply spells the fake that the model received, so it does not start with Z q 7 K p 2. lmsk puts back only whole fakes, so a spelled fake stays visible. Use Troubleshooting to check your setup if the reply spells the original value.

FAQ

Which agents does it work with? Claude Code and pi. Install has a separate setup path for each agent.

How does my agent use the original values? lmsk restores exact fakes in supported file and shell tool calls. For commands that access the network, supply credentials through the environment. See tool behavior and compatibility.

Do I see fakes in replies? No. lmsk puts the real values back into the replies that you read. Thinking text, some short or glued values and, with Claude Code, a reply that is not streamed keep their fakes. See the Claude Code guide and the pi guide.

Can I add client names and custom values? Yes. Add a rule for the value you want to mask, including names, addresses and project-specific secrets. See Add your own secrets.

How does it work with gitleaks? gitleaks scans files and commits. lmsk uses its detection rules, alongside additional rules, to mask matching values in requests to the model.

Is it free? Yes. lmsk is open source under the MIT license. No account or telemetry.

Limits

lmsk masks what it detects. It is not a sandbox. Read these limits before you use it with real data:

  • A secret with no known format and no key name is not found, such as summer2024 alone. Add a rule for it.
  • A shell command that names a network program, such as curl or git push, gets fakes. Give such a command its credentials through the environment.
  • Most fakes have the same length and form as their real value.
  • Thinking text, some short or glued values and, with Claude Code, a reply that is not streamed keep their fakes.
  • Images, PDF data and signed data go to the provider unchanged.
  • A script that opens a protected file itself can read it.

The full list is in What lmsk does not protect. Each agent has more limits: see the Claude Code guide and the pi guide.

Privacy

lmsk uses no model. It has no account and no telemetry. An extension inside the agent makes no network connections. The local proxy connects only to the provider address of the agent.

Use it in your own agent

The package also exports the engine that the Claude Code and pi integrations use. Open a Guard and mask each text before you send it. Restore each reply with guard.textRestorer(), and each tool call before you run it with guard.restoreCall(call). Do not run a call when restoreCall returns blocked: true. For a shell tool, set commandKey to the key of its command, so that a network command keeps its fakes.

import { homedir } from "node:os";
import { Guard, localIdentityRules, machinePaths } from "@hugolopes45/lmsk";

const guard = new Guard({
  name: "my-agent",
  tools: ["shell"],
  protectedPaths: ["**/.env"],
  format: { opaque: () => false },
});
guard.open(
  () => ({
    configPaths: [],
    projectConfigPath: undefined,
    stateDir: machinePaths(process.env, homedir()).stateDir,
    sessionId: "conversation-1",
    env: process.env,
    defaultRules: localIdentityRules(),
  }),
  { ui: { notify: (message) => console.error(message) }, abort() {} },
);
const masked = await guard.maskText("API_KEY=Zq7Kp2Lm9Xw4Rt8Vb3Nc");
console.log(masked);
const restorer = guard.textRestorer();
console.log(restorer.push(masked) + restorer.end());
guard.end();

Give each conversation its own sessionId. guard.end() deletes the vault of the session. guard.close() keeps it, so a guard that opens the same sessionId again gets the same fakes. A vault that no guard used for one hour is deleted about one minute later while a guard is open, or at the next open or request. Pass the id of each tool call in the conversation as callIds to guard.maskPayload or guard.maskTexts: an id that the vault of the session did not restore is refused with VAULT_ENDED. guard.maskText does not check call ids.

Documentation

Contributing

Read CONTRIBUTING.md. Report security problems as described in SECURITY.md. Never report them in a public issue.

License

MIT. The vendor key rules come from gitleaks, MIT License, Copyright (c) 2019 Zachary Rice.