# AI Text Encoding Guard

A detector and repair tool for Chinese text corruption, or mojibake, that AI coding assistants can silently introduce when editing files, usable as a GitHub Action, a Claude Code hook, or a standalone command-line scan.

AI Text Encoding Guard scans files for seven kinds of encoding damage, including UTF-8 bytes misread as GBK, corrupted HTML tags where an AI edit swallowed an angle bracket, and telltale character patterns left by double round-trip conversions, each contributing a weighted score; a file scoring above zero is flagged as suspicious, with a higher score meaning more severe corruption. A command-line tool scans a directory and can output JSON, fail a CI pipeline when it finds corruption, or attempt an automatic fix.

The automatic fix does not blindly replace text: it tries both directions of GB18030-to-UTF-8 re-encoding, then only applies a fix if the corruption score afterward has dropped to a third or less of the original and improved by at least eight points; anything that does not clear both thresholds is left alone and flagged for manual review, with a backup file created for anything it does change. It integrates as a GitHub Action that runs on push and pull request, or as a Claude Code PostToolUse hook that checks files after every Write or Edit.

It is written in Python and released under the MIT license.

Website: https://github.com/haodehaode378/text-encoding-guard
