Query your local WeChat data from the command line.
Chat history · Contacts · Sessions · Favorites · Statistics · Export
- 🚀 Zero-config install —
npm install -gand you're done, no Python needed - 📦 11 commands — sessions, history, search, contacts, members, stats, export, favorites, unread, new-messages, init
- 🤖 AI-first — JSON output by default, designed for LLM agent tool calls
- 🔒 Fully local — on-the-fly SQLCipher decryption, data never leaves your machine
- 📊 Rich analytics — top senders, message type breakdown, 24-hour activity charts
- 📝 Flexible export — Markdown or plain text, with time range filtering
AI Agents — skip ahead to "Installation (For AI Agents)" below.
Install or update from this repository to get the macOS WeChat 4.1.13 key extraction fix:
python3 -m pip install --upgrade "git+https://github.com/sunfeihu007/wechat-cli.git@main"
wechat-cli --versionUse a Python virtual environment to avoid system Python restrictions. With Homebrew Python, create one using python3 -m venv ~/.venvs/wechat-cli and activate it using source ~/.venvs/wechat-cli/bin/activate. Confirm version 0.2.5, log in to WeChat on that machine, then run wechat-cli init --force. If administrator access is required, run sudo "$(command -v wechat-cli)" init --force. After re-signing, fully restart WeChat, log in, and repeat the same command.
The npm/PyPI instructions below refer to upstream releases. This fork's fix is distributed through the Git URL above and includes the rebuilt macOS arm64 helper. Other platform extractors are unchanged.
npm install -g @canghe_ai/wechat-cliCurrently ships a macOS arm64 binary. Other platforms can use the pip method below. PRs with additional platform binaries are welcome.
Update to the latest version:
npm update -g @canghe_ai/wechat-clipip install wechat-cliRequires Python >= 3.10.
git clone https://github.com/sunfeihu007/wechat-cli.git
cd wechat-cli
pip install -e .Simply paste the following prompt into Claude Code, OpenClaw, or any AI coding agent:
Install or update WeChat CLI from the main branch of https://github.com/sunfeihu007/wechat-cli in a Python virtual environment, confirm version 0.2.5, then refresh keys after WeChat is logged in on this machine.For example, in Claude Code:
Note: Make sure you have Node.js installed first. You can ask your agent to set it up if needed.
Make sure WeChat is running, then:
# macOS/Linux: may need sudo for memory scanning
sudo wechat-cli init
# Windows: run in a terminal with sufficient privileges
wechat-cli initThis auto-detects your WeChat data directory, extracts encryption keys, and saves config to ~/.wechat-cli/.
On macOS, you'll need to run the sudo command and enter your password:
If you have multiple WeChat accounts logged in locally, you'll be prompted to choose one. Select the account you're currently using (the default is the first one):
If you're unsure which WeChat account is currently active, navigate to the data folder and sort by modification date to find out:
Before running init, make sure your terminal app has Full Disk Access:
- Open System Settings → Privacy & Security → Full Disk Access
- Add your terminal app (e.g. Terminal, iTerm2, or the terminal in your IDE)
- Restart the terminal after enabling
Without this permission, the tool cannot access WeChat's data directory and key extraction will fail.
On some macOS systems, init may fail with task_for_pid failed even when running with sudo. This is due to macOS security restrictions on process memory access.
WeChat CLI will automatically attempt to fix this by re-signing WeChat with the required entitlement (original entitlements are preserved). Just follow the on-screen instructions:
- The tool will re-sign WeChat automatically
- Quit WeChat completely (not just minimize)
- Reopen WeChat and log in
- Run
sudo wechat-cli init --forceagain
If auto re-signing fails, you can do it manually:
# Quit WeChat first, then:
sudo codesign --force --sign - --entitlements /dev/stdin /Applications/WeChat.app <<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.get-task-allow</key>
<true/>
</dict>
</plist>
EOFHeads up: Re-signing WeChat is safe and will not cause account issues or bans. However, it may affect WeChat's auto-update mechanism. If you notice any feature not working properly, or want to update WeChat to the latest version, simply re-download and reinstall WeChat from the official website — no need to re-run
init, your existing config and keys will continue to work.
wechat-cli sessions # Recent chats
wechat-cli history "Alice" --limit 20 # Chat messages
wechat-cli search "deadline" --chat "Team" # Search messagesWeChat CLI is designed as an AI agent tool. All commands output structured JSON by default.
Add to your project's CLAUDE.md:
## WeChat CLI
You can use `wechat-cli` to query my local WeChat data.
Common commands:
- `wechat-cli sessions --limit 10` — list recent chats
- `wechat-cli history "NAME" --limit 20 --format text` — read chat history
- `wechat-cli search "KEYWORD" --chat "CHAT_NAME"` — search messages
- `wechat-cli contacts --query "NAME"` — search contacts
- `wechat-cli unread` — show unread sessions
- `wechat-cli new-messages` — get messages since last check
- `wechat-cli members "GROUP"` — list group members
- `wechat-cli stats "CHAT" --format text` — chat statisticsThen in conversation you can ask Claude things like:
- "Check my unread WeChat messages"
- "Search for messages about the project deadline in the Team group"
- "Who sent the most messages in the AI group this week?"
WeChat CLI works with any AI tool that can execute shell commands:
# Get recent conversations
wechat-cli sessions --limit 5
# Read specific chat
wechat-cli history "Alice" --limit 30 --format text
# Search with filters
wechat-cli search "report" --type file --limit 10
# Monitor for new messages (great for cron/automation)
wechat-cli new-messages --format textwechat-cli sessions # Last 20 sessions
wechat-cli sessions --limit 10 # Last 10
wechat-cli sessions --format text # Human-readablewechat-cli history "Alice" # Last 50 messages
wechat-cli history "Alice" --limit 100 --offset 50
wechat-cli history "Team" --start-time "2026-04-01" --end-time "2026-04-03"
wechat-cli history "Alice" --type link # Only links
wechat-cli history "Alice" --format textOptions: --limit, --offset, --start-time, --end-time, --type, --format
wechat-cli search "hello" # Global search
wechat-cli search "hello" --chat "Alice" # In specific chat
wechat-cli search "meeting" --chat "TeamA" --chat "TeamB" # Multiple chats
wechat-cli search "report" --type file # Only filesOptions: --chat (repeatable), --start-time, --end-time, --limit, --offset, --type, --format
wechat-cli contacts --query "Li" # Search contacts
wechat-cli contacts --detail "Alice" # Contact details
wechat-cli contacts --detail "wxid_xxx" # By WeChat IDReturns: nickname, remark, WeChat ID, bio, avatar URL, account type.
wechat-cli members "Team Group" # All members (JSON)
wechat-cli members "Team Group" --format textwechat-cli stats "Team Group"
wechat-cli stats "Alice" --start-time "2026-04-01" --end-time "2026-04-03"
wechat-cli stats "Team Group" --format textReturns: total messages, type breakdown, top 10 senders, 24-hour activity distribution.
wechat-cli export "Alice" --format markdown # To stdout
wechat-cli export "Alice" --format txt --output chat.txt # To file
wechat-cli export "Team" --start-time "2026-04-01" --limit 1000Options: --format markdown|txt, --output, --start-time, --end-time, --limit
wechat-cli favorites # Recent bookmarks
wechat-cli favorites --type article # Articles only
wechat-cli favorites --query "machine learning" # SearchTypes: text, image, article, card, video
wechat-cli unread # All unread sessions
wechat-cli unread --limit 10 --format textwechat-cli new-messages # First: return unread + save state
wechat-cli new-messages # Subsequent: only new since last callState saved at ~/.wechat-cli/last_check.json. Delete to reset.
The --type option (on history and search):
| Value | Description |
|---|---|
text |
Text messages |
image |
Images |
voice |
Voice messages |
video |
Videos |
sticker |
Stickers/emojis |
location |
Location shares |
link |
Links and app messages |
file |
File attachments |
call |
Voice/video calls |
system |
System messages |
- macOS ≥ 26.3.1
- WeChat for Mac: legacy hex scanning supports ≤ 4.1.8.100. This branch also reads
Config.Cipher, verified on Apple Silicon WeChat 4.1.13 (269631) against all 33 local database keys.
Other WeChat builds may require different layouts. Failed, empty, or invalid scans preserve existing keys. Verified new keys are merged with verified existing keys and saved atomically.
| Platform | Status | Notes |
|---|---|---|
| macOS (Apple Silicon) | ✅ Supported | Bundled arm64 binary |
| macOS (Intel) | ✅ Supported | x86_64 binary needed |
| Windows | ✅ Supported | Reads Weixin.exe process memory |
| Linux | ✅ Supported | Reads /proc/pid/mem, requires root |
WeChat stores chat data in SQLCipher-encrypted SQLite databases locally. WeChat CLI:
- Extracts keys — scans WeChat process memory for encryption keys (
init) - Decrypts on-the-fly — transparent page-level AES-256-CBC decryption with caching
- Queries locally — all data stays on your machine, no network access
This project is a local data query tool for personal use only. Please note:
- Read-only — this tool only reads locally stored data, it does not send, modify, or delete any messages
- No cloud transmission — all data stays on your local machine, nothing is uploaded to any server
- No WeChat ecosystem disruption — this tool does not interfere with WeChat's normal operation, does not automate any actions, and does not violate WeChat's Terms of Service
- Use at your own risk — this project is for personal learning and research purposes only. Users are responsible for ensuring compliance with local laws and regulations
This project is built on top of wechat-decrypt, which provides the core WeChat database decryption and data parsing capabilities.




