mloda-pii
mloda-pii is a Claude Code hook that replaces
identifiers (emails, phone numbers, IBANs, IP addresses, card numbers, US SSNs, crypto wallets, your own names and
ID formats) in tool results with tokens such as PII_EMAIL_ADDRESS_... before the model sees them. Detection runs on
Microsoft Presidio; spaCy models add names and places. Your local tools and Claude's replies on your screen keep the
real values. Every token is a keyed HMAC-SHA256, computed through mloda. It guards
against accidental exposure and does not see everything the model gets; see Limits below.
The hook's steps ship as mloda FeatureGroups, so a pipeline can detect, tokenize and restore text columns the same way.
Setup
uv tool install "mloda-pii[hook,presidio]" # or pip install it into a virtualenv that stays in place
cd your-project
mloda-pii init # paste your invite when asked
The hook runs on Linux and macOS, and on Windows natively (Git Bash or PowerShell) or inside WSL. It needs Claude Code
2.1.152 or later; init and status warn when the claude on PATH is older. init, status and each session
start warn when the license expires within 7 days.
Then restart Claude Code. Run by Claude inside a local Claude Code session of 2.1.257 or later, init lets that
session load the hook without a restart; older and cloud sessions are told how to restart and keep the conversation.
On a terminal init asks for the invite with hidden input; scripts pass the invite file, - for stdin, or the token
itself. init creates the master key, stores and verifies the license, runs the hook once on a test value, and only
then registers it in .claude/settings.local.json. It also creates .mloda-pii/config.toml, kept out of git: names ([deny]) and ID formats ([patterns]) to detect, and values to keep in clear ([allow], loopback
addresses by default; also the presets documentation and private_networks). Unknown entries are rejected. Running
init again is safe, and needed after an upgrade to register new events. The first event of a session starts a warm
server for the project and the session end stops it; an event the server does not answer is blocked.
| Option | Effect |
|---|---|
--user |
Register in ~/.claude/settings.json, for every project. |
--project |
Register in the committed .claude/settings.json; every teammate installs mloda-pii and runs init --project. |
--key-file <path> |
Import an existing master key instead of creating one. |
Ask for an invite at info@mloda.ai or via mloda.ai.
Without a valid license every gated event blocks: tool results are withheld, tool calls denied, prompts blocked. A
setup from the removed local mode (MLODA_PII_MODE=local) blocks the same way until mloda-pii init runs again with an
invite; the master key stays, and so do the tokens and the vault.
Back up your master key
The master key lives in ~/.config/mloda-pii/master.key. Back it up: every token depends on it, and a lost key
changes all of them. Keep a copy of the file somewhere private; mloda-pii init --key-file <copy> restores it. init
and status remind you, and init never overwrites an existing key.
Everyday commands
mloda-pii status: the Claude Code version, the key, the license and its expiry, whether the project config loads, where the hook is registered, the last events. Exits 1 when something is missing (a[spacy_models]model too), the config has an error or the state dir is open to other accounts.mloda-pii uninstall: removes the hook entries (same--user/--projectflags).--purgealso deletes the master key, the stored license and the vaults in the state directory, after asking (--yesskips it).mloda-pii license install | status | remove: manage the license alone.mloda-pii stats: per-day counts from the audit log, which never holds values.
A prompt that contains raw identifiers is blocked, and mloda-pii sends Claude a pseudonymized copy instead, so work goes
on with one Enter. Claude Code keeps the blocked original in the input box (it was not sent): clear it (press Esc
twice). If a sent copy never reaches Claude, auto-send pauses for 24 hours and the copy is shown to resubmit instead,
also on the clipboard when one is reachable (MLODA_PII_CLIPBOARD=off disables that). Auto-send needs Claude Code
2.1.312 or later in a terminal; claude -p, --project setups and MLODA_PII_AUTOSEND=off keep the copy to resubmit.
claude -p and SDK hosts have no input box, so their message only says to resubmit the copy.
At the end of a session the hook sends redaction counts per group and label to PostHog EU, with a random install id
and the license and customer ids from your license (base64, never the token itself), never values.
MLODA_PII_TELEMETRY=off switches it off; mloda-pii stats send --dry-run shows the exact payload.
| Variable | Effect |
|---|---|
MLODA_PII_KEY_FILE |
Master key file (default ~/.config/mloda-pii/master.key). |
MLODA_PII_CONFIG |
The project config (default .mloda-pii/config.toml). |
MLODA_PII_ENTITIES |
Presidio labels to detect (default EMAIL_ADDRESS,PHONE_NUMBER,IBAN_CODE,IP_ADDRESS,CREDIT_CARD,US_SSN,CRYPTO). +UK_NHS,-PHONE_NUMBER adjusts the defaults and keeps labels later releases add; a plain list replaces them. |
MLODA_PII_WRAP_BASH |
On by default: most failed Bash commands exit 0, and failed PowerShell commands succeed in auto mode, with a "the command failed" marker instead of the exit code, so their output is pseudonymized too. In auto it adds about 2 s to each Bash call the classifier judges. 0 turns it off; failed output then reaches the model raw. |
MLODA_PII_TOKEN_STYLE |
hex (default, PII_EMAIL_ADDRESS_<32 hex>) or readable (PII_EMAIL_ADDRESS_1, numbered per project). |
MLODA_PII_FAIL_CLOSED |
On by default. 0 lets an action pass when the hook itself fails, logged as failed_open; a license block always blocks. |
MLODA_PII_REVERSE_MCP |
1 also puts real values back into MCP tool input; a remote MCP server then receives them. |
MLODA_PII_VAULT_RETENTION_DAYS |
Delete vault entries not seen for this many days when a hook server worker starts (default off). |
MLODA_PII_WORKERS |
Hook server processes that run events in parallel, about 150 MB each, at least two once an event ran (default: CPUs minus one, at most 3). |
MLODA_PII_AUDIT_LOG |
Audit log path (default ~/.local/state/mloda-pii/audit.jsonl); off disables it. |
MLODA_PII_TELEMETRY |
On by default; off (or DO_NOT_TRACK=1) stops the redaction counts. |
MLODA_LICENSE_FILE, MLODA_LICENSE_KEY |
Take precedence over the stored license; init checks the one in use and self-tests with it. |
Command options: mloda-pii <command> --help.
The FeatureGroups
import os
from pathlib import Path
from mloda.user import Feature, Options
from mloda_pii.feature_groups.anonymizer import derive_anon_key
os.environ["PII_KEY"] = derive_anon_key(Path("~/.config/mloda-pii/master.key").expanduser().read_bytes())
feature = Feature("email__hmac_sha256_pseudonymized", Options(context={"pii_key_env": "PII_KEY"}))
envs = {"pii_key_env": "PII_KEY", "pii_vault_path_env": "VAULT_PATH"}
text = Feature("notes__pii_marked_hash_pseudonymized", Options(context=envs, cascade_context_keys=frozenset(envs)))
Tokens come from the license-gated anonymizer_binary, so a pipeline needs the hook extra and a license in
MLODA_LICENSE_FILE or MLODA_LICENSE_KEY. <column>__hmac_sha256_pseudonymized returns the 64-hex keyed HMAC-SHA256
token of a string column, or of each element of a list column. pii_key_env names the environment variable
that holds the 64-hex key; derive_anon_key derives it from the master key, so a pipeline gets the hook's tokens.
Installed with the hook extra, mloda-pii's PiiAnonymizerFeatureGroup takes over every __hmac_sha256_pseudonymized
feature from mloda-enterprise's AnonymizerFeatureGroup: it adds list columns and gives the same tokens.
<column>__pii_<marked_hash|counter>_pseudonymized replaces the identifiers in a text column with tokens, as the hook
does; <column>__pii_<strategy>_restored maps them back from the vault named by pii_vault_path_env.
<column>__pii_spans returns the detected spans and publishes their count per label as the result attribute
pii.spans.<LABEL> for an mloda Extender (never values). Detection needs the presidio extra. pii_config_env names
the variable that holds the path of a config.toml (the hook's project config: allow list, deny words, patterns,
spaCy models); without it the defaults apply. A text column's name counts as written before each of its texts, so an
ip_address column keeps 10.0.0.1 as an address; pii_field_column names a column with one field name per row
instead, cascaded like the variables above.
Limits
- The hook guards against accidental exposure, not a model that tries to recover values: a Bash command gets the real value and can return it disguised, which detection misses.
- In
autopermission mode a Bash or PowerShell command that holds a token asks for your approval, since auto mode would send its restored real values to its classifier model;claude -pinautomode denies such a command. - Hooks never see
@filementions, CLAUDE.md and memory files, the client's own reminders and context (such as its git status), images or compaction summaries; those reach the model unchanged, as do results of Claude Code's own account memory MCP tools (the client drops their rewrites). - Untested: whether tools that
claude mcp serveruns for another MCP client go through the hooks, so do not serve a project that holds personal data that way; and whether/resumeor compaction sends the original structured MCP result the local transcript keeps next to the rewrite. - Detection finds emails, phone numbers, IBANs, IP addresses, card numbers (Luhn valid), US SSNs written
NNN-NN-NNNNand checksum-valid Bitcoin addresses, and names and places once the project config names a spaCy model per language ([spacy_models]withdeanden, installed from the release wheels at https://github.com/explosion/spacy-models/releases, as "Names and places" in the hook's README shows); without them names are found only under[deny]. Postal addresses and your ID formats are found only through[deny]or[patterns]; anything else passes in clear. A value a command cuts off at a line or output end (head -c) is found from seven characters on only as a[deny]word cut mid-word or a vault value with a digit or@(see the hook's README); a phone the vault does not hold yet passes raw. Add a Presidio pattern label such asUK_NHSwithMLODA_PII_ENTITIES=+UK_NHS(URLandDATE_TIMEalso match file names and dates). A[patterns]regex with nested repetition can run long enough to block every event it scans. A path that holds a detected value (an email in a file name) reaches the model as a token, and local tools get the real path back; a file format that is no top-level domain, such as.json, stays outside the token when the domain keeps a dot (a@b.com.json). - Known false positives and misses: anything shaped
name@x.yreads as an email (react@18.3.1,git@github.com) unless its domain ends in a file format that is no top-level domain, also with a-or_suffix or a rotation number or date, so the file namesicon@2x.png,icon@2x.png-1andapp@host.log.1stay; an email on such a domain (ops@build.bin) is missed unless a[deny]entry lists it; a bare 10-digit number valid in the US or Canadian plan reads as a phone unless it sits deep in a URL or path (/runs/,#issuecomment-) or right after an ID word (id,run,build), so a lone ID still becomes a phone token, and so does every copy of it, and a bare phone in such a place is missed; outside the US and Canada an unlabeled bare national number (9876543210) is missed unless a[patterns]entry covers it or the vault, the same tool result or prompt, or the same pipeline run holds that phone spelled out (+91 98765 43210); a phone of only digits and dots right after<digit>.or starting0., or dotted or0-led and spaced in a grouping its region does not use (0151.1234.5678,01 2345 6789) without a phone word before it, is missed, and a short float such as4.96901940872can still read as a+49phone; a 4-part version with a part of 32 or more (1.0.0.123) becomes an IP token unless a version sign such asupgraded toorpkg==comes right before it, and an address after such a sign is missed unless an address sign, the vault or the same run keeps it; a 13 to 17 digit ID or either part of a decimal-comma number (314292388910493,12) that passes the Luhn check and starts like a card becomes a card token, and in a file name or other value the hook does not rewrite it makes the verifier end the turn. Cards starting with 1 (UATP) or 56 to 59 (some Maestro) are missed, as are SSNs written without dashes and a card glued to a decimal point and digit on either side (0.4111111111111111,4111111111111111.5), also in a file name (export-4532015112830366.7z); pipelines using the presidio engine withenamong the languages detect the same.[allow]keeps exact values in clear. - An IPv4 address with every part below 32 (
10.0.0.1) is read as a version and stays in clear unless a port, CIDR suffix, URL or a word likeiporhostcomes with it, in the hook and in pipelines alike; the nearest MCP field name or the pipeline column name (client_ip,ips) counts too, an outer key or a{"name": ..., "value": ...}pair does not. An address tokenized once is tokenized bare in every field or row of the same run, and an IPv4 address the vault holds in later events, a version string equal to it too. A bare copy shown before the address was tokenized stays in the conversation, and a small IPv6 address is not carried to later events, so there the model can still pair the token with the address. An IPv6 address of at most two decimal groups (2001::1) or two names of up to three characters (a::b) needs the same sign, since it reads like a Python slice or a scope; in a subscript, two groups that are decimal or up to three characters (a[1::2],a[b::2]), and a bare::, always stay in clear. - A tool result reaches the model as it is when the hook process itself crashes or hangs past the 60 s timeout
initsets, and so does a failed tool other than Bash or PowerShell, a failed PowerShell command outsideautoor one that ends early (exit,return, a terminating error as under$ErrorActionPreference = 'Stop', a parse error, a trailing backtick), a failed Bash command the wrapper cannot reach (exec, anexitafter the command sets its own EXIT trap, most syntax errors, and outsidebypassPermissionsa sourced file that exits, a trailing\or a failing open heredoc without anexit), or a timed-out one that Claude Code kills instead of moving it to the background (one that starts withsleep, or any withCLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1). The verifier then ends the turn, but the result stays in the conversation and the model reads it on the next turn. - There is no size cap: a tool result is scanned whole, so a large one takes longer. The hook blocks an event its
server does not answer within about 25 s (waiting behind other sessions' and subagents' events included), or whose
server is still starting after 45 s (50 s in all; the start goes on for a later event), so a slow machine may block
every event: result withheld, call denied, prompt blocked.
MLODA_PII_FAIL_CLOSED=0lets it pass instead. - A Claude Code below 2.1.152 may skip every hook (untested), and one below 2.1.121 ignores the rewritten output of
built-in tools in any case.
initandstatuswarn only about theclaudeonPATH, not an IDE or desktop client. A Claude Code release that changes the hook interface can let values through unnoticed until mloda-pii follows. Supported platforms are listed under Setup. - Claude Code checks an Edit's
old_stringbefore any hook runs, so an Edit whoseold_stringholds a token fails. The hook tells the model to use a Bash command or Write instead; a Bash command may ask for permission, and a Write from a partial Read cuts the file. - The license gate is a speed bump: a token is a standard keyed HMAC-SHA256, which whoever holds the master key can recompute without a license.
- Tokens are still personal data under GDPR; whoever holds the key can recompute them.
- The local vault under
~/.local/state/mloda-pii/(or$XDG_STATE_HOME) maps tokens back to raw values. It keeps them untilMLODA_PII_VAULT_RETENTION_DAYSexpires them oruninstall --purgedeletes it; an expired token no longer maps back.
License
mloda-pii is proprietary and source-available, under the mloda-pii License in the LICENSE file of the package. Use
in your daily work is permitted with a license key from mloda, also when the key is free. The license text is binding
over this summary.
Related
- mloda: declarative data and feature access, the framework mloda-pii runs on.
- mloda-registry: plugins and guides for mloda.
Metadata
Release files for mloda-pii 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mloda_pii-0.8.0.tar.gz | 140.3 kB | With provenance | Details for mloda_pii-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mloda_pii-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for mloda_pii-0.8.0-py3-none-any.whl |
Total release size: 304.5 kB
Release files / mloda_pii-0.8.0.tar.gz
| Download URL | mloda_pii-0.8.0.tar.gz |
|---|---|
| Size | 140.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
590e13eaafaf26651288e0ffc40e3fb737b05cbf717f99e15a50753faa6d1448
|
|
BLAKE2b-256 checksum How to use checksums |
e4e051b1a360fa1b35d395a8c04b5737b028e5722a4c75fc9c1030ec67a124da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logRelease files / mloda_pii-0.8.0-py3-none-any.whl
| Download URL | mloda_pii-0.8.0-py3-none-any.whl |
|---|---|
| Size | 164.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6f00493999ebe9338b4b44785bc744f3aedd0f0475364034909d9a73be491ac
|
|
BLAKE2b-256 checksum How to use checksums |
3b4249ecf507e5c44ed8bdb14e6010eac388c35def3813ade579d29e5a3c0c0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logSecurity for mloda-pii 0.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mloda_pii-0.8.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.