
trapr
io.github.jaykrishna316/trapr
Find copies of your code: signed markers, canaries and fingerprints, checked locally.
Documentation
Built by Jayakrishna Ichapurapu Β· Primeape94 Lab Β· MIT License
TrapR
Plant traceable fingerprints in your open-source code, then hunt for copies, with your own CLI or with an AI agent.
Mapmakers used to draw fake "trap streets", roads that don't exist, to prove when someone copied their map. TrapR does the same for code.
New: the weekly hunt is on the GitHub Marketplace. New in 0.7.0: TrapR is an MCP server. Claude Code, Claude Desktop, Cursor and other agents can check suspect code against your projects as a tool. See Use it from your AI agent.
Protect your repo in one minute
Pick whichever way suits you. The tool always runs from outside your repo, so nothing of it stays behind.
1. Ask your AI coding agent (Claude Code, Codex, Cursor, Devinβ¦)
Set up TrapR on this repo using github.com/jaykrishna316/TrapR
The agent follows AGENTS.md: it confirms the license, runs a dry run, protects the repo, helps wire in the canaries, and tells you where your vault is.
2. One file, no install
curl -fsSLo ~/trapr.py https://raw.githubusercontent.com/jaykrishna316/TrapR/v0.7.0/trapr.py
cd ~/code/my-project
python3 ~/trapr.py protect --license MIT --owner "Your Name"
git diff --stat # review, then commit and push
3. As a command
pip install git+https://github.com/jaykrishna316/TrapR # or: pipx install git+https://github.com/jaykrishna316/TrapR
trapr protect --license MIT --owner "Your Name"
Add pip install tree-sitter tree-sitter-language-pack for AST fingerprints in non-Python repos.
One command does everything:
| What it plants or records | Where it goes |
|---|---|
A signed marker comment in every source file, e.g. # rev: 565e0bf5-1a2b3c4d (label varies per project) | your repo |
| SPDX license headers (optional) | your repo |
| 3 behavioral canaries (up to 4), each a different kind of useful helper (rollout bucket, colour index, shard router, checksum) with secret constants | your repo, spread over core files |
| Structural fingerprints of every file (token + AST winnowing) | the vault |
| Search queries, marker table, canary probes, secret key | the vault |
| A playbook any AI agent can follow to hunt for copies | the vault |
| A secret-free commitment, timestamped in Bitcoin via OpenTimestamps | next to the vault (.trapr-commitment.json + .ots) |
The vault is a single Markdown file written outside your repo (../neo.trapr-vault.md). Keep it private.
Hunting for copies
Option A: let an AI agent do it. Open the vault in Claude Code (or any agent with GitHub access) and say:
Follow the playbook in this file.
The vault tells the agent which lines to read, which searches to run (gh, GitHub search, grep.app), how to verify each hit, how to grade the evidence, what not to do (never run suspect code, never leak the vault), and the exact report format to return.
Option B: the CLI.
trapr hunt --vault neo.trapr-vault.md # GitHub code search + forks + PyPI + npm, verifies every hit
trapr verify --vault neo.trapr-vault.md <target> # a file, folder, git URL, or GitHub file URL
trapr refresh --vault neo.trapr-vault.md --repo-dir ~/code/neo # after big changes (same key)
trapr mark --vault neo.trapr-vault.md --repo-dir ~/code/neo # another branch, same key
trapr similarity --repo-dir ~/code/neo --target <folder|git URL> # lead finder, works across languages
similarity compares your code with a suspect even after a port to another language: keywords map to neutral
tokens and distinctive string and number literals are compared separately. It returns a lead for review, never
proof. Calibrated on 36 unrelated repo pairs with 0 false leads; it misses short ports that share only one or two
distinctive literals.
hunt searches four places: GitHub code search, your fork network (forks aren't in code search; it flags forks that
removed your LICENSE or stripped markers), and PyPI and npm packages with similar names, downloaded and scanned
safely, never installed. Code search and forks need GITHUB_TOKEN or a logged-in gh; registries need nothing.
Pick sources with --sources code,forks,pypi,npm.
Option C: every week, automatically, with an email. Use the TrapR hunt Action from the GitHub Marketplace. Keep your vaults in one private repo and add the workflow from
examples/vaults-repo:
- uses: jaykrishna316/TrapR@v0.7.0
with:
vaults: "vaults/*.trapr-vault.md"
search-token: ${{ secrets.TRAPR_SEARCH_TOKEN }} # fine-grained PAT, public read
On your schedule (the example runs every Sunday) it hunts with every vault in the repo, so a new project is covered as soon as you add its vault. It writes one report per project, uploads them, and comments on a single "TrapR weekly hunt" issue with a row per project, all clear or not. When there's definitive or strong evidence it also opens a separate issue. GitHub emails both to you, so a quiet week still lands in your inbox.
Your tokens stay put: the search token goes only into API request headers, never into logs, reports or issues,
and the issues are posted with the repository's own GITHUB_TOKEN. The action refuses to run in a public
repository, because vaults hold secret keys.
Use it from your AI agent (MCP)
trapr mcp runs TrapR as a local Model Context Protocol server, so your agent can
ask "was this code copied from Neo?" and get graded evidence back. It uses only the standard library, like the rest
of TrapR, and supports both current and older MCP clients.
| Tool | What it does |
|---|---|
trapr_list_vaults | The projects this server can check (never the keys) |
trapr_verify | Check a file, folder, git URL or GitHub file URL: π΄ definitive, π strong, π‘ moderate |
trapr_similarity | Cross-language comparison, a lead for review (needs --repo NAME=PATH) |
trapr_hunt | A quick, bounded hunt (code search, forks, PyPI, npm); keep weekly hunts in the GitHub Action |
Claude Desktop (one click): download trapr-mcp.mcpb from the
latest release and open it. Claude Desktop asks for your
vault files (and, optionally, a read-only GitHub token for hunts) and stores the token securely. Needs Python 3.10+.
It's also listed in the MCP Registry as io.github.jaykrishna316/trapr.
Claude Code
claude mcp add trapr -- python3 ~/.trapr/trapr.py mcp --vault ~/trapr-vaults/neo.trapr-vault.md
Claude Desktop, Cursor and others (claude_desktop_config.json, ~/.cursor/mcp.json):
{
"mcpServers": {
"trapr": {
"command": "python3",
"args": ["/Users/you/.trapr/trapr.py", "mcp",
"--vault", "/Users/you/trapr-vaults/neo.trapr-vault.md",
"--repo", "neo=/Users/you/code/neo"]
}
}
}
Add --vault once per project. For trapr_hunt to search GitHub, the server needs a token: a logged-in gh is
picked up automatically, so nothing secret goes in the config file.
What it can't do, by design: all four tools are read-only. The agent can only use the vaults you list, by
project name, never a path of its choosing. Results never include the vault's key. Nothing is written to disk.
Suspect code runs only inside TrapR's sanitized harness, and results mark third-party paths and names as untrusted
data. protect, refresh, mark and probe-models aren't exposed. Keep the server local (stdio): it reads your
vaults.
Did an AI model learn your code?
trapr probe-models --vault neo.trapr-vault.md # every local Ollama model
trapr probe-models --vault neo.trapr-vault.md --provider openai --model <model> # any OpenAI-compatible API
trapr probe-models --vault neo.trapr-vault.md --provider anthropic --model <model>
Each model sees only a canary's signature and docstring and is asked to finish it. Its answer runs on the six secret
probes. Without having seen your code, the chance of matching all six is about 1 in 2^186, so a match is definitive:
the model saw your code in training, or fetched it live. A miss proves nothing; most models won't memorize one repo.
Works with Ollama, LM Studio, vLLM, OpenRouter, OpenAI, Groq, Anthropic, and anything OpenAI-compatible (--base-url).
Prove when your traps existed
protect hashes everything the vault can prove (marker tags, fingerprint hashes, canary specs, a hash of the key)
into a commitment and anchors it in Bitcoin through OpenTimestamps. The commitment
reveals nothing, so you can publish it. A few hours later, ots upgrade and ots verify (from
pip install opentimestamps-client) prove the date to anyone. trapr timestamp --vault β¦ --swh re-stamps and asks
Software Heritage to archive your public repo as an independent witness.
Keep it current: the merge gate
Every new file should carry a build reference before it reaches main. Two pieces, and your public repo never holds the key:
- In the protected repo, add the check
trapr gate-workflowprints and make trapr-gate a required status check. It fails while any source file lacks a build reference. - In your private vaults repo, add
trapr-sync.ymlandtrapr_sync.py, list your repos intrapr-sync.json, and give it a fine-grained token with write access to them. When the gate fails, the sync marks the pull request's branch with a comment-only commit and the check passes. It also keeps the vault's fingerprints current.
trapr gate-workflow --vault neo.trapr-vault.md --vaults-repo you/trapr-vaults --branch main > .github/workflows/trapr-gate.yml
Pull requests from forks can't be marked by the bot (it can't push to someone else's fork): mark those
locally with trapr mark before merging.
TrapR protects itself. The # build-id: 8113f5bb-β¦ line at the top of trapr.py is TrapR's own marker, and this
repo runs the same gate. It's a comment: copying TrapR under the MIT license is fine, just keep the attribution.
Six layers of evidence
| Layer | Survives | Grade when it fires |
|---|---|---|
| Signed marker: HMAC of the file path under your key | copy-paste, forks, moved files | π΄ Definitive |
| Canary behavior: 6 secret probes β 6 secret outputs per canary (β1 in 2^186 by chance) | renaming, restyling, reduce/forEach/while rewrites, class methods with class constants, porting to another language, broken imports around it | π΄ Definitive |
| Canary constants: each canary's secret constants, hex or decimal | rewrites that keep the math | π Strong |
| Token winnowing: MOSS's algorithm over normalized tokens | renamed identifiers, stripped comments/markers, reordering | π Strong β₯60% Β· π‘ Moderate β₯35% |
| AST winnowing: tree shapes in language-neutral classes | forβwhile, +=β= x +, reformatting | same as above |
| Function matching (0.6.0): fingerprints of each function and method, ignoring layout | partial copies: a few functions pasted into someone else's file, renamed and reformatted | π‘ Moderate Β· π Strong for 2+ functions |
Moderate evidence from two different layers adds up to π Strong. Function matching skips functions that are mostly data (tool schemas, config tables) and fingerprints shared by many of your own functions, because those look alike in every project.
Make the canaries load-bearing. protect prints an import and a real use for each (a rollout check, an avatar colour, a worker pick, an ETag). Wire them in, so a copier can't delete them without breaking their code, and has to find and rewrite every one.
Tested on Neo and Braxis
Retested on 2026-11-08 with v0.4.1, on fresh clones of Neo (main, 283 files protected) and Braxis (61 files),
3 canaries each.
| Copier did this | Result |
|---|---|
| Copied 2 Neo files verbatim | π΄ 2/2 definitive (markers) |
Copied all 54 files of Neo's core/, stripped every marker and SPDX line | π΄ 1 definitive (canary) + π 51 strong; the 2 misses are 13-line __init__.py files |
| Took the 3 Neo files carrying canaries, stripped markers (their imports don't resolve elsewhere) | π΄ 3/3 definitive, each by its own canary |
| Rewrote 3 Neo files with the AST: 37β87 identifiers renamed per file, docstrings and comments removed, reformatted | π 3/3 strong (83β95% structural match) |
Reimplemented each of Neo's 3 canaries by hand: a JavaScript port using forEach, a class method with class constants, a while loop, all with decimal constants | π΄ 3/3 definitive (6/6 probes each) |
Took only braxis.py, stripped markers | π΄ definitive (canary + 100% structure) |
Prepended a booby-trapped open("PWNED") to a copied Neo canary file | π΄ Caught. The trap never ran. |
| False positives: itsdangerous, uvicorn, rich, requests, click, typer, httpx, attrs, structlog, pip-tools, checked against both the Neo and Braxis vaults | 0 flagged across 20 checks. Closest unrelated file: 32%, against a tiny archived Neo test fixture; every other file 13% or less (threshold 35%) |
Neo and Braxis test suites after protect | Identical to before (Neo: 183 passed; Braxis: 26 passed; the same pre-existing failures on both sides) |
Registries, live: pretended to own itsdangerous and @sindresorhus/slugify | The real PyPI and npm packages flagged (12 and 2 files, 100% match); 9 lookalikes such as types-itsdangerous, more-itsdangerous, slugify and react-slugify not flagged |
Model probes, live with Ollama (qwen2.5:3b, qwen3.5:4b) on Neo's canaries | No false alarms: 6/6 probe runs cleared. Positive control: when the model was shown a canary and asked to copy it, TrapR caught 3/3, each 6/6 secret probes |
| Model probes against a server speaking the Ollama, OpenAI and Anthropic APIs | A model returning the canary: caught on every canary. A model that hadn't seen it: cleared. A model that returned no code: reported inconclusive |
| Timestamp, live: Neo's commitment submitted to OpenTimestamps | Accepted by all 4 public calendars |
Merge gate, live on a throwaway GitHub repo: main requires a green trapr-gate, then a pull request adds an unmarked file | The check failed and named the file; the private sync marked the branch with a 3-line comment-only commit; the check passed. 34 seconds, nobody touched anything. The key never left the private vaults repo |
Accuracy benchmark
python3 tests/benchmark.py protects 14 Python standard-library modules as "your project", disguises every file the
way a copier would, and scans 58 unrelated modules that must never be flagged. It runs offline in CI on every push,
and the build fails if accuracy drops below the recorded floor.
| Copier did this | Caught before 0.6.0 | Caught in 0.6.0 |
|---|---|---|
| Stripped markers, comments and docstrings | 100% | 100% |
| Renamed every name and reformatted | 100% | 100% |
| Renamed and reordered every definition | 100% | 100% |
| Pasted about a third of the functions, renamed, into another module | 29% | 71% |
| Pasted one function, renamed, into another module | 50% | 100% |
| Unrelated code flagged | 0 of 58 | 0 of 58 |
On real code, the function layer was also checked against 4,700+ files from 23 unrelated open-source projects (Python, JavaScript and Java, including other rate limiters and circuit breakers), with Neo and Braxis as the protected projects and against each other: no false positives. Five of those projects were held out until the settings were final. With renamed, reformatted Neo functions pasted into those projects' files, three functions were caught 83% of the time and a single function about half the time; very short functions stay below the evidence floor.
Test suites: python3 tests/test_trapr.py (50 checks), python3 tests/test_similarity.py (cross-language),
python3 tests/test_constants.py (canary-constant false positives), python3 tests/test_units.py (function
matching) and python3 tests/test_mcp.py (the MCP server, both protocol eras). The main suite covers mocked GitHub search and forks, malicious archives,
three model-API wire formats, a timestamp proof parsed by the official OpenTimestamps library, and all 1,152 canary
kind Γ style combinations. CI runs it on Python 3.10β3.14, with and without tree-sitter, and passes on all 10 jobs.
Tested live: a full hunt from the GitHub Action across four projects (code search, fork crawl, PyPI, npm)
found the test fork that stripped the LICENSE and markers: π΄ 2 definitive by canary, π 1 strong. It also surfaced
31 coincidental single-constant matches in unrelated data files, which led to the v0.5.3 fix that clears all of
them. The merge gate marks new files on push. Not yet tested live: probing cloud models.
How verification stays safe
Checking a canary means running suspect code, so TrapR never imports the suspect module. It parses the file and keeps only definitions:
- functions and classes (decorators and call-containing defaults stripped)
- constants whose values make no calls
- absolute imports
Every top-level statement that would execute something is dropped. The result runs in a subprocess with a memory cap, a 2-second limit per call, an empty environment, and a temp directory. This is defense in depth, not a perfect sandbox: for unattended hunt runs, use a container or CI.
Options
protect --license MIT --owner "Name" SPDX headers (omit for markers only)
--canaries 3 how many canaries, 0-4, each a different kind
--canary-into path/to/file.py put every canary in one file (default: spread over core files)
--no-timestamp don't submit the commitment to OpenTimestamps
--canary-lang auto|py|js|ts|none
--marker-label rev the comment label (default: picked per project)
--include-dir .claude also protect a hidden folder (repeatable)
--exclude-owner myorg extra owners to ignore in results (repeatable)
--vault PATH default: ../<repo>.trapr-vault.md
--no-markers --no-spdx --dry-run --force
hunt --sources code,forks,pypi,npm --max-queries 40 --max-forks 300 --max-packages 15
--pause 7 (code search allows ~10 requests/minute)
probe-models --provider ollama|openai|anthropic --model NAME --base-url URL --samples 3
timestamp --swh also ask Software Heritage to archive the public repo
Dependencies: none (Python 3.10+). Optional pip install tree-sitter tree-sitter-language-pack adds AST fingerprints for 18 languages and JS canary verification. Node.js is needed to run JS canary checks.
Security model: what a copier who has read this README can do
TrapR is open source, so assume copiers know how it works. Its strength rests on your secret key, not on secrecy of the method:
- Markers use a label picked per project (
rev,src-ref,build-idβ¦), but thexxxxxxxx-xxxxxxxxpattern is greppable. Stripping them is easy; they catch the lazy majority. - The canary's name, docstring, variable names and arithmetic style are chosen per project from your key, so there's no fixed string to search for. Its shape (a small multiply-xor hash) is still recognizable to someone who suspects it. Removing it means rewriting whatever depends on it, which is why it should be load-bearing.
- Structural fingerprints need no secrecy. Defeating them takes a real rewrite.
- Without the key, nobody can forge your markers, compute your canary's probe outputs, or prove a file is yours.
See SECURITY.md for the full threat model.
Honest limits
- Markers are visible. A careful copier strips them, which is why the canary and structural layers exist.
- A full reimplementation of non-canary code can get below the threshold. Structural matching catches lazy and medium-effort disguise. The canary catches anything short of replacing the algorithm.
- Very short copied functions aren't evidence. A function needs enough distinctive code to tell it apart from
coincidence; one copied single function is caught about half the time on real code. Vaults made before 0.6.0 gain
function matching after
trapr refresh(the private sync adds it on its next run). - GitHub code search only finds strings. If a copier strips markers, renames everything, and drops the canary,
huntwon't surface them. Runverifyon suspects you find another way (forks, similar names, PyPI/npm). - Lead queries (distinctive strings and identifiers) also match legitimate users of your project. They are leads, not evidence.
- Model probes only catch memorization or live retrieval. A model trained on your repo but unable to recite the canary passes. That's the expected outcome for most models and one repo; nothing today can prove that case.
- Model probes have run live against Ollama, but not yet against cloud APIs. Please report problems.
similaritymisses short ports that share only one or two distinctive literals. It's precision-first on purpose.- The vault is large (about 290 KB for Braxis and 910 KB for Neo with function matching) because it carries fingerprints. Agents are told to read only the first few hundred lines.
- Lose the vault and you lose the proof. Back it up. With
--force,protectmakes a new key and the old markers become unprovable. - MIT/Apache permit copying. You're detecting missing attribution. This is evidence gathering, not legal advice.
Related work
TrapR builds on decades of research and stands next to good tools. Use them too:
- Similarity detection: MOSS and its winnowing algorithm (Schleimer, Wilkerson & Aiken, 2003), Dolos, JPlag, and Trail of Bits' Vendetect (2025). TrapR's structural layers use the same winnowing idea.
- Software watermarking: Collberg & Thomborson's static and dynamic watermarks (late 1990s onward); research systems such as SrcMarker, CodeMark and CoProtector.
- Canaries and honeytokens: Thinkst Canarytokens, GitGuardian honeytokens, and the "AI Code Canaries" defensive publication (Technical Disclosure Commons, 2024).
- License compliance: ScanCode, FOSSology, and commercial snippet matchers.
What TrapR adds is the maintainer-side workflow: one command to plant everything, a secret-keyed behavioral canary verified safely in a sandbox, and a private vault that both a CLI and an AI agent can use to hunt for copies.
Roadmap
- crates.io, Go modules and Maven scanning
- More canary types (string normalizers, checksums) and TypeScript behavior verification
- A cross-project vault index for one-command hunts across all your repos
- MCP tools that change files (
mark,refresh), behind an explicit confirmation - The merge gate as its own Marketplace Action (the hunt Action is already listed)
- Function-level matching for the cross-language
similaritycommand (verify and hunt have it since 0.6.0) - More places to hunt: grep.app and Sourcegraph public search, GitLab, Bitbucket
Contributing
Issues and PRs welcome. The rules are in AGENTS.md: one file, zero required dependencies, tests must pass, and detection changes need false-positive numbers.
https://github.com/jaykrishna316/TrapR/releases/download/v0.7.0/trapr-mcp.mcpb# mcpb: https://github.com/jaykrishna316/TrapR/releases/download/v0.7.0/trapr-mcp.mcpb