Encoding Guard logo

Encoding Guard

Community
cropflre
encoding-guard

Prevent garbled text (乱码) when editing code and comments. Use this skill whenever reading, writing, or modifying files to ensure proper UTF-8 encoding handling. Activates on any file edit operation, especially when working with Chinese characters, emoji, or non-ASCII content.

Overview

Publishercropflre
Repositorynowen-note
Skill nameencoding-guard
Stars
553
Forks
86
Bundled files
1
LicenseGPL-3.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by cropflre on GitHub. Read the source before you install it.

Installation

Install the Encoding Guard AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/cropflre/nowen-note/tree/main/.claude/skills/encoding-guard
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cropflre/nowen-note.git /tmp/nowen-note
mkdir -p .claude/skills
cp -r /tmp/nowen-note/.claude/skills/encoding-guard .claude/skills/encoding-guard
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Encoding Guard in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Encoding Guard on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Encoding Guard is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Encoding Guard

Ensures all file operations use proper UTF-8 encoding to prevent garbled text (乱码).

Core Principles

  1. Always use UTF-8 — Read and write files with explicit UTF-8 encoding
  2. Validate before write — Check that content is valid UTF-8 before saving
  3. Preserve BOM awareness — Detect and handle BOM (Byte Order Mark) when present
  4. Handle mixed encoding — Convert legacy encodings (GBK, GB2312, Big5) to UTF-8

When Reading Files

bash
# Always specify encoding when reading
cat -n file.tsx  # Use Read tool which handles encoding

# If you suspect encoding issues, check with:
file -I file.tsx  # Shows charset
hexdump -C file.tsx | head -5  # Inspect raw bytes

When Writing Files

bash
# Ensure locale supports UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# When using Edit tool, the content is already validated
# When using Write tool, ensure content is proper UTF-8

Detection Patterns

Watch for these signs of encoding problems:

  1. Mojibake characters: é, è, ü (UTF-8 read as Latin-1)
  2. Chinese garbled: 锟斤拷, 烫烫烫, 屯屯屯 (GBK/UTF-8 mismatch)
  3. Replacement character: � (U+FFFD) — missing or invalid bytes
  4. Question marks: ??? where Chinese should be

Fix Strategies

Strategy 1: Re-read with correct encoding

If a file shows garbled text:

bash
# Check current encoding
file -I problematic.tsx

# If it's GBK, convert to UTF-8
iconv -f GBK -t UTF-8 problematic.tsx > fixed.tsx
mv fixed.tsx problematic.tsx

Strategy 2: Use Read tool with encoding awareness

The Read tool automatically handles encoding. If you see garbled output:

  1. Stop and check the file's actual encoding
  2. Convert if needed before editing
  3. Then proceed with normal Read/Edit operations

Strategy 3: Validate after write

After any Edit or Write operation:

bash
# Quick validation
python3 -c "
with open('file.tsx', 'r', encoding='utf-8') as f:
    content = f.read()
    print(f'Valid UTF-8: {len(content)} chars')
"

Common Scenarios

Scenario 1: Editing TypeScript/JSX with Chinese comments

typescript
// ✅ Correct: UTF-8 encoded comment
// 这是一个中文注释

// ❌ Wrong: Encoding mismatch causes garbled
// 杩欐槸涓€涓�腑鏂囨敞閲�

Action: Always use UTF-8 locale. Set in shell:

bash
export LANG=en_US.UTF-8

Scenario 2: Mixed encoding in project

If some files are GBK and others UTF-8:

bash
# Find all non-UTF-8 files
find . -name "*.tsx" -exec file -I {} \; | grep -v utf-8

# Batch convert
for f in $(find . -name "*.tsx" -exec file -I {} \; | grep gb2312 | cut -d: -f1); do
    iconv -f GBK -t UTF-8 "$f" > "$f.utf8"
    mv "$f.utf8" "$f"
done

Scenario 3: Git shows encoding warnings

bash
# Configure git to handle encoding
git config core.quotepath false  # Show Chinese filenames correctly
git config i18n.commitencoding utf-8
git config i18n.logoutputencoding utf-8

Prevention Checklist

Before any file operation:

  • Locale is set to UTF-8 (echo $LANG should show *.UTF-8)
  • File encoding is verified (file -I filename)
  • Content being written is valid UTF-8
  • Editor/IDE is configured for UTF-8

Quick Diagnostic

Run this to check your environment:

bash
echo "Locale: $LANG"
echo "LC_ALL: $LC_ALL"
python3 -c "import sys; print(f'Default encoding: {sys.getdefaultencoding()}')"
python3 -c "import locale; print(f'Preferred encoding: {locale.getpreferredencoding()}')"

Expected output:

Locale: en_US.UTF-8
LC_ALL: en_US.UTF-8
Default encoding: utf-8
Preferred encoding: UTF-8

Integration with Tools

Read Tool

  • Automatically detects and handles encoding
  • If garbled, the file may need conversion first

Edit Tool

  • Content parameter must be valid UTF-8
  • Tool validates encoding before applying changes

Write Tool

  • Content parameter must be valid UTF-8
  • Overwrites file with UTF-8 encoding

Bash Tool

  • Set locale before commands: LANG=en_US.UTF-8 command
  • Pipe through iconv if needed: command | iconv -f GBK -t UTF-8

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Encoding Guard AI skill do?

Prevent garbled text (乱码) when editing code and comments. Use this skill whenever reading, writing, or modifying files to ensure proper UTF-8 encoding handling. Activates on any file edit operation, especially when working with Chinese characters, emoji, or non-ASCII content.

Why use Encoding Guard on TypingMind?

Because you install it once and use it with any model. Encoding Guard is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Encoding Guard in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/cropflre/nowen-note/tree/main/.claude/skills/encoding-guard. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Encoding Guard?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Encoding Guard?

As many as you like. As long as a model supports skills, you can use Encoding Guard with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Encoding Guard AI skill free?

Yes. It is published on GitHub by cropflre under the GPL-3.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇