Skip to content
FunCoding

Zhihu

Listed in the official MCP Registry

Zhihu CLI for AI agents: search, read, download, and publish from the terminal.

Star
32
Version
v0.3.0
License
MIT
Last commit
Nov 28, 2026

🧢 zhihu-cli

The terminal is your new Zhihu HQ.

A feature-complete, automation-ready Zhihu CLI & Developer Toolkit.

browse · download · search · publish · analyze — all from the command line.

Python 3.10+ License: MIT GitHub Repo stars


zhihu-cli turns your terminal into a full-featured Zhihu client. Authenticate once, then browse, search, download, publish, and analyze — without ever opening a browser.

⚠️ This is an unofficial CLI for Zhihu. Use at your own risk. Not affiliated with Zhihu Inc.

👉 Looking for the DSH plugin? → dsh-plugin/


🚀 Quick Start

Requirement: Python 3.10 or newer. Check your version with python --version before installing.

# Install
pip install zhihu-toolkit

1. Authenticate

zhihu auth paste          # paste a cURL from browser DevTools
zhihu auth login          # scan a QR code with the Zhihu App
zhihu auth import         # import the session from a local browser (needs: pip install 'zhihu-toolkit[browser]')

2. Verify

zhihu auth status         # check login status and active profile

✨ What You Can Do

📖 Read & Browse

Browse Zhihu's feeds, hot lists, questions, articles, pins, and comments — all rendered in your terminal with a Rich-powered pager. Explore the real-time trending list with excerpts, scroll through your personalized recommend feed, or dive into a question and its full answer thread without clicking a single link. Zhihu Daily (知乎日报) has its own group: zhihu daily latest, zhihu daily before <date>, and zhihu daily story <id> --save.

💾 Download for Offline

Save any Zhihu content (articles, answers, questions, pins, videos, collections) as clean Markdown with YAML frontmatter. Download individual pieces or batch-process from a manifest. Everything lands in ~/.zhihu-cli/downloads/, organized by type, ready for your note-taking system or offline reading. Re-running a download is incremental by default: items whose file already exists and whose listing timestamp has not advanced are skipped, with state kept in .zhihu-download.json in the output directory. Use --force to re-download everything, --since YYYY-MM-DD to bound the listing walk for download user, and -j/--concurrency (default 4) to fetch items in parallel.

Search questions, articles, users, and topics across Zhihu. Fine-tune result depth and quantity — all from the command line.

✍️ Publish & Edit

Write answers and articles in Markdown, publish them to Zhihu with one command. Need to update? Modify existing answers and articles from your local files. Markdown-to-HTML conversion happens automatically via Zhihu's own rendering pipeline.

💬 Interact

Vote, thank, follow, block, and comment — full social interaction without the browser. Manage collections: create, populate, and organize them. Send and receive direct messages, and stream real-time notifications and chat via MQTT.

🕸️ Scrape & Export

Batch-export your creations, activity history, answers, and articles as structured JSON. Scrape exports are plain asset lists, so you can feed them straight into the download batch-* commands or your own data pipeline.

📊 Analyze

Creator analytics — pull your Zhihu income data and visualize it: monthly summaries, trend charts (with EMA), advanced indicators (Bollinger Bands, MACD), derivative analysis (velocity/acceleration/jerk), weekday breakdowns, and per-content daily metrics. Charts are saved as PNGs.

NLP tools — run word frequency analysis, generate word clouds, and perform K-means clustering on your downloaded content. All operate across your full Markdown library.

🔐 Multi-Account

Save multiple profiles from different accounts, switch between them with a single command. Each profile keeps its own auth credentials and cookies.


🏗️ Architecture

src/zhihu_cli/
├── main.py                  # Click CLI — command group hub
├── api.py                   # supported Python API (the downstream contract)
├── errors.py                # public exception hierarchy
├── output.py                # styled terminal output (Rich)
├── content/
│   ├── handlers/            # one file per Zhihu domain
│   └── utils/               # HTML↔Markdown, ZSE v4 signing
├── creator_tools/           # income analytics + plotting
└── nlp_tools/               # word count, wordcloud, clustering
LayerWhat It Does
🔐 AuthBrowser Cookie + User-Agent headers from cURL paste or QR code login, cached per-profile
✍️ SigningEvery Zhihu request gets auto-signed with x-zse-93 / x-zse-96 headers via ZSE v4 cipher
🌐 Requestscurl_cffi impersonates Chrome's TLS fingerprint to avoid detection
📄 ExtractionPrefers direct API calls; falls back to HTML page scraping with js-initialData parsing
📝 MarkdownHTML → LaTeX preprocessing → recursive traversal → clean Markdown. Reverse for publishing
🐍 Libraryzhihu_cli.api — lazy imports, normalized errors, per-thread profile pinning

🐍 Use as a Library

zhihu_cli.api is the supported Python surface. Everything under content/, commands/, and the other subpackages is internal and may move between releases.

from zhihu_cli import ZhihuError, fetch_hot_list, rate_limit, scrape_article, use_profile

with use_profile("alt"), rate_limit(2):
    for item in fetch_hot_list(limit=10):
        print(item["title"])

metadata, markdown = scrape_article("https://zhuanlan.zhihu.com/p/123456")

The library API is read-only: fetch, stream, scrape, comments, profiles, feeds, notifications, drafts, and collections. Publishing, interaction, media download, and the TUI stay CLI-only.

  • Calls block; stream_* returns a lazy iterable and issues its requests while you iterate.
  • Every failure raises a subclass of zhihu_cli.ZhihuError (AuthError, NotFoundError, RateLimitError, ZhihuHTTPError), with the original exception as __cause__.
  • use_profile(name) pins an account per thread without rewriting the global active profile; rate_limit(qps) restores the previous limit on exit.
  • The package ships py.typed; heavy dependencies load on first use, so import zhihu_cli stays cheap.

🧪 Extras

Optional Dependencies

pip install "zhihu-toolkit[nlp]"          # jieba, matplotlib, wordcloud, scikit-learn...
pip install "zhihu-toolkit[creator]"      # matplotlib, numpy, pandas, seaborn...
pip install "zhihu-toolkit[llm]"          # openai (zhihu agora ai, zhihu chat bot)
pip install "zhihu-toolkit[notify]"       # desktop-notifier (zhihu chat interactive --notify)
pip install "zhihu-toolkit[browser]"      # browser-cookie3 (zhihu auth import)
pip install "zhihu-toolkit[mcp]"          # click2mcp (the zhihu-mcp server entry point)

Shell Completions

Click ships completion for each shell — add the matching line to your rc file:

# bash
eval "$(_ZHIHU_COMPLETE=bash_source zhihu)"
# zsh
eval "$(_ZHIHU_COMPLETE=zsh_source zhihu)"
# fish
_ZHIHU_COMPLETE=fish_source zhihu | source

From a repository clone, python autocomp.py detects your shell and prints the right line.


🤝 Contributing

PRs welcome! The codebase is organized by layer:

  • New command? Add a file to commands/ with a register_<name>(group) function, import it in main.py.
  • New handler? Add a file to content/handlers/ — follow the existing patterns.
  • New library function? Add a wrapper to api.py and its name to __all__; the API tests fail if the handler it names is missing.

Run the formatter before submitting:

pre-commit run --all-files
ruff check .
ruff format .

📜 License

MIT


Made with ❤️ and way too many terminal sessions.

Report a bug · Fork this repository · Star ⭐ this repo!

Similar MCP servers

Featured

Douyin_TikTok_Download_API

Download watermark-free videos, fetch posts, authors, comments. Self-hosted, no signup or quota.

EVEvil0ctal/Douyin_TikTok_Download_API22k124 new stars in the last 7 days

Featured

xiaohongshu-mcp

Sign in to Xiaohongshu and publish image or video posts.

XPxpzouying/xiaohongshu-mcp17k105 new stars in the last 7 days

Featured

12306-mcp

Search 12306 train tickets, with train filters, stopover and transfer queries.

JOJoooook/12306-mcp2.5k9 new stars in the last 7 days

Featured

wenyan-mcp

Format Markdown articles and publish them to WeChat Official Accounts.

CAcaol64/wenyan-mcp1.4k4 new stars in the last 7 days

chubbyskills

把中文全渠道内容(抖音 / B站 / 小红书 / 公众号 / X / 播客)采集进个人知识库的 14 个 AI Skill:图文存图、视频转文字稿、字幕优先免 GPU、RSS/YouTube 订阅调度与每日情报简报,附带知识库 MCP server。| Ingest Chinese content into your personal knowledge base — image/video routing, subtitle-first transcription, feed subscriptions with daily digests, and a KB MCP server.

CHchubbyguan/chubbyskills1.4k11 new stars in the last 7 days

CloudBase

CloudBase MCP: DB, functions, storage, hosting via @cloudbase/cloudbase-mcp

TETencentCloudBase/CloudBase-AI-Toolkit1.2k3 new stars in the last 7 days