How to Use OpenCLI as a Cross-Platform Backend for Twitter, Reddit, and XiaoHongShu
OpenCLI leverages your existing Chrome login session to provide a unified, authentication-free backend for Twitter/X, Reddit, and XiaoHongShu, with Agent Reach automatically probing the daemon and extension status via opencli_status to prioritize it over other channel backends.
Agent Reach (Panniantong/Agent-Reach) treats OpenCLI (@jackwener/opencli) as a desktop-only backend that reuses your existing Chrome cookies, eliminating per-platform credential configuration. The repository implements a sophisticated probing system across three channel implementations to detect OpenCLI availability and health before executing queries.
How Agent Reach Probes OpenCLI Status
The opencli_status function in agent_reach/backends/opencli.py performs non-destructive detection of the OpenCLI installation, daemon state, and Chrome extension connectivity.
The Detection Pipeline
The probing mechanism executes in three stages. First, it runs opencli --version to verify the binary exists via the probe_command helper. Second, it executes opencli daemon status and parses the output for Daemon: … and Extension: … status lines. Third, if the extension reports as disconnected, a secondary disk check (_extension_installed_on_disk) searches typical Chrome profile roots:
- macOS:
~/Library/Application Support/Google/Chrome - Linux:
~/.config/google-chrome - Windows:
%LOCALAPPDATA%
The OpenCLIStatus Dataclass
The probe returns an OpenCLIStatus dataclass (lines 80-104) containing fields for installed, broken, daemon_running, extension_connected, extension_installed, version, and hint. This structured result enables channel-level logic to determine whether OpenCLI is ready for operations or requires user intervention.
Channel-Level OpenCLI Integration
Each platform channel implements a private _check_opencli() method that interprets the OpenCLIStatus and returns standardized tuples for the public check() method.
Twitter/X Channel Implementation
In agent_reach/channels/twitter.py (lines 94-108), the _check_opencli() method:
- Imports and calls
opencli_status()fromagent_reach.backends - Returns
Noneif OpenCLI is not installed, allowing fallback totwitter-clior legacy backends - Returns
("error", hint)if the binary exists but reports a broken state - Returns
("ok", message)whenstatus.readyis true (extension connected or sleeping) - Returns
("warn", hint)when installed but the extension is disconnected, prompting the user to start Chrome
Reddit and XiaoHongShu Implementations
The identical pattern appears in agent_reach/channels/reddit.py (lines 80-95) and agent_reach/channels/xiaohongshu.py (lines 97-112). Each probes OpenCLI before falling back to platform-specific alternatives like reddit-cli or manual cookie-based authentication.
Backend Priority Logic
The public check() method in each channel iterates over ordered_backends(), where OpenCLI appears first in the list (e.g., ["OpenCLI", "twitter-cli", "bird CLI (legacy)"] for Twitter). The selection algorithm prioritizes the first backend returning ("ok", ...), then falls back to the first ("warn", ...), ensuring OpenCLI wins over installed-but-unauthenticated alternatives.
Installation and Setup Workflow
The CLI entry point in agent_reach/cli.py provides automated installation guidance through _install_opencli_deps() (lines 742-754).
Installing OpenCLI Dependencies
Running python -m agent_reach.cli install --channels opencli triggers the following workflow:
# Install the OpenCLI npm package globally
npm install -g @jackwener/opencli
# Install the Chrome extension from the Web Store
open https://chromewebstore.google.com/detail/opencli/ildkmabpimmkaediidaifkhjpohdnifk
Verifying Daemon and Extension Status
After installation, verify the stack is operational:
# Check daemon and extension status
opencli daemon status
# Auto-start daemon and wake extension if needed
opencli doctor
The opencli_status probe interprets "Extension: connected" or sleeping-but-installed states as ready for use, while disconnected extensions trigger the hint field to guide users through Chrome extension activation.
Cross-Platform Query Patterns
OpenCLI executes requests inside your logged-in Chrome instance, requiring no additional authentication configuration. Each platform follows a consistent YAML-formatted output pattern.
Twitter/X Search Commands
Query tweets, articles, or user timelines:
# Search tweets
opencli twitter search "OpenAI GPT-4" -f yaml
# Fetch user posts
opencli twitter user-posts jack -f yaml
# Read specific article
opencli twitter article <url> -f yaml
Reddit Search Commands
Perform subreddit searches and hot listing fetches:
# Search posts
opencli reddit search "machine learning" -f yaml
# Fetch hot posts from a subreddit
opencli reddit subreddit python hot -f yaml
# Read specific post
opencli reddit read <post_id> -f yaml
XiaoHongShu Search Commands
Search notes and fetch user feeds:
# Search notes (Chinese keywords supported)
opencli xiaohongshu search "旅行" -f yaml
# Fetch note comments
opencli xiaohongshu comments <note_id> -f yaml
# Get user feed
opencli xiaohongshu feed <user_id> -f yaml
Summary
- OpenCLI provides a unified backend for Twitter/X, Reddit, and XiaoHongShu by executing queries within your existing Chrome session.
- The
opencli_statusfunction inagent_reach/backends/opencli.pyprobes installation, daemon state, and extension connectivity without side effects. - Each channel's
_check_opencli()method (intwitter.py,reddit.py, andxiaohongshu.py) standardizes OpenCLI detection and returnsok,warn,error, orNonestatuses. - OpenCLI appears first in
ordered_backends(), giving it priority over other authentication methods when the Chrome extension is installed. - All platforms use consistent YAML-formatted output via the
-f yamlflag, enabling predictable parsing across Twitter searches, Reddit subreddits, and XiaoHongShu notes.
Frequently Asked Questions
How does OpenCLI authenticate with Twitter, Reddit, and XiaoHongShu without API keys?
OpenCLI operates as a Chrome extension that executes commands inside your existing browser session. Because it reuses your logged-in Chrome cookies and session storage, it requires no API keys, OAuth tokens, or manual credential entry. The extension simply automates the browser you already use for these platforms.
What should I do if Agent Reach reports OpenCLI as installed but the extension is disconnected?
Run opencli doctor in your terminal to auto-start the daemon and wake the extension. If the issue persists, manually open Chrome and ensure the OpenCLI extension icon shows as connected. The _check_opencli() method in each channel returns a ("warn", hint) tuple specifically for this scenario, guiding you to activate the extension before queries will succeed.
Can I use OpenCLI on headless servers or CI/CD environments?
No. According to the source code in agent_reach/backends/opencli.py, OpenCLI is designed as a desktop-only backend that requires a local Chrome installation with the extension loaded. The probe checks for Chrome profile directories on macOS, Linux, and Windows, making it unsuitable for headless environments without a graphical browser session.
How does Agent Reach choose between OpenCLI and other backends like twitter-cli?
The check() method in each channel file iterates through ordered_backends() and selects the first candidate returning an ("ok", ...) status. Because OpenCLI appears first in the list, it wins whenever the binary is present and the extension is either connected or installed (even if sleeping). Only if OpenCLI returns None (not installed) or ("error", ...) does Agent Reach fall back to twitter-cli or other alternatives.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →