Stripping hidden characters does not remove an AI text watermark
To scramble and blur statistical watermarks in AI generated text, the kind Claude, Gemini and other models put into the words they pick, you can use ai-watermark-scrambler, an open source (Apache-2.0) agent skill and set of Python scripts I wrote at github.com/novatechflow/ai-watermark-scrambler. A statistical watermark is not a hidden character or a metadata field. It is a bias in which tokens the model chose, and a detector with the secret key finds it by counting. ai-watermark-scrambler has the text written again by a different model of your choice, open weight on vLLM or Ollama or any OpenAI compatible endpoint, in four strengths, simplify, paraphrase, backtranslate and structural. That changes the word choices the watermark lives in, so the detector's score falls. It blurs the mark, it does not certify that it is gone, and one pass often leaves a context-free watermark detectable. As side jobs it removes invisible Unicode and C2PA, EXIF, XMP and document metadata from text, Markdown, HTML, PNG, JPEG, SVG, PDF, DOCX and ODT. Pixel, audio, video and visible watermarks are out of scope.
Claude, Gemini and other models now mark the text they write. Anthropic describes Claude's text watermark as woven into the text itself. It survives copy and paste, and it gets weaker under paraphrase, translation or a heavy edit. Google published SynthID-Text in Nature. Neither the algorithm details nor the keys behind these production marks are public, but the class is well known from research.
It is not only those two, and the rules differ a lot between vendors. This is how it looks in November 2026. OpenAI calls its mark textGrain. It is adding it to eligible ChatGPT and Codex text in the EU, and in its API it is off by default, so customers opt in for select models (OpenAI). xAI's API docs say Grok text watermarking is built on SynthID Text. It is off by default, a team admin turns it on per model, and turning it off again means confirming that a legal exception applies to your use. Some models can be locked on. Mistral does not mark text yet, but it says it will ship output marking and a detection tool by December 2, 2026, the EU AI Act deadline. Google says SynthID marks the text of the Gemini app and web experience. For the Gemini API, Google's own docs say nothing either way, but researchers at ETH Zurich's SRI Lab measured the mark on every Gemini model they tested through the API. I found no Google setting that turns the text mark off. The watermark switch in the Gemini app only controls visible marks on images, video and music, and Google says it does not affect SynthID. Claude is the strict one. Anthropic marks supported models in every product and region, and Amazon's Bedrock docs say you cannot turn the Claude mark off. Every one of these is a mark in the word choices, not a hidden character.
That kind of mark does not sit in a header or a hidden character. It sits in which words the model picked. You cannot delete it like a metadata field. The only way to blur it is to have the text written again by a different model, so the word choices change. That is the job of ai-watermark-scrambler, and it is honest about what it cannot prove. It is written as an agent skill, so a coding agent can run it for you, but every step is a plain Python script you can run yourself.
Code: github.com/novatechflow/ai-watermark-scrambler. Open source under Apache-2.0. Python scripts that need only the standard library, tested in CI on Python 3.11, 3.12 and 3.13. There is no PyPI package, you clone the repository. Optional extras are pikepdf for PDFs, c2pa-python for C2PA inspection and exiftool for a second metadata pass on images.
Why I built ai-watermark-scrambler
- Anthropic and Google watermark the text their models write, and those text watermarks are statistical. They sit in the words the model picks. OpenAI and xAI have statistical text marks too, and Mistral says it will add one by December 2026.
- You cannot see that kind of mark and you cannot delete it like a metadata field. You can only scramble it.
- My question was, what happens to that mark when I rework or translate the text? Translating with another model is already a rewrite.
- So I built the rewrite step as the core. Run the text through a different model, change the word choices, blur the statistics.
- I run it on AI generated text, on translations and on drafts.
- For the rewrite I use open weight models on vLLM and Ollama. Any OpenAI compatible endpoint works.
- The metadata and invisible character cleaning came along because it is the easy part of the same job.
- Who should use it? Whoever wants to. It is open source.
How a statistical text watermark works
Nothing is hidden between the letters. At every step the model chooses the next token, and the watermark biases that choice.
- Green list and red list. In the scheme from Kirchenbauer et al., 2023, the recent tokens are hashed with a secret key, and that splits the vocabulary into a green list and a red list. Green tokens get a small boost to their logits. The sentence still reads normally.
- The mark is a count. Watermarked text has more green tokens than chance would give. A detector with the key counts them and turns the excess into a z-score. Long text is easy to call. Short text often is not.
- SynthID-Text does the same job differently. Dathathri et al., Nature 2024 use tournament sampling, where a keyed score picks among candidate tokens.
- Claude's text watermark is this class. Anthropic describes it as part of the text, not the file, and has not published the algorithm or the key.
- Context hash or context free. A context-hash list is redrawn from the previous tokens. A context-free list, the unigram watermark from Zhao et al., 2023, colors each token green or red on its own. That one survives small edits better, because changing a word does not reshuffle the lists after it.
- The signal sits in content words. The bias only works where the model had a real choice. Function words are predictable, so forcing them would sound wrong. The mark lives in choices like purchase or buy, approximately or about.
Why a rewrite blurs it
The detector's evidence is more green tokens than chance. Replace those tokens and the evidence shrinks. That is the blur. It is not a certificate.
- A context-hash mark also loses alignment. Change one word and the green lists after it are rebuilt, so later words you did not touch stop counting.
- A context-free mark does not. The new word is green or red on its own. You only gain on the words you change, and only when the replacement is off the list.
- The rewrite has to come from somewhere else. Running the text back through the same watermarked model writes a new statistical mark in place of the old one. Use a model from a different family than the one that likely wrote the text.
Scramble the watermark with rewrite_text.py
The repo calls the rewrite Layer B. rewrite_text.py has four strengths, split by how much of the token sequence moves:
simplify. Content words become shorter, more common synonyms. Function words, names and numbers stay, and so does the sentence order. A context-hash mark moves. A context-free mark often stays, because the simpler word can still be green. Based on synonym substitution as studied by Cheng et al., 2025.paraphrase, the default. New wording in every sentence, same sentence order. That is the lexical diversity knob of DIPPER from Krishna et al., 2023.backtranslate. Out to another language and back, French by default and set with--lang. This is the attack used in the Kirchenbauer robustness evaluation.structural. The text becomes an outline of claims, then a new document with new wording and a new sentence order. That moves the most tokens and drifts furthest from the source.
There are three backends. The default, print-prompt, calls no model at all. It prints the prompt so you or your agent can run the rewrite anywhere:
SCRIPTS=skills/ai-watermark-scrambler/scripts
python3 $SCRIPTS/rewrite_text.py draft.md --backend print-prompt --strength simplify
ollama drives a local Ollama server. If you have not set Ollama up yet, my post on running Llama 3 or any LLM on your MacBook covers it.
python3 $SCRIPTS/rewrite_text.py draft.md -o draft.rewritten.md \
--backend ollama --model llama3.2 --base-url http://127.0.0.1:11434 \
--strength paraphrase
openai-compatible talks to /v1/chat/completions, so vLLM, llama.cpp or a hosted API all work. You can set everything through environment variables instead of flags:
export WATERMARKS_REWRITE_BACKEND=openai-compatible
export WATERMARKS_REWRITE_BASE_URL=http://127.0.0.1:8000
export WATERMARKS_REWRITE_MODEL=mistralai/Mistral-7B-Instruct-v0.3
export WATERMARKS_REWRITE_API_KEY=... # only if your server needs one
python3 $SCRIPTS/rewrite_text.py draft.md --strength structural
If the base URL is not localhost, the script warns you that the text will leave your machine. After the rewrite it runs the Layer A clean on the model output again, because a model can add invisible characters of its own. --no-layer-a-after turns that off.
For code, do not rewrite. Statistical marks in code are weak and a rewrite risks breaking it. Run a formatter such as prettier, black or gofmt plus the Layer A clean instead.
Measure the blur with the research harness
You cannot score a vendor watermark without the vendor key, and those keys are not public. So the repo ships a small research harness in demo/ that makes its own watermark with a key it holds and then measures what happens to it.
- It builds a 400 token document where each token comes from a green list of about a quarter of a fixed vocabulary.
context/1hashes one previous token,context/8hashes eight, andunigramhashes only the key. - It runs Layer A on that document. The mark is not a hidden character, so the z-score does not move.
- It replaces about 30% of the tokens with words chosen without the key. That is a stand-in for a Layer B rewrite, not a call to a real model.
make qa
tokens=400 gamma=0.25 rewrite_rate=0.3 seed=2026
context/1 marked 34.53 after Layer A 34.53 after unkeyed rewrite 19.54
context/8 marked 34.53 after Layer A 34.53 after unkeyed rewrite 1.67
unigram marked 34.53 after Layer A 34.53 after unkeyed rewrite 24.85
The eight token context drops below the usual detection region of a z-score around 4, because after a changed word the lists stay wrong until eight untouched tokens in a row have passed. The one token context only gets a dent, and the unigram list keeps most of its score. That is why one light synonym pass is not the whole of Layer B, and why simplify is the weak strength.
The harness can also send a paragraph to ZeroGPT before and after the rewrite if you set ZEROGPT_API_KEY. Treat that as a side by side look, not a pass or fail. ZeroGPT, GPTZero and similar classifiers guess whether prose reads like a model. They do not have the watermark key and do not compute this z-score.
What it cannot promise
This part matters as much as the rewrite, so it is in the README and in the skill itself.
- Blurred, not certified gone. Without the vendor's detector and key nobody can check the result. The tool never calls the result undetectable.
- One pass is often not enough for a unigram watermark. The repo says so, citing Zhao et al. and Rastogi and Pruthi (EMNLP 2024). A context-free mark often survives a single paraphrase.
- No watermark stealing. Querying the watermarked model to learn its green list and then swapping words, as in Wu and Chandrasekaran, 2024 and Jovanović et al., 2024, is not implemented. It needs the watermarked model as an oracle, and the skill does not call one.
- Pixel, audio and video watermarks are a different thing. SynthID for images and media sits in the signal. The skill does not ship the generative denoiser a removal attack would need, and it does not claim those marks are gone.
- Visible watermarks stay. Logos and stock stamps on a single image cannot be inverted, so the tool does not try.
- C2PA soft binding stays. A watermark in the content that points back to a remote manifest survives a metadata strip by design.
- Model side marks are out of reach. Anything trained into a model, such as trigger phrases.
The side jobs, invisible Unicode and metadata
Invisible characters are not the statistical watermark. They are a separate channel that often rides along with AI output and copied text, together with metadata in files. The repo calls the character clean Layer A. It is deterministic and you can verify it.
- Text. Zero width spaces and joiners, the word joiner, the byte order mark, soft hyphens, bidi controls, Unicode tag characters, variation selectors and other invisible format characters are removed. Exotic spaces such as the no-break space and the ideographic space become a normal space. Emoji sequences and the joiners that Arabic, Indic and Myanmar letters need stay. Stray copies are removed.
- PNG and JPEG. C2PA manifests (the JPEG APP11 segment), text chunks and EXIF and XMP. Color data stays, so PNG keeps its ICC profile, gamma, sRGB and cHRM chunks, and JPEG keeps JFIF, the ICC profile and the Adobe APP14 segment. If
exiftoolis installed it runs a second metadata pass that leaves the color data alone. - SVG.
<metadata>blocks and XMP packets. - PDF. XMP, the document info dictionary and C2PA manifests attached to the file. With
pikepdf, orqpdfas a fallback, the file is written fresh so the old metadata does not stay readable in an earlier revision. - DOCX and ODT. Document properties,
customXmlparts and their relationships,meta:generator, and invisible Unicode in the document text. - HTML. AI generator meta tags, provenance meta names, provenance JSON-LD and
data-ai*attributes, plus the Layer A clean. The description, Open Graph tags, a CMS generator tag and ordinary JSON-LD stay. - Markdown. Provenance key names in the YAML front matter, such as
generatororai_generated, plus the Layer A clean. A title or description that only mentions a vendor stays.
The workflow is always inspect, clean, inspect again. Here is a Markdown note from the test fixtures in the repo:
python3 $SCRIPTS/inspect_file.py tests/fixtures/sample_ai.md
Kind: container
Path: tests/fixtures/sample_ai.md
Format: markdown
C2PA: False
AI metadata: True
- frontmatter key: generator
- frontmatter key: ai_generated
python3 $SCRIPTS/clean_file.py tests/fixtures/sample_ai.md -o note.cleaned.md
python3 $SCRIPTS/inspect_file.py note.cleaned.md # AI metadata: False, exit 0
For plain text, inspect_text.py lists each invisible character with its code point, name, count and position, and clean_text.py removes them. Both read from stdin with -:
pbpaste | python3 $SCRIPTS/clean_text.py - | pbcopy # clean the clipboard on macOS
By default the tool writes a *.cleaned.* copy next to the input. --in-place overwrites the file, keeps a .bak of the original and refuses to write through a symlink. --nfkc and --aggressive-homoglyphs change more than invisible characters, so use them on purpose.
Install ai-watermark-scrambler
git clone https://github.com/novatechflow/ai-watermark-scrambler
cd ai-watermark-scrambler
# optional, installs pikepdf and c2pa-python into the skill's own venv
make tools
# optional, for the second metadata pass on images
brew install exiftool # macOS
sudo apt install libimage-exiftool-perl # Debian or Ubuntu
python3 skills/ai-watermark-scrambler/scripts/ensure_tools.py # what is installed
The scripts work without any of the extras. The extras only remove degraded modes. They go into a .venv inside the skill folder, and the scripts find it on their own.
Use it from an agent
Cloning the repo does not load the skill. Agents only read a skill from a discovery directory, and skills/ at the repo root is not one. Put the folder where your agent looks:
- Grok, all projects.
make install-skilllinks it to~/.grok/skills/ai-watermark-scrambler. You get/ai-watermark-scrambler, and Grok uses it on its own when a request matches the description. SetSKILLS_DIRto link it somewhere else. - Grok, one repo.
<repo>/.grok/skills/ai-watermark-scrambler, so anyone who clones that repo has it. - Claude Code.
~/.claude/skills/ai-watermark-scrambleror<repo>/.claude/skills/ai-watermark-scrambler. - Cursor.
~/.cursor/skills/ai-watermark-scrambleror<repo>/.cursor/skills/ai-watermark-scrambler. - Anything that can run Python. Point the agent at
skills/ai-watermark-scrambler/SKILL.mdand it follows the workflow and runs the scripts.
# all Grok projects
make install-skill
# Claude Code, all projects
mkdir -p ~/.claude/skills
ln -sfn "$(pwd)/skills/ai-watermark-scrambler" ~/.claude/skills/ai-watermark-scrambler
The slash command is the folder name. /remove-ai-marks and /remove-claude-marks in the description are trigger phrases, not extra commands. The agent inspects, writes a cleaned copy, offers the rewrite for prose with a model other than the likely origin, inspects again, and reports what was verified, which scramble ran, and that the statistical signal is not certified gone. make test and make smoke check the scripts, not that your agent loaded the skill.
If you install skills from other people, read them first. I wrote about what goes wrong otherwise in how I built a secure AI agent squad with OpenClaw.
Exit codes for scripts and pipelines
- 0 means clean, nothing found or everything removed.
- 1 means marks were found by an inspect, or something is still there after a clean.
- 2 means bad input, a missing path, an unsupported type or a file the cleaner cannot read.
- 3 means degraded. The cleaner ran without a tool it needed and the output is not fully cleaned. The common case is a PDF without
pikepdforqpdf.
The codes are the same across every script, and a test in the repo pins them and the documented flags against the real --help output. An inspect that finds something exits 1 on purpose, so guard it in make or shell scripts.
Things to know before you use it on real files
- A rewrite changes your text.
structuraldrifts the most. Read the result, check numbers and names, and start withsimplifyorparaphrase. - Emoji and some scripts need invisible characters. Family emoji are joined with zero width joiners, the red heart uses a variation selector, and the flags of England, Scotland and Wales are built from tag characters. Persian and several Indic scripts use the zero width non-joiner for correct spelling. Layer A keeps these sequences and only removes stray copies, but read such text after a clean anyway.
- No-break spaces become normal spaces. French typography and some number formats use them on purpose.
clean_text.pyhas--no-normalize-spacesto keep them. - The default image strip removes all EXIF and XMP, not only the AI parts. Color data stays.
--keep-non-ai-metadatadrops only the segments that look like C2PA or AI metadata and keeps the rest. - Check the diff on Markdown and HTML. The rules target provenance key names and AI generator tags, and leave titles, descriptions and Open Graph tags alone. Diff the cleaned copy before you publish it anyway.
- It is a young project. There are no tagged releases yet, so pin the commit you tested.
What it is for and what it is not for
The main use is research on how robust statistical text watermarks really are, and scrambling them in your own text and translations. Stripping metadata from your own files before you publish them is ordinary hygiene too. EXIF holds locations, document properties hold names and history, and invisible characters break parsers, diffs and search.
It is not a way around a disclosure you owe someone. If a university, a publisher, a court or a customer has a rule that you tell them when AI was used, removing the mark does not change what you have to tell them. Laws on metadata removal and document handling differ between countries, and checking them is your job.
Frequently asked questions
Can ai-watermark-scrambler remove the Claude or Gemini text watermark?
It scrambles and blurs it. The rewrite has a different model write the text again, which changes the word choices the watermark depends on, so the detector's score falls. Without the vendor's detector nobody can prove the mark is gone, and one pass often leaves a context-free watermark detectable.
Are invisible Unicode characters the AI watermark?
No. Zero width characters and odd spaces are a separate channel that the tool removes deterministically. The statistical watermark is in the choice of words, and only a rewrite touches it.
Can I rewrite the text with the same model that wrote it?
You should not. A watermarked model writes a new statistical mark into the rewrite. Use a model from another family, for example an open weight model on Ollama or vLLM for Claude text.
How do I remove C2PA Content Credentials from a PNG or JPEG?
Run clean_file.py image.png -o image.cleaned.png and then inspect_file.py on the result. The hard bound manifest in the file is removed. A soft binding watermark in the pixels, if the generator used one, is not.
Does it need an internet connection?
No. Inspecting and cleaning run locally. The rewrite talks to the model server you point it at, which can be on localhost.
Papers and sources
- Google DeepMind, SynthID. Text marks in the Gemini app and web.
- ETH Zurich SRI Lab, Probing the SynthID-text deployment on Gemini APIs. All tested Gemini API models marked.
- Gemini Apps Help, Manage watermark settings. Visible marks only, SynthID unaffected.
- OpenAI, 2026, Our approach to EU text provenance rules. textGrain, EU rollout, API opt-in.
- xAI, Output Watermarking. Grok API text marks, SynthID Text, team setting.
- Mistral AI Legal Center, Vibe Work. Output marking planned by December 2, 2026.
- Amazon Bedrock, Watermarking. Claude text mark on by default and cannot be disabled.
- Kirchenbauer et al., 2023, A Watermark for Large Language Models. Green list, logit bias, z-score.
- Zhao et al., 2023, Provable Robust Watermarking for AI-Generated Text. The context-free unigram list.
- Dathathri et al., 2024, Scalable watermarking for identifying large language model outputs. SynthID-Text.
- Krishna et al., 2023, Paraphrasing evades detectors of AI-generated text. DIPPER.
- Cheng et al., 2025, Revealing Weaknesses in Text Watermarking Through Self-Information Rewrite Attacks.
- Wu and Chandrasekaran, 2024, Bypassing LLM Watermarks with Color-Aware Substitutions. Not implemented.
- Jovanović et al., 2024, Watermark Stealing in Large Language Models. Not implemented.
- Anthropic, How Claude marks AI-generated content. Text watermark plus C2PA. Detection of the text mark is a private preview.
- Anthropic, How Claude's text watermarking works. The mechanism write-up.
Source code
ai-watermark-scrambler is on GitHub at github.com/novatechflow/ai-watermark-scrambler under Apache-2.0, with a pytest suite that also covers the rewrite hook, zip bombs in DOCX and ODT, symlink writes, path handling and the research harness. Issues and pull requests are welcome.
If you are cleaning PDFs before you make them searchable, my post on chatting with PDFs locally using OCR, RAG and Ollama with docai picks up from there. And if you need help with AI systems that have to handle provenance and compliance properly, that is the kind of work I do in my consulting.
Need help with distributed systems, backend engineering or data platforms? See my consulting services.