How to Manually Configure Twitter Cookies in Agent Reach: Supported Formats and Step-by-Step Guide
To configure Twitter cookies in Agent Reach, export your auth_token and ct0 cookies from the browser, then run agent-reach configure twitter-cookies "auth_token=xxx; ct0=yyy" — the tool accepts both semicolon-separated header strings and space-separated token pairs.
Manually configuring Twitter cookies is essential when using Agent Reach to interact with X (formerly Twitter) through its upstream twitter-cli integration. This guide covers the exact cookie formats accepted by Agent Reach, the complete configuration workflow, and the underlying source code implementation in the Panniantong/Agent-Reach repository.
Required Twitter Cookies for Authentication
Agent Reach relies on two browser session cookies to authenticate with Twitter:
| Cookie | Purpose |
|---|---|
auth_token |
Primary authentication token for the Twitter session |
ct0 |
CSRF token required for API requests |
These cookies are extracted and stored as twitter_auth_token and twitter_ct0 in Agent Reach's local configuration, as defined in agent_reach/config.py at lines 107–108.
Exporting Cookies from Your Browser
The recommended method uses the Cookie-Editor extension available for Chrome and Edge.
-
Install Cookie-Editor from the Chrome Web Store or Edge Add-ons store.
-
Navigate to
https://x.com(orhttps://twitter.com) and log into your account. -
Click the Cookie-Editor extension icon, then select Export → Header String.
-
Copy the resulting string — it will resemble:
auth_token=xxxxxxxxxxxx; ct0=yyyyyyyyyyyy; other_cookie=zzz…
Detailed visual instructions are documented in docs/cookie-export.md at lines 21–27.
Configuring Cookies in Agent Reach
Basic Configuration Command
Pass the exported cookie string directly to the configure command:
agent-reach configure twitter-cookies "auth_token=ABC123; ct0=DEF456; guest_id=v1%3A1690000000"
The parser in agent_reach/cli.py (_parse_twitter_cookie_input at lines 1248–1365) extracts only the auth_token and ct0 values, ignoring extraneous cookies.
Verifying the Configuration
Check that both values were stored correctly:
agent-reach doctor | grep -E "twitter_auth_token|twitter_ct0"
Note: The doctor command verifies the configuration keys exist but does not execute an actual twitter status call to test live connectivity.
Accepted Cookie Input Formats
The _parse_twitter_cookie_input function in agent_reach/cli.py accepts two representations:
| Format | Example | Parser Behavior |
|---|---|---|
| Semicolon-separated header string | auth_token=xxx; ct0=yyy; … |
Extracts auth_token= and ct0= key-value pairs anywhere in the string |
| Space-separated tokens | xxx yyy |
Treats first token as auth_token, second as ct0 |
Both formats ignore additional data — extra cookies in a header string or additional tokens in space-separated input are discarded.
Running Twitter Commands
Using Agent Reach's Wrapper (Recommended)
When you run Twitter commands through Agent Reach, environment variables are automatically injected:
agent-reach run twitter search "agent reach" -n 3
The channel implementation in agent_reach/channels/twitter.py (lines 23–31) reads the stored configuration and sets TWITTER_AUTH_TOKEN and TWITTER_CT0 for the subprocess.
Using twitter-cli Directly
For direct twitter invocations, export the variables manually:
TWITTER_AUTH_TOKEN=ABC123 TWITTER_CT0=DEF456 twitter search "open-source AI" -n 5
Legacy Environment Sync
Add --sync-legacy-twitter during configuration to additionally write the cookies to the legacy twitter-cli environment:
agent-reach configure twitter-cookies "$COOKIE_STRING" --sync-legacy-twitter
This enables plain twitter … calls without manual environment variable management.
Complete Configuration Example
# 1. Export cookies with Cookie-Editor and copy the header string
COOKIE_STRING="auth_token=ABC123; ct0=DEF456; guest_id=v1%3A1690000000"
# 2. Store in Agent Reach configuration
agent-reach configure twitter-cookies "$COOKIE_STRING"
# 3. Verify configuration
agent-reach doctor | grep -E "twitter_auth_token|twitter_ct0"
# 4. Execute Twitter search through Agent Reach
agent-reach run twitter search "agent reach" -n 3
# 5. Or call twitter-cli directly with manual exports
TWITTER_AUTH_TOKEN=ABC123 TWITTER_CT0=DEF456 twitter search "agent reach" -n 3
Key Source Files
| File | Lines | Purpose |
|---|---|---|
agent_reach/cli.py |
1248–1365 | Cookie parsing logic (_parse_twitter_cookie_input) |
agent_reach/config.py |
107–108 | Configuration key definitions (twitter_auth_token, twitter_ct0) |
agent_reach/channels/twitter.py |
23–31 | Environment variable injection for Twitter subprocesses |
docs/install.md |
149–157 | User-facing configure twitter-cookies documentation |
docs/cookie-export.md |
21–27 | Cookie-Editor export instructions |
Summary
- Two cookies required:
auth_tokenandct0exported from an active X/Twitter browser session. - Two input formats accepted: semicolon-separated header strings or space-separated token pairs.
- Configure with:
agent-reach configure twitter-cookies "auth_token=xxx; ct0=yyy". - Verify with:
agent-reach doctorto confirm keys are stored. - Execute via:
agent-reach run twitter …for automatic environment setup, or manualTWITTER_AUTH_TOKEN=xxx TWITTER_CT0=yyy twitter …for direct CLI usage. - Implementation: Parsing logic resides in
agent_reach/cli.pywith configuration management inagent_reach/config.py.
Frequently Asked Questions
What happens if my cookie string contains extra cookies?
Agent Reach's parser ignores any additional cookies. Only auth_token and ct0 values are extracted and stored; all other key-value pairs in a header string are discarded without error.
Can I configure Twitter cookies without the Cookie-Editor extension?
Yes. Any method that obtains the raw auth_token and ct0 values works. You can manually construct a space-separated string ("token_value ct0_value") or semicolon-separated format — both are accepted by the parser in agent_reach/cli.py.
Why does agent-reach doctor not test actual Twitter connectivity?
The doctor command only validates that configuration keys exist in the local config file. It does not invoke twitter status or make live API calls to avoid rate limiting and unnecessary authentication attempts during routine diagnostics.
How do I update cookies after they expire?
Re-export fresh cookies from your browser and rerun agent-reach configure twitter-cookies "new_auth_token=xxx; new_ct0=yyy". The configuration command overwrites existing values, so no manual deletion is required.
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 →