How to Configure YouTube Cookies for Age-Restricted and Member-Only Videos in Agent-Reach

Agent-Reach passes authentication cookies to yt-dlp to bypass YouTube's age restrictions and membership checks, requiring only a browser cookie export and CLI configuration.

Agent-Reach is an open-source content extraction tool that leverages yt-dlp as its backend for YouTube processing. When accessing age-restricted videos or member-only content, standard anonymous requests fail with authentication errors. By configuring YouTube cookies in Agent-Reach, you authorize the tool to present valid session tokens and unlock access to protected videos.

Agent-Reach delegates all YouTube processing to yt-dlp, which supports cookie-based authentication via the --cookies command-line option. When you execute agent-reach configure youtube-cookies, the CLI persists your cookie string to ~/.agent-reach/config.yaml under the youtube_cookies_from key. During video extraction, Agent-Reach retrieves these cookies from [agent_reach/cli.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) and automatically passes them to yt-dlp, allowing the backend to present valid authentication tokens to YouTube's servers.

Exporting Cookies from Your Browser

You must extract active session cookies from a browser where you are logged into YouTube:

  1. Install the Cookie-Editor extension for Chrome, Firefox, or Edge.
  2. Navigate to https://www.youtube.com and sign in to your Google account.
  3. Click the Cookie-Editor toolbar icon, select Export, then choose Header String.
  4. Copy the resulting text, which resembles Cookie: SID=ABC123; HSID=XYZ789; SSID=DEF456....

Important: When configuring Agent-Reach, omit the leading Cookie: prefix and copy only the key-value pairs (e.g., SID=ABC123; HSID=XYZ789).

Configuring Agent-Reach with YouTube Cookies

Store the exported string using the configuration command:

agent-reach configure youtube-cookies "SID=ABC123; HSID=XYZ789; SSID=DEF456..."

This updates your ~/.agent-reach/config.yaml with the authentication tokens. The implementation in [agent_reach/cli.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) handles the secure storage and validation of these credentials.

Installing the JavaScript Runtime

YouTube's age-verification system requires JavaScript execution to process security challenges. The check is implemented in [agent_reach/channels/youtube.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/youtube.py).

You need to install one of the following:

  • Node.js (requires explicit configuration in the yt-dlp setup)
  • Deno (works out-of-the-box without additional configuration)

After installing your chosen runtime, execute:

agent-reach install

This invokes helpers from [agent_reach/utils/paths.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/utils/paths.py) to append the necessary --js-runtimes flags to the underlying yt-dlp configuration, ensuring age-gate bypasses function correctly.

Verifying Your Configuration

Run the built-in diagnostic tool to confirm your setup:

python -m agent_reach.cli doctor

A successful configuration shows youtube as "ok" with a message indicating the system "可提取视频信息和字幕" (can extract video information and subtitles). Ensure no warnings appear regarding missing JavaScript runtimes or cookie authentication before proceeding.

Accessing Age-Restricted and Member-Only Videos

With cookies stored and the JS runtime available, you can now process protected content:


# Fetch metadata from an age-restricted video

agent-reach read https://www.youtube.com/watch?v=AGE_RESTRICTED_ID

# Generate transcripts from member-only content

agent-reach transcribe https://www.youtube.com/watch?v=MEMBER_ONLY_ID

Agent-Reach automatically supplies the stored cookies to yt-dlp via the --cookies option when calling the backend, circumventing YouTube's authentication gates for both age-restricted and membership-protected videos.

Summary

  • Authentication Requirement: Age-restricted and member-only videos require valid YouTube session cookies to bypass access controls.
  • Cookie Export: Use Cookie-Editor to copy the Header String from an authenticated YouTube session.
  • CLI Configuration: Run agent-reach configure youtube-cookies <string> to store credentials in ~/.agent-reach/config.yaml.
  • Runtime Setup: Install Node.js or Deno, then execute agent-reach install to enable JavaScript execution for age verification.
  • Validation: Confirm functionality with python -m agent_reach.cli doctor before processing protected URLs.

Frequently Asked Questions

Why do I need cookies for YouTube videos in Agent-Reach?

YouTube restricts age-restricted and member-only content to authenticated users. Without cookies, yt-dlp cannot verify your account age or membership status, causing Agent-Reach to fail when fetching metadata, subtitles, or transcripts from protected videos.

The CLI saves the cookie string under the youtube_cookies_from key in ~/.agent-reach/config.yaml. According to [agent_reach/channels/youtube.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/youtube.py), this value is read at runtime and passed to yt-dlp to authenticate requests.

What if the doctor command shows JavaScript runtime warnings?

You must install either Node.js or Deno and run agent-reach install to update the yt-dlp configuration. The warning indicates that the channel implementation cannot locate a valid JS runtime required for processing YouTube's age-verification challenges.

Can I use cookies from any browser?

Yes, provided you export them in the correct format. The Header String output from Cookie-Editor works across Chrome, Firefox, and Edge. Ensure you remove the Cookie: label from the exported text and that you maintain an active login session when copying the values.

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 →