by freestylefly
A CLI tool to query your local WeChat data — chat history, contacts, sessions, favorites, and more. Designed for LLM integration.
# Add to your Claude Code skills
git clone https://github.com/freestylefly/wechat-cliGuides for using ai agents skills like wechat-cli.
Last scanned: 5/17/2026
{
"issues": [
{
"type": "clone-failed",
"message": "Could not clone repository",
"severity": "medium"
}
],
"status": "WARNING",
"scannedAt": "2026-05-17T06:44:53.305Z",
"semgrepRan": false,
"npmAuditRan": false,
"pipAuditRan": false
}Query your local WeChat data from the command line.
Chat history · Contacts · Sessions · Favorites · Statistics · Export
npm install -g and you're done, no Python neededAI Agents — skip ahead to "Installation (For AI Agents)" below.
npm install -g @canghe_ai/wechat-cli
Currently 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-cli
pip install wechat-cli
Requires Python >= 3.10.
git clone https://github.com/freestylefly/wechat-cli.git
cd wechat-cli
pip install -e .
Simply paste the following prompt into Claude Code, OpenClaw, or any AI coding agent:
帮我配置并安装:npm install -g @canghe_ai/wechat-cli
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 init
This 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:
Without this permission, the tool cannot access WeChat's data directory and key extraction will fail.
task_for_pid failed ErrorOn 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:
sudo wechat-cli init againIf 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>
EOF
Heads 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 messages
WeChat 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 statistics
Then in conversation you can ask Claude things like:
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 text
sessions — Recent Chatswechat-cli sessions # Last 20 sessions
wechat-cli sessions --limit 10 # Last 10
wechat-cli sessions --format text # Human-readable
history — Chat Messageswechat-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 text
Options: --limit, --offset, --start-time, --end-time, --type, --format
search — Search Messageswechat-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 files
Options: --chat (repeatable), --start-time, --end-time, --limit, --offset, --type, --format
contacts — Contact Search & Detailswechat-cli contacts --query "Li" # Search contacts
wechat-cli contacts --detail "Alice" # Contact details
wechat-cli contacts --detail "wxid_xxx" # By WeChat ID
Returns: nickname, remark, WeChat ID, bio, avatar URL, account type.
members — Group Memberswechat-cli members "Team Group" # All members (JSON)
wechat-cli members "Team Group" --format text
stats — Chat Statisticswechat-cli stats "Team Group"
wechat-cli stats "Alice" --start-time "2026-04-01" --end-time "2026-04-03"
wechat-cli stats "Team Group" --format text
Returns: total messages, type breakdown, top 10 senders, 24-hour activity distribution.
export — Export Conversationswechat-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 1000
Options: --format markdown|txt, --output, --start-time, --end-time, --limit
favorites — WeChat Bookmarkswechat-cli favorites # Recent bookmarks
wechat-cli favorites --type article # Articles only
wechat-cli favorites --query "machine learning" # Search
Types: text, image, article, card, video
unread — Unread Sessionswechat-cli unread # All unread sessions
wechat-cli unread --limit 10 --format text
new-messages — Incremental New Messageswechat-cli new-messages # First: return unread + save state
wechat-cli new-messages # Subsequent: only new since last call
State 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 |
Older macOS versions or newer WeChat versions may not be compatible.
| Platform | Status | Notes | |----------|--------
No comments yet. Be the first to share your thoughts!