How to Auto-Extract Cookies from Chrome/Firefox for Agent Reach Platform Authentication
Agent Reach reads authentication cookies directly from your local Chrome, Firefox, Edge, Brave, or Opera browsers and automatically persists them to ~/.agent-reach/config.yaml using the configure --from-browser CLI command.
Agent Reach eliminates manual cookie copying by interfacing directly with your browser's local storage. The Panniantong/Agent-Reach repository implements a secure, local-only extraction pipeline that maps browser cookies to platform-specific authentication requirements. This guide explains how the cookie extraction system works and how to use it for instant authentication across Twitter/X, XiaoHongShu, Bilibili, and Xueqiu.
How Cookie Extraction Works in Agent Reach
The extraction pipeline is implemented in agent_reach/cookie_extract.py and operates entirely offline to ensure your credentials never leave the machine.
Dual Library Architecture with Automatic Fallback
The module attempts to use the fast Rust-based rookiepy library first, falling back to browser_cookie3 if unavailable. This logic appears in the import section of agent_reach/cookie_extract.py:
# Lines 55-68 in cookie_extract.py
try:
import rookiepy
HAS_ROOKIE = True
except ImportError:
HAS_ROOKIE = False
try:
import browser_cookie3
HAS_BROWSER_COOKIE3 = True
except ImportError:
HAS_BROWSER_COOKIE3 = False
Platform-Specific Cookie Mapping
The PLATFORM_SPECS static table (lines 15-40) defines which cookies each platform requires. For example, Twitter/X needs auth_token and ct0, while Bilibili requires SESSDATA and bili_jct. The system filters raw browser cookies against these specifications, returning a unified dictionary structure.
The Extraction Process
When extract_all(browser) is called, it reads the browser's cookie store, wraps entries in a lightweight _Cookie object to normalize differences between rookiepy and browser_cookie3, and returns a dictionary like:
{
"twitter": {"auth_token": "...", "ct0": "..."},
"xhs": {"cookie_string": "a=1; b=2; …"},
"bilibili": {"SESSDATA": "...", "bili_jct": "..."},
"xueqiu": {"cookie_string": "..."} # only if xq_a_token present
}
Auto-Extracting Cookies via CLI
The configure sub-command in agent_reach/cli.py (lines 279-287) provides the --from-browser flag to automate credential setup.
Extract from Chrome
Run the following to extract and store cookies for all supported platforms from Chrome:
agent-reach configure --from-browser chrome
Sample output:
✅ Cookies configured! Run `agent-reach doctor` to see updated status.
Twitter/X ✔ auth_token + ct0
XiaoHongShu ✔ 5 cookies
Bilibili ✔ SESSDATA + bili_jct
Xueqiu ✔ 7 cookies (含 xq_a_token)
Extract from Firefox
For Firefox users, simply change the browser argument:
agent-reach configure --from-browser firefox
Verification
After extraction, verify the configuration with:
agent-reach doctor
This checks that channel modules like agent_reach/channels/twitter.py and xiaohongshu.py recognize the stored credentials.
Programmatic Cookie Extraction
You can also integrate cookie extraction into Python scripts using the public API.
Using extract_all()
Import extract_all to retrieve cookies without persisting them to config:
from agent_reach.cookie_extract import extract_all
# Grab cookies from Chrome (default)
cookies = extract_all() # or extract_all("chrome")
# Access specific platform credentials
twitter_auth = cookies.get("twitter", {})
auth_token = twitter_auth.get("auth_token")
ct0 = twitter_auth.get("ct0")
print("Twitter auth token:", auth_token)
Using configure_from_browser()
To replicate the CLI behavior programmatically, use configure_from_browser which handles persistence to ~/.agent-reach/config.yaml:
from agent_reach.cookie_extract import configure_from_browser
from agent_reach.config import Config
cfg = Config()
results = configure_from_browser("chrome", cfg)
for platform, ok, msg in results:
print(f"{platform}: {'✅' if ok else '❌'} – {msg}")
Summary
- Local-only processing: The extraction pipeline in
agent_reach/cookie_extract.pyreads browser databases directly without network requests. - Dual library support: Automatically uses
rookiepy(Rust) when available, falling back tobrowser_cookie3. - CLI convenience: The
agent-reach configure --from-browser <browser>command automates extraction and storage. - Unified interface: The
_Cookiewrapper normalizes differences between extraction libraries. - Platform specs:
PLATFORM_SPECSmaps browser cookies to specific platform requirements (e.g.,auth_tokenfor Twitter).
Frequently Asked Questions
Is it safe to extract cookies from my browser using Agent Reach?
Yes. According to the source code in agent_reach/cookie_extract.py, the extraction process is completely local—no network requests are performed while reading the browser's cookie database. Your authentication secrets remain on your machine and are only written to the local configuration file at ~/.agent-reach/config.yaml.
Which browsers are supported for cookie auto-extraction?
Agent Reach supports Chrome, Firefox, Edge, Brave, and Opera. The underlying rookiepy and browser_cookie3 libraries handle the specific database formats for each browser, while Agent Reach's abstraction layer provides a consistent interface regardless of the browser choice.
What happens if rookiepy is not installed on my system?
The code implements an automatic fallback mechanism. If rookiepy (the fast Rust-based library) is unavailable, agent_reach/cookie_extract.py catches the ImportError and falls back to browser_cookie3. This ensures cookie extraction works on any system with at least one of the supported libraries installed.
How do I verify that the cookies were extracted and saved correctly?
Run agent-reach doctor after the extraction process. This command checks that the credentials stored in ~/.agent-reach/config.yaml are valid and recognized by the respective channel implementations (e.g., agent_reach/channels/twitter.py for Twitter/X). The CLI output will indicate which platforms are properly authenticated.
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 →