百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
W

whatsapp-cli

> AI 编程
开源

危险!危险!高电压!让你的 Codex/Claude 访问 WhatsApp

191 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

危险!危险!高电压!让你的 Codex/Claude 访问 WhatsApp

WhatsApp CLI - Complete Reference

For Humans & LLMs: This document covers the WhatsApp CLI tool: installation, usage, the API reference, examples, architecture, and troubleshooting. Humans and large language models can both read it.

Version: 1.3.2 Repository: https://github.com/vicentereig/whatsapp-cli License: MIT Language: Go 1.24+


Table of Contents

  • Overview
  • Installation
  • Quick Start
  • Complete Command Reference
  • JSON Response Format
  • Usage Examples
  • Integration with LLMs/AI Tools
  • Data Model
  • Storage & Persistence
  • Authentication & Security
  • Architecture
  • Error Handling
  • Troubleshooting
  • Development
  • FAQ
  • Credits

Overview

What is WhatsApp CLI?

WhatsApp CLI is a standalone command-line tool for WhatsApp. It uses the WhatsApp Web multidevice protocol. Every command returns structured JSON output. Use it for:

  • Automation: Shell scripts, cron jobs, CI/CD pipelines
  • AI Integration: Codex, Claude Code, GPT-based tools
  • Data Analysis: Extract and analyze WhatsApp conversations
  • Custom Applications: Build tools on top of WhatsApp

Key Features

Feature Description
Zero Dependencies Single compiled binary (21MB), no runtime required
JSON Output All commands return structured JSON for easy parsing
Persistent Sessions Authenticate once via QR code, auto-reconnect for ~20 days
Local Storage SQLite database, no cloud dependencies
Full Messaging Send, receive, search messages; manage contacts & chats
Group Support Send/receive messages in group chats
TDD Implementation 100% test coverage, production-ready

System Requirements

  • Operating System: Linux, macOS, Windows
  • Architecture: x86_64, ARM64
  • Go Version: 1.24+ (for building from source)
  • Storage: ~50MB for binary + variable for message database
  • Network: Internet connection required
  • WhatsApp Account: Active WhatsApp account with smartphone

Installation

Method 1: Homebrew (Recommended)

bash
brew install vicentereig/tap/whatsapp-cli

Or tap first, then install:

bash
brew tap vicentereig/tap
brew install whatsapp-cli

Method 2: Download Pre-built Binary

…

Method 3: Build from Source

bash
# Clone repository
git clone https://github.com/vicentereig/whatsapp-cli.git
cd whatsapp-cli

# Install dependencies
go mod download

# Build
go build -o whatsapp-cli .

# Install (optional)
sudo mv whatsapp-cli /usr/local/bin/

# Verify installation
whatsapp-cli --help

Method 4: Install via Go

bash
go install github.com/vicentereig/whatsapp-cli@latest

Release & Distribution Notes

  • Version tags use semantic versioning (vMAJOR.MINOR.PATCH). For reproducible builds, use a specific tag, for example v1.0.0, with go install github.com/vicentereig/[email protected].
  • The GitHub Releases page has pre-built artifacts for Linux, macOS, and Windows. Each archive has a matching SHA-256 entry in checksums.txt. Before you install, run shasum -a 256 -c checksums.txt --ignore-missing to verify the archive.
  • Binaries use the name whatsapp-cli-- (Windows adds .exe). After you extract the file, mark it executable with chmod +x and place it in your PATH, for example /usr/local/bin/whatsapp-cli.
  • Each uploaded file, including checksums.txt, also has a Sigstore cosign signature (.sig) and certificate (.pem). To verify a file, run cosign verify-blob --certificate .pem --signature .sig . GitHub Actions uses OIDC identities, so you can enforce provenance during verification.
  • To build from source, follow Method 3. Use this method to audit the code, change compilation flags, or test changes before you tag a release.
  • Maintainers can follow the steps in docs/RELEASE.md. It covers go install, source builds, and GitHub Release automation.

Quick Start

Step 1: First-Time Authentication

bash
whatsapp-cli auth

What happens:

  1. QR code appears in terminal
  2. Open WhatsApp on your phone → Settings → Linked Devices → Link a Device
  3. Scan the QR code
  4. Session saved to ./store/whatsapp.db

Output:

json
{
  "success": true,
  "data": {
    "authenticated": true,
    "message": "Successfully authenticated"
  },
  "error": null
}

Session Duration: ~20 days before re-authentication required

Step 2: Sync Messages

Before you list or search messages, sync them from WhatsApp:

bash
# Start syncing messages (run this in the background or a separate terminal)
whatsapp-cli sync
# Press Ctrl+C when done syncing

What happens:

  1. Connects to WhatsApp and stays connected
  2. Downloads message history from WhatsApp servers
  3. Receives new messages in real-time
  4. Stores everything in ./store/messages.db
  5. Runs until you press Ctrl+C

Tip: Run sync in a tmux or screen session, or as a background service, so it keeps receiving messages.

Step 3: Basic Operations

bash
# List your chats
whatsapp-cli chats list --limit 10

# Search for a contact
whatsapp-cli contacts search --query "John"

# Send a message
whatsapp-cli send --to 1234567890 --message "Hello from CLI!"

# Search messages
whatsapp-cli messages search --query "meeting"

Step 4: Check the Installed Version

bash
whatsapp-cli version

Example Output:

json
{
  "success": true,
  "data": {
    "version": "v1.1.0"
  },
  "error": null
}

Complete Command Reference

Global Options

All commands support these global flags:

Flag Type Default Description
--store string ./store Directory for session and message databases

Example:

bash
whatsapp-cli --store /var/lib/whatsapp chats list

Command: auth

Authenticate with WhatsApp via QR code.

Syntax:

bash
whatsapp-cli auth

Parameters: None

Returns:

json
{
  "success": true,
  "data": {
    "authenticated": boolean,
    "message": string
  },
  "error": null
}

Behavior:

  • If already authenticated: Returns success immediately
  • If not authenticated: Displays QR code and waits for scan
  • Timeout: 5 minutes
  • Creates store/whatsapp.db with session data

Example:

bash
whatsapp-cli auth
# Scan QR code with phone
# ✓ Successfully authenticated!

Command: sync

⚠️ IMPORTANT: Run this command to fill the message database. If you do not run sync, messages list and messages search return empty results.

Sync messages from WhatsApp to the local database continuously. This command:

  • Downloads message history from WhatsApp servers
  • Receives new messages in real time
  • Stores all messages in the SQLite database
  • Runs until you press Ctrl+C

Syntax:

bash
whatsapp-cli sync

Parameters: None

Returns: (on exit via Ctrl+C)

json
{
  "success": true,
  "data": {
    "synced": true,
    "messages_count": 1234
  },
  "error": null
}

Behavior:

  • Connects to WhatsApp (authenticates if needed)
  • Registers event handlers for incoming messages and history sync
  • Processes *events.Message for real-time messages
  • Processes *events.HistorySync for message history batches
  • Stores all messages in store/messages.db
  • Sends progress to stderr (does not affect JSON output)
  • Runs until interrupted (Ctrl+C)
  • Disconnects on exit

Progress Output (stderr):

 Starting WhatsApp sync...
✓ Connected to WhatsApp
 Listening for messages... (Press Ctrl+C to stop)
 Processing history sync (42 conversations)...
 Synced 1234 messages...
^C
✓ Sync completed. Total messages synced: 1234

Examples:

bash
# Basic sync - run in foreground
whatsapp-cli sync

# Run in background (recommended for continuous syncing)
whatsapp-cli sync > sync.json 2> sync.log &

# Run in tmux/screen session
tmux new -s whatsapp
whatsapp-cli sync
# Detach with Ctrl+B D

# Run with custom storage directory
whatsapp-cli --store /var/lib/whatsapp sync

# Stop sync gracefully
kill -INT 
# Or press Ctrl+C in foreground

Use Cases:

  1. Initial Setup: Run once to download all message history
  2. Continuous Sync: Run as background service to receive messages
  3. Periodic Sync: Run via cron to update messages on a schedule
  4. Development: Run in terminal while testing queries

Notes:

  • Message history sync can take time. The duration depends on the number of messages.
  • SQLite PRIMARY KEY constraints prevent duplicate messages.
  • The CLI does not download media files. It stores only metadata: type, filename, and URL.
  • The connection stays open until you interrupt it.
  • You can restart the sync safely. It does not create duplicate messages.

Command: messages list

List messages from all chats or a specific chat.

Syntax:

bash
whatsapp-cli messages list [OPTIONS]

Parameters:

Flag Type Required Default Description
--chat string No - Filter by chat JID (e.g., [email protected])
--limit int No 20 Maximum number of messages to return
--page int No 0 Page number for pagination (0-indexed)

Returns:

json
{
  "success": true,
  "data": [
    {
      "id": "msg_unique_id",
      "chat_jid": "[email protected]",
      "chat_name": "John Doe",
      "sender": "1234567890",
      "content": "Message text content",
      "timestamp": "2025-10-26T10:30:00Z",
      "is_from_me": false,
      "media_type": ""
    }
  ],
  "error": null
}

Examples:

bash
# List 50 most recent messages across all chats
whatsapp-cli messages list --limit 50

# List messages from specific chat
whatsapp-cli messages list --chat [email protected]

# Pagination: Get second page of results
whatsapp-cli messages list --limit 20 --page 1

# Get JID first, then list messages
JID=$(whatsapp-cli contacts search --query "Alice" | jq -r '.data[0].jid')
whatsapp-cli messages list --chat "$JID" --limit 100

Sorting: Messages returned in reverse chronological order (newest first)


Command: messages search

Search messages by content across all chats.

Syntax:

bash
whatsapp-cli messages search --query TEXT [OPTIONS]

Parameters:

Flag Type Required Default Description
--query string Yes - Search term (case-insensitive, partial match)
--limit int No 20 Maximum number of results
--page int No 0 Page number for pagination

Returns: Same format as messages list

Examples:

bash
# Search for messages containing "meeting"
whatsapp-cli messages search --query "meeting"

# Search with more results
whatsapp-cli messages search --query "project" --limit 100

# Case-insensitive search
whatsapp-cli messages search --query "URGENT"  # Finds "urgent", "Urgent", etc.

Search Behavior:

  • Case-insensitive
  • Partial word matching
  • Searches message content only (not sender names)
  • Returns messages from all chats

Command: contacts search

Search contacts by name or phone number.

Syntax:

bash
whatsapp-cli contacts search --query TEXT

Parameters:

Flag Type Required Default Description
--query string Yes - Search term for name or phone number

Returns:

json
{
  "success": true,
  "data": [
    {
      "phone_number": "1234567890",
      "name": "John Doe"

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goclaudeclaude-codecodexllm

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类AI 编程
定价开源

> 相关工具

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.