How to Use OpenCLI as a Backend to Share Browser Sessions Across XiaoHongShu and Reddit

OpenCLI acts as a shared backend that controls a single Chrome instance, allowing the XiaoHongShu and Reddit channels in Agent-Reach to automatically reuse your logged-in browser sessions without managing separate cookies or API keys.

OpenCLI (@jackwener/opencli) provides a unified browser automation layer for the Agent-Reach framework, enabling zero-configuration session sharing across multiple social platforms. By running a local daemon that controls a real Chrome process, OpenCLI allows both XiaoHongShu and Reddit channels to piggyback on your existing browser authentication. This eliminates the need to extract cookies or manage authentication tokens separately for each platform.

How OpenCLI Enables Cross-Platform Session Sharing

OpenCLI operates as a local daemon that interfaces with a genuine Chrome instance. Because it drives the same browser process, any active login session in Chrome—whether for XiaoHongShu or Reddit—is automatically available to all OpenCLI commands.

The system probes availability through agent_reach/backends/opencli.py. The opencli_status() function (lines 59-115) checks three critical states:

  • Binary existence: Verifies the opencli command is installed
  • Daemon status: Confirms the background service is running
  • Extension state: Validates the Chrome extension is either connected or installed locally

When opencli_status() reports daemon_running=True and either extension_connected=True or extension_installed=True, the backend is marked as ready. Channels then route all read and search operations through this single Chrome instance, which automatically injects the browser's existing cookies into each request.

Channel Integration Architecture

Both the XiaoHongShu and Reddit channels implement a _check_opencli() method that queries the shared status function.

In agent_reach/channels/xiaohongshu.py (lines 97-112), the channel suggests running opencli xiaohongshu commands when the backend is available. Similarly, agent_reach/channels/reddit.py (lines 90-94) recommends opencli reddit commands.

When the status reports status == "ok", the channel declares the backend usable. The AgentReach core in agent_reach/core.py then dispatches all subsequent requests to the OpenCLI executable, which leverages Chrome's shared cookie store.

Installation and Verification

Install OpenCLI globally via npm, then verify the daemon status using the Agent-Reach library:


# Install the OpenCLI node package

npm install -g @jackwener/opencli

# Verify daemon and extension status

python -c "from agent_reach.backends import opencli_status; print(opencli_status())"

The output should contain installed=True, daemon_running=True, and either extension_connected=True or extension_installed=True. If the extension is merely installed but not actively connected, OpenCLI wakes it on the first command, making the session instantly shareable after the initial call.

Practical Usage Examples

Command Line Interface

Query both platforms directly through OpenCLI, which automatically reuses your logged-in Chrome sessions:


# Search XiaoHongShu notes using the shared browser session

opencli xiaohongshu search "travel tips" -f yaml

# Search Reddit posts using the same Chrome instance

opencli reddit search "open source AI" -f yaml

Python Library Integration

Use the AgentReach client to automatically select the OpenCLI backend when available:

from agent_reach.core import AgentReach

# Initialize client (defaults to OpenCLI preference)

client = AgentReach()

# Read a Reddit post (routes through OpenCLI if daemon is ready)

post = client.read("https://www.reddit.com/r/python/comments/xyz123/example_post")
print(post)

# Search XiaoHongShu (shares the same Chrome cookies)

notes = client.search("xiaohongshu", "AI art")
print(notes)

The AgentReach core automatically selects the first ready backend reported by each channel. Because opencli_status() reports "ready" when the daemon is active, these calls hit the OpenCLI daemon and share the same browser authentication context.

Fallback Mechanisms

If OpenCLI is not installed or the Chrome extension is missing, channels automatically degrade to secondary backends:

  • XiaoHongShu falls back to xiaohongshu-mcp or xhs-cli
  • Reddit falls back to rdt-cli

This logic resides in the check() methods of each channel (XiaoHongShuChannel.check at lines 60-95 and RedditChannel.check at lines 47-75), ensuring robust operation even without OpenCLI configured.

Summary

  • OpenCLI runs a local daemon that controls a real Chrome instance, enabling automatic reuse of existing browser logins.
  • The opencli_status() function in agent_reach/backends/opencli.py validates daemon health and extension connectivity before enabling the backend.
  • Both XiaoHongShu and Reddit channels probe OpenCLI availability through _check_opencli(), routing requests to opencli xiaohongshu or opencli reddit commands when ready.
  • Sessions are shared instantly across platforms because OpenCLI injects Chrome's native cookies into every request.
  • Fallback logic automatically switches to alternative backends (xiaohongshu-mcp, xhs-cli, or rdt-cli) if OpenCLI is unavailable.

Frequently Asked Questions

Do I need to manually export cookies from Chrome to use OpenCLI?

No. OpenCLI controls the Chrome process directly and automatically accesses the browser's internal cookie store. When you are logged into XiaoHongShu or Reddit in Chrome, those sessions are immediately available to OpenCLI commands without manual extraction or configuration files.

What happens if the OpenCLI extension is installed but not currently connected?

If the extension is installed but sleeping, OpenCLI wakes it automatically upon the first command execution. The opencli_status() check considers an installed extension as valid (extension_installed=True), and the daemon handles the activation handshake on demand, making the session shareable immediately after the first API call.

Can I use OpenCLI with other platforms besides XiaoHongShu and Reddit?

Yes. OpenCLI supports multiple channels including Twitter and YouTube. Any channel that implements the _check_opencli() probe pattern can leverage the shared Chrome session, providing zero-config authentication across all supported platforms simultaneously.

How does the AgentReach core decide which backend to use?

The AgentReach class in agent_reach/core.py queries each channel's check() method, which internally calls opencli_status(). If the status returns daemon_running=True with a valid extension state, the channel marks OpenCLI as the active backend. The core then dispatches read and search operations to the first ready backend in the preference order, typically prioritizing OpenCLI over CLI 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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →