# How to Configure YouTube Cookies in Agent Reach for Age-Restricted Videos

> Easily configure YouTube cookies in Agent Reach for age-restricted videos. Use agent-reach configure youtube-cookies to authenticate and access content seamlessly.

- Repository: [Pnant/Agent-Reach](https://github.com/Panniantong/Agent-Reach)
- Tags: how-to-guide
- Published: 2026-07-02

---

**To access age-restricted or member-only YouTube videos in Agent Reach, run `agent-reach configure youtube-cookies <browser|filepath>` to store your authentication credentials, which the tool then passes to yt-dlp via `--cookies-from-browser` or `--cookies`.**

Agent Reach relies on **yt-dlp** to extract metadata and subtitles from YouTube URLs. When videos are gated behind age restrictions or membership requirements, you must configure YouTube cookies in Agent Reach to authenticate requests. This guide explains the exact CLI commands and source code implementation that enable seamless access to restricted content.

## Why Cookies Are Required for Age-Restricted Videos

YouTube serves age-restricted and member-only content only to authenticated users. Without valid session cookies, yt-dlp encounters access barriers and cannot retrieve video metadata or transcripts. By configuring YouTube cookies in Agent Reach, you provide yt-dlp with the necessary authentication tokens to bypass these restrictions while keeping your credentials local and secure.

## Step-by-Step Configuration Guide

Agent Reach exposes a dedicated CLI command that writes your cookie source to the configuration file at `~/.agent-reach/config.yaml`.

### Configure Cookies from a Browser

The most common method uses cookies from a browser where you are already logged into YouTube. Supported browsers include `chrome`, `firefox`, `edge`, `brave`, and `opera`.

```bash
agent-reach configure youtube-cookies chrome

```

This command stores `chrome` under the `youtube_cookies_from` key in your configuration file. When the agent executes yt-dlp, it automatically appends `--cookies-from-browser chrome` to the command.

### Configure Cookies from a File

If you prefer exporting cookies manually, use a browser extension like Cookie-Editor to save your YouTube cookies to a text file, then reference that path:

```bash
agent-reach configure youtube-cookies ~/my_youtube_cookies.txt

```

The configuration file now contains:

```yaml
youtube_cookies_from: /home/user/my_youtube_cookies.txt

```

Agent Reach detects the file path and passes `--cookies /home/user/my_youtube_cookies.txt` to yt-dlp instead of the browser flag.

## How Agent Reach Implements Cookie Handling

The cookie configuration flows through several key modules in the Agent Reach codebase.

**CLI Command Processing**

In [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) (line 1108), the `configure` subcommand handles the `youtube-cookies` argument by persisting the value via `config.set("youtube_cookies_from", value)`:

```python

# From agent_reach/cli.py

config.set("youtube_cookies_from", value)

```

**Configuration Persistence**

The [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) module (lines 79-84) provides the `set()` and `get()` methods that read and write to `~/.agent-reach/config.yaml`. This ensures your cookie source persists across agent sessions.

**YouTube Channel Integration**

When processing YouTube URLs, [`agent_reach/channels/youtube.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/youtube.py) (lines 23-46) contains the `check()` method that validates yt-dlp availability and prepares the environment. The channel implementation reads the `youtube_cookies_from` configuration and constructs the appropriate yt-dlp command flags.

**Runtime Path Utilities**

The [`agent_reach/utils/paths.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/utils/paths.py) module (lines 29-45) includes `render_ytdlp_fix_command()`, which generates fix commands for Node.js runtime configuration—critical for yt-dlp's JavaScript execution on YouTube pages.

## Verification and Troubleshooting

Always verify your configuration before attempting to process restricted videos.

### Verify Configuration with Doctor Command

Run the built-in diagnostic tool:

```bash
agent-reach doctor

```

You should see confirmation similar to:

```

✅ YouTube cookie source configured: chrome

```

### Ensure JavaScript Runtime Availability

yt-dlp requires **Node.js** or **Deno** to execute JavaScript on YouTube pages. The `check()` method in [`agent_reach/channels/youtube.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/youtube.py) warns you if a JS runtime is missing. If you encounter runtime errors, execute the command suggested by `render_ytdlp_fix_command()` in [`agent_reach/utils/paths.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/utils/paths.py), or run:

```bash
agent-reach install

```

### Verify Cookie Authentication

Test your setup by requesting an age-restricted video:

```bash
agent-reach read https://youtube.com/watch?v=EXAMPLE_ID

```

If configured correctly, the agent builds and executes a yt-dlp command similar to:

```bash
yt-dlp --dump-json --cookies-from-browser chrome "https://youtube.com/watch?v=EXAMPLE_ID"

```

For file-based cookies, the command uses `--cookies` instead:

```bash
yt-dlp --dump-json --cookies ~/my_youtube_cookies.txt "https://youtube.com/watch?v=EXAMPLE_ID"

```

## Summary

- **Configure YouTube cookies in Agent Reach** using `agent-reach configure youtube-cookies <browser|filepath>` to enable access to age-restricted and member-only content.
- **Browser authentication** supports Chrome, Firefox, Edge, Brave, and Opera via `--cookies-from-browser`.
- **File-based authentication** requires exporting cookies manually and referencing the path via `--cookies`.
- **Configuration storage** occurs in `~/.agent-reach/config.yaml` under the `youtube_cookies_from` key, implemented in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) and [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py).
- **JavaScript runtime requirement**: Ensure Node.js or Deno is installed, as validated by the `check()` method in [`agent_reach/channels/youtube.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/youtube.py).
- **Privacy preservation**: Cookies remain local and are never uploaded to remote servers.

## Frequently Asked Questions

### What browsers are supported for cookie authentication?

Agent Reach supports `chrome`, `firefox`, `edge`, `brave`, and `opera` for direct cookie extraction via yt-dlp's `--cookies-from-browser` flag. You must be logged into YouTube in the chosen browser for authentication to succeed.

### Why do I need Node.js or Deno installed?

According to the `check()` method in [`agent_reach/channels/youtube.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/youtube.py), yt-dlp requires a JavaScript runtime to execute code on YouTube pages when processing age-restricted content. The `render_ytdlp_fix_command()` function in [`agent_reach/utils/paths.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/utils/paths.py) generates configuration commands to specify `--js-runtimes node` if the automatic detection fails.

### Can I use exported cookie files instead of browser extraction?

Yes. Export your cookies using a browser extension like Cookie-Editor to a [`cookies.txt`](https://github.com/Panniantong/Agent-Reach/blob/main/cookies.txt) file, then run `agent-reach configure youtube-cookies /path/to/cookies.txt`. Agent Reach detects the file path and uses the `--cookies` parameter instead of `--cookies-from-browser` when invoking yt-dlp.

### Where does Agent Reach store my cookie configuration?

The configuration is stored locally in `~/.agent-reach/config.yaml` under the `youtube_cookies_from` key. This value is written by the CLI handler in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) (line 1108) and retrieved by the configuration module in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) (lines 79-84) during video processing.