Twitch integration setup
Create a Twitch application, sign in, and connect your bot account
This guide walks you through every step of setting up Twitch integration for DireWork — from creating the Twitch application to connecting your bot account.
Overview
DireWork uses Twitch OAuth for two things:
- Streamer login — You sign in with your main Twitch account
- Bot account — A separate Twitch account that reads and sends chat messages
Both use the same Twitch application, but different redirect URLs.
Step 1: Create a Twitch application
- Go to the Twitch Developer Console
- Log in with your main Twitch account (the streamer account)
- Click Applications in the left sidebar
- Click Register Your Application
Twitch only lets accounts with two-factor authentication register applications. If the console asks you to enable it, turn it on under Twitch Settings → Security and Privacy, then come back.
Fill in the application details
| Field | Value |
|---|---|
| Name | DireWork (or any name you want) |
| OAuth Redirect URLs | See below |
| Category | Broadcasting Suite |
| Client Type | Confidential |
Add redirect URLs
You need to add two redirect URLs. Click the + Add button for each:
For local development:
http://localhost:3001/api/auth/callback/twitch
http://localhost:3001/api/bot/callback/twitchFor production (add these too if you plan to deploy — swap in your workers.dev subdomain):
https://dirework.<your-subdomain>.workers.dev/api/auth/callback/twitch
https://dirework.<your-subdomain>.workers.dev/api/bot/callback/twitchThe redirect URLs must match exactly — including the protocol (http vs https), port number, and path. A mismatch will cause "Invalid redirect URI" errors.
- Click Create
Copy your credentials
After creating the app:
- You'll see the Client ID on the application page — copy it
- Click New Secret to generate a Client Secret
- Copy the secret immediately — it's only shown once
If you lose the client secret, you'll need to generate a new one by clicking New Secret again. This will invalidate the old secret.
Step 2: Configure environment variables
Create or edit your packages/infra/.env file (copy it from .env.example if you
haven't yet) and add the Twitch credentials:
# Twitch OAuth (from dev.twitch.tv)
TWITCH_CLIENT_ID="paste_your_client_id_here"
TWITCH_CLIENT_SECRET="paste_your_client_secret_here"Your complete .env should look like this:
# Better Auth
BETTER_AUTH_SECRET="generate-a-random-32-character-string"
BETTER_AUTH_URL="http://localhost:3001"
CORS_ORIGIN="http://localhost:3001"
# Twitch OAuth
TWITCH_CLIENT_ID="abc123def456..."
TWITCH_CLIENT_SECRET="xyz789..."Generate a strong secret with:
openssl rand -base64 32BETTER_AUTH_URL must match the origin you used in your Twitch redirect URLs. For local dev, that's http://localhost:3001.
Step 3: Sign in
- Start the app with
bun run dev - Open http://localhost:3001
- On a fresh install you'll land on the setup screen — click Claim with Twitch
- You'll be redirected to Twitch — authorize the app with your streamer account
- After authorizing, you'll land on the dashboard as the instance owner
If sign-in fails, check:
- Your
TWITCH_CLIENT_IDandTWITCH_CLIENT_SECRETare correct - The redirect URL
http://localhost:3001/api/auth/callback/twitchis in your Twitch app BETTER_AUTH_URLis set tohttp://localhost:3001
Step 4: Create a bot account on Twitch
The bot account is the Twitch account that sends messages in your chat. A separate bot account is recommended. Using your own streamer account also works, but every bot reply will then come from you.
Create the bot account
- Open a private/incognito browser window (so you don't get logged out of your main account)
- Go to twitch.tv
- Click Sign Up and create a new account
- Choose a name like
YourNameBotorDireWorkBot - You'll need a different email address
- Choose a name like
- Complete the account setup (verify email, etc.)
Twitch allows multiple accounts. The bot account is just a regular Twitch account that DireWork uses to send chat messages.
Make the bot a moderator (recommended)
In your main streamer account's chat, type:
/mod YourBotUsernameThis prevents the bot from being rate-limited when sending messages.
Step 5: Connect the bot account
- Go to Bot settings at http://localhost:3001/dashboard/bot (the bot chip in the dashboard's header links there too)
- Find the Bot account card
- Click Connect bot account
- You'll be redirected to Twitch — sign in with the bot account (not your streamer account, unless you chose to use it as the bot)
- Authorize the app
- You'll be redirected back to Bot settings (
/dashboard/bot?bot=connected) with a success message
The bot will have chat:read and chat:edit permissions (plus the Helix chat scopes user:read:chat and user:write:chat) — enough to read messages and respond to commands — and moderator:read:followers for the follower check below.
One more thing before the bot talks: the bot runs in a token-gated browser page, not on a server. Copy its URL from Dashboard → Bot and keep it open: the invisible widget in an OBS browser source or a Moblin widget, or the dock in an OBS custom browser dock or a pinned tab. The bot listens to chat only while that page is open. See Chat commands for the full command list.
Where to keep the bot page
Pick one. The dashboard's Set up streaming card and the Run the bot card on
Dashboard → Bot ask How will you run the bot? and show the URL for your pick
(Widget URL or Dock URL) with its steps. Both carry the same secret token, so treat
them like a stream key, and run one or the other: only one bot page joins chat at a time.
Open a second copy and it stands by (tab title DireWork bot · Standby); the dock version
shows The bot is running somewhere else with a Take over button that moves the bot
to it. A standby page takes over on its own once the running page closes. While a page runs
the bot, the dashboard's bot chip says Bot connected.
| Option | URL | Notes |
|---|---|---|
| Widget | …/bot/<token> | A blank, transparent page: nothing shows on stream, so it can sit on any scene at any size. Add it as an OBS browser source (untick Shutdown source when not visible) or a Moblin browser widget (keep it in a scene that stays loaded). Its browser tab title says the state, such as DireWork bot · Connected. |
| Dock / browser tab | …/bot/<token>?view=dock | A narrow control panel styled like OBS's dark theme: status light, muted state, timer and bot buttons, last error, recent commands and a Reconnect button. Mute bot / Unmute bot and Reconnect stay pinned at the top, so they're reachable even in a short dock. Add it as an OBS custom browser dock, or open it in a browser tab and pin the tab. |
Either page can stay open while you update DireWork. It picks up alias changes, and new commands from an update, within an hour; reload it (or refresh the OBS browser source) to use them right away.
The widget never shows errors on stream. If the bot stops (the URL was reset, or Twitch no longer accepts the bot's login), the dock shows why, and Dashboard → Bot is where you fix it.
OBS 31+ is recommended. OBS 28–30 is untested; OBS 27.1's Chromium 75-era browser source can't run DireWork's bundles.
Add the dock (Windows, macOS and Linux X11):
- In OBS, open Docks → Custom Browser Docks (older versions: View → Docks → Custom Browser Docks).
- Give it a name such as
DireWork Bot, paste the Dock URL, and click Apply. - Drag the dock where you want it. If it's in the way, tab it behind another dock.
Don't close the dock. Closing it (the X, or unticking it in the Docks menu) unloads the page and stops the bot until you open the dock again. A dock tabbed behind another one keeps running.
Dock buttons. Each button sends a chat command as you (the broadcaster), exactly as if you'd typed it, but the bot's reply shows in the dock instead of chat:
| Button | Sends |
|---|---|
| Start, Pause, Resume, Skip, Reset | !timer start, !timer pause, !timer resume, !timer skip, !timer reset |
| Mute bot / Unmute bot | !mute / !unmute |
| Clear done | !clear done |
- Reset and Clear done ask before they run.
- The dock doesn't watch the timer, so all five timer buttons always show. A button that doesn't apply right now gets the same answer a mod would in chat (for example, "not running").
- While muted, only Unmute bot works: a muted bot ignores every other command.
- The buttons turn on once the bot is connected. If a timer or task command is turned off in Dashboard → Bot, its button sends but the bot has no reply.
Streaming from a phone? Add the Widget URL as a browser widget in an app that draws web pages on the stream, such as Moblin (iOS 16.4+ / Safari 16.4+); the bot runs while that widget's scene is loaded. If your phone instead sends its feed to a PC or cloud OBS (SRT, RTMP) that goes live to Twitch, add the widget or the dock on that OBS. Apps with no browser widget that stream straight to Twitch can't keep the bot running.
OAuth scopes
DireWork requests specific OAuth scopes for each connection type:
| Connection | Scopes | Purpose |
|---|---|---|
| Streamer login | openid | Authentication, profile info (no email) |
| Bot account | chat:read, chat:edit | Read and send chat messages over IRC (the connection the bot page actually uses) |
| Bot account | user:read:chat, user:write:chat | Helix chat API equivalents — reserved for a future move to Helix sends |
| Bot account | moderator:read:followers | Check whether a viewer follows you, for Who can add tasks → Followers. Twitch answers only when the bot is a mod in your chat |
You don't need to configure scopes manually — DireWork requests them automatically during the OAuth flow. The scopes are minimal by design: only what's needed for the bot to read and write chat messages.
Connected your bot before chat:read/chat:edit were added? Existing tokens don't
gain scopes automatically — disconnect the bot account and connect it again to pick up
the new scopes.
Connected your bot before the follower check? It keeps working exactly as before. Only Who can add tasks → Followers needs the new permission: click Reconnect the bot where Bot settings asks, or Connect bot account again with the same account.
If connection fails
Common issues:
| Error | Solution |
|---|---|
| Token exchange failed | Check that http://localhost:3001/api/bot/callback/twitch is in your Twitch app's redirect URLs |
| Redirected to home page | Make sure you're logged in to DireWork first |
| No error but nothing happened | Check the browser console and server logs for details |
| "Invalid redirect URI" on Twitch | The redirect URL in your Twitch app doesn't match exactly — check for trailing slashes, wrong port, or http vs https |
The most common issue is a redirect URL mismatch. The URL {BETTER_AUTH_URL}/api/bot/callback/twitch must exactly match one of the redirect URLs in your Twitch Developer Console app.
Step 6: Set up OBS overlays
After signing in, your dashboard shows both overlay URLs in OBS sources, under the timer controls:
- Copy the Timer overlay URL
- In OBS, add a Browser Source
- Paste the overlay URL (it looks like
http://localhost:3001/overlay/t/YOUR_TOKEN) - Set width and height to
300(the timer scales to fill the source; use 700 x 800 for the task list) - Check "Shutdown source when not visible"
- Repeat with the Tasks tab's Tasks overlay URL
See the Overlays guide for more details.
Redirect URLs reference
| URL Pattern | Purpose | When it's used |
|---|---|---|
{BETTER_AUTH_URL}/api/auth/callback/twitch | Streamer login | When you sign in with Twitch |
{BETTER_AUTH_URL}/api/bot/callback/twitch | Bot account connection | When you click "Connect bot account" |
For local development, BETTER_AUTH_URL = http://localhost:3001
For production, replace with your web worker's origin
(e.g., https://dirework.<your-subdomain>.workers.dev)
Who can sign in?
You don't need to configure access. DireWork is single-owner: the first Twitch account to sign in claims the instance, and after that no one else can take it over.
Until that first sign-in, though, any Twitch user who opens your instance's URL can claim it. Sign in as soon as your first deploy finishes and don't share the URL before then. If someone else claimed it, follow Recovering an instance someone else claimed.
Production checklist
When deploying to production, make sure to:
- Set
BETTER_AUTH_URLandCORS_ORIGINto your web worker's origin — for GitHub Actions deploys, set these as GitHub repository variables (repo Settings → Secrets and variables → Actions → Variables); the deploy job consumes them via${{ vars.* }}indeploy.yml— don't edit the workflow file itself - Add production redirect URLs to your Twitch app:
https://dirework.<your-subdomain>.workers.dev/api/auth/callback/twitchhttps://dirework.<your-subdomain>.workers.dev/api/bot/callback/twitch
- Use
https://(nothttp://) for all production URLs
The full walkthrough lives in the Deployment guide.