| name | wechat-cli-local-data |
| description | Query local WeChat chat history, contacts, sessions, and favorites from the command line with AI-first JSON output |
| triggers | ["check my wechat messages","search wechat chat history","export wechat conversation","get wechat unread messages","show wechat contacts","analyze wechat chat statistics","query my local wechat data","read wechat group messages"] |
WeChat CLI — Local Data Query Skill
Skill by ara.so — Devtools Skills collection.
A CLI tool to query your local WeChat data — chat history, contacts, sessions, favorites, and more. Designed for LLM integration with JSON output by default. All data stays on your machine; uses on-the-fly SQLCipher decryption.
Installation
npm (Recommended)
npm install -g @canghe_ai/wechat-cli
Currently ships with macOS arm64 binary. For other platforms, use pip:
pip install wechat-cli
Requires Python >= 3.10.
From Source
git clone https://github.com/freestylefly/wechat-cli.git
cd wechat-cli
pip install -e .
Initial Setup
Before using any commands, you must initialize the tool to extract WeChat encryption keys:
sudo wechat-cli init
wechat-cli init
Prerequisites:
- WeChat must be running
- On macOS: Terminal needs "Full Disk Access" (System Settings → Privacy & Security → Full Disk Access)
This command:
- Auto-detects WeChat data directory
- Scans WeChat process memory for encryption keys
- Saves config to
~/.wechat-cli/
macOS: Handling task_for_pid failed Error
If init fails with task_for_pid failed, the tool will automatically re-sign WeChat with required entitlements:
- Follow on-screen instructions
- Quit WeChat completely
- Reopen WeChat and log in
- Run
sudo wechat-cli init again
Manual re-signing (if auto-signing fails):
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
Core Commands
Sessions — List Recent Chats
wechat-cli sessions
wechat-cli sessions --limit 10
wechat-cli sessions --format text
JSON Output Structure:
[
{
"chat_name": "Alice",
"last_message": "See you tomorrow!",
"last_time": "2026-04-15 18:30:45",
"unread_count": 2
}
]
History — Read Chat Messages
wechat-cli history "Alice"
wechat-cli history "Alice" --limit 100 --offset 50
wechat-cli history "Team Group" --start-time "2026-04-01" --end-time "2026-04-03"
wechat-cli history "Alice" --type link
wechat-cli history "Alice" --format text --limit 20
JSON Output Structure:
[
{
"msg_id": "123456",
"type": "text",
"content": "Hello!",
"sender": "Alice",
"timestamp": "2026-04-15 10:30:00",
"is_sender": false
}
]
Search — Find Messages
wechat-cli search "deadline"
wechat-cli search "meeting notes" --chat "Work Team"
wechat-cli search "report" --chat "TeamA" --chat "TeamB"
wechat-cli search "proposal" --type file
wechat-cli search "budget" --start-time "2026-04-01" --end-time "2026-04-30"
Contacts — Search & Details
wechat-cli contacts --query "Li"
wechat-cli contacts --detail "Alice"
wechat-cli contacts --detail "wxid_abc123xyz"
JSON Output (Detail):
{
"nickname": "Alice",
"remark": "Alice from Marketing",
"wechat_id": "wxid_abc123xyz",
"bio": "Always learning",
"avatar_url": "https://...",
"account_type": "personal"
}
Members — Group Member List
wechat-cli members "AI Research Group"
wechat-cli members "AI Research Group" --format text
Stats — Chat Analytics
wechat-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 message count
- Message type breakdown (text, image, file, etc.)
- Top 10 senders with message counts
- 24-hour activity distribution
Export — Save Conversations
wechat-cli export "Alice" --format markdown
wechat-cli export "Alice" --format txt --output alice_chat.txt
wechat-cli export "Team Group" --start-time "2026-04-01" --limit 1000 --format markdown --output team_april.md
Supported formats: markdown, txt
Favorites — WeChat Bookmarks
wechat-cli favorites
wechat-cli favorites --type article
wechat-cli favorites --query "machine learning"
Types: text, image, article, card, video
Unread — Unread Sessions
wechat-cli unread
wechat-cli unread --limit 10 --format text
New Messages — Incremental Updates
wechat-cli new-messages
wechat-cli new-messages
wechat-cli new-messages --format text
State saved at ~/.wechat-cli/last_check.json. Delete to reset.
Use Case: Perfect for automation/cron jobs to monitor new messages.
AI Agent Integration
WeChat CLI is designed for AI agent tool calls. All commands output JSON by default.
Claude Code Integration
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
All commands output JSON by default. Add `--format text` for human-readable output.
Example Agent Workflows
Check unread messages:
wechat-cli unread --format text
Search for project updates:
wechat-cli search "project status" --chat "Work Team" --start-time "2026-04-01"
Analyze chat activity:
wechat-cli stats "AI Discussion Group" --format text
Export important conversation:
wechat-cli export "Client Meetings" --start-time "2026-04-01" --end-time "2026-04-07" --format markdown --output client_weekly.md
Message Type Filters
Use with --type option on history and search commands:
| Type | 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 |
Common Patterns
Monitor New Messages in Script
#!/bin/bash
while true; do
NEW_MSGS=$(wechat-cli new-messages --format text)
if [ -n "$NEW_MSGS" ]; then
echo "New messages detected:"
echo "$NEW_MSGS"
fi
sleep 300
done
Search Across Multiple Groups
wechat-cli search "deadline" \
--chat "Project Alpha" \
--chat "Project Beta" \
--chat "Project Gamma" \
--format text
Export Weekly Summaries
START_DATE=$(date -d "7 days ago" +%Y-%m-%d)
END_DATE=$(date +%Y-%m-%d)
wechat-cli export "Team Sync" \
--start-time "$START_DATE" \
--end-time "$END_DATE" \
--format markdown \
--output "team_sync_weekly.md"
Get Contact Details Before Messaging
CONTACT_INFO=$(wechat-cli contacts --detail "New Client")
if [ $? -eq 0 ]; then
echo "Contact found:"
echo "$CONTACT_INFO" | jq '.nickname, .wechat_id'
else
echo "Contact not found"
fi
Configuration
Configuration stored at ~/.wechat-cli/:
~/.wechat-cli/
├── config.json # WeChat data path, account info
├── keys.json # Encryption keys (auto-extracted)
└── last_check.json # State for new-messages command
config.json structure:
{
"data_dir": "/Users/username/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/abc123",
"account_id": "wxid_abc123xyz"
}
To reset: Delete ~/.wechat-cli/ and run init again.
To switch accounts: Run init again and select different account.
Troubleshooting
"WeChat data directory not found"
Solution:
- Ensure WeChat is running
- On macOS: Grant "Full Disk Access" to your terminal app
- Run
init with sudo on macOS/Linux
"Failed to extract encryption key"
Solution:
- On macOS: Re-sign WeChat (tool will auto-attempt this)
- Ensure WeChat is logged in and active
- Try restarting WeChat and running
init again
"Database decryption failed"
Solution:
- WeChat version changed — run
init again to refresh keys
- Database corruption — check WeChat data directory permissions
Empty Results for Valid Chat Name
Solution:
- Use exact chat name (case-sensitive)
- For groups, use full group name as shown in WeChat
- Use
sessions command to see exact chat names
- Try searching with partial name using
contacts --query
new-messages Returns Everything
Solution:
- Delete
~/.wechat-cli/last_check.json to reset state
- First run after reset will return all unread messages
- Subsequent runs will only show new messages
Permission Denied Errors
macOS/Linux:
sudo wechat-cli init
wechat-cli sessions
Windows:
- Run terminal as Administrator for
init
- Regular commands can run without elevation
System Requirements
- macOS ≥ 10.15 (Catalina)
- WeChat for Mac ≤ 4.1.8.100
- Python ≥ 3.10 (for pip installation)
- Node.js (for npm installation)
Platform Support:
| Platform | Status | Notes |
|---|
| macOS (Apple Silicon) | ✅ | Bundled arm64 binary |
| macOS (Intel) | ✅ | Supported via pip/source |
| Windows | ✅ | Reads Weixin.exe process memory |
| Linux | ✅ | Reads /proc/pid/mem, requires root |
How It Works
- Key Extraction: Scans WeChat process memory for SQLCipher encryption keys
- Decryption: Transparent AES-256-CBC decryption with page-level caching
- Query: Local SQLite queries on decrypted database
- Privacy: All data stays local — no network access, no cloud transmission
Read-only: This tool only reads locally stored data, never sends or modifies messages.
Quick Reference
sudo wechat-cli init
wechat-cli sessions --limit 10
wechat-cli history "Alice" --limit 50
wechat-cli search "keyword" --chat "Group"
wechat-cli contacts --detail "Bob"
wechat-cli unread
wechat-cli new-messages
wechat-cli sessions --format text
wechat-cli history "Alice" --format text --limit 20
wechat-cli stats "Group" --format text
wechat-cli export "Chat" --format markdown --output file.md
wechat-cli stats "Group"
wechat-cli members "Group"
wechat-cli favorites --query "search term"
--limit N --offset N
--start-time "YYYY-MM-DD" --end-time "YYYY-MM-DD"
--type text|image|voice|video|file|link|call|system
--format json|text