Skip to content
Use casesLearnAbout me
cleverest
Back to all articles

How to build a Claude routine that sends Slack notifications

A follow-along companion to the YouTube tutorial. Use this to check off each step, copy the right URLs and terminology, and come back later when you build your next routine.

By the end, you'll have a scheduled Claude Code routine that runs in the cloud, reads sources you care about, writes a digest to a GitHub repo, and pings you on Slack — even when your laptop is off.


What you'll build

A Claude Code routine that:

  1. Runs on a schedule in Anthropic's cloud (not on your machine)
  2. Works in a GitHub repository you control
  3. Reaches Slack through a custom cloud environment with an allowed-domains list and a bot token
  4. Posts a message to your Slack workspace as a bot, so you actually get a phone notification

What you'll need

  • A Claude.ai Pro, Max, Team, or Enterprise subscription with Claude Code on the web enabled — routines aren't available on the free tier. See Automate work with routines for current availability.
  • Claude Code installed on your machine. If you don't have it yet, start with Claude Code quickstart.
  • A GitHub account. The gh CLI is helpful but not required — Claude Code can walk you through the install.
  • A Slack workspace where you can create and install a Slack app. Most workspaces allow this by default; if yours doesn't, your Slack admin will need to approve it.
  • A target Slack channel already created in your workspace (public or private — either works). You'll invite the bot to this channel in Part 4.
  • About 30 minutes the first time. Every routine you build after this takes closer to 5.

Heads-up on cost: routines use your Claude subscription, not separate API credits. If you're on Pro or Max, the budget is already in the plan.


Part 1: Set up a GitHub repository

Routines need a GitHub repository to work in. That's where the routine's output — your daily digest, in this case — gets committed and stored.

The fastest way to set one up is to ask Claude Code to do it for you. If you'd rather do it manually, GitHub's Quickstart for repositories walks through the web UI.

Option A — Ask Claude Code to do it

  1. Open your terminal and navigate to a fresh folder you want Claude to work in. You can create one anywhere, for example on your desktop. The folder doesn't need to be empty — anything you put in it becomes part of the initial commit.
  2. Run claude to start Claude Code in that folder.
  3. Ask Claude: "Help me set up a private GitHub repository for this project." Claude checks if the GitHub CLI (gh) is installed. If it isn't, Claude walks you through installing and authenticating it.
  4. Answer Claude's questions about name, visibility, and purpose. Use a descriptive name like daily-digest. Choose Private for anything personal. Tell Claude what the repo is for so it can draft a README and basic folder structure.
  5. Approve the commits when Claude is ready. Claude creates the repo locally, creates it on GitHub with gh repo create, and pushes the initial commit.

Option B — Create the repository yourself

Follow GitHub's official guide: Creating a new repository. Use the + menu in the upper-right of GitHub.com, select New repository, name it, choose visibility, and click Create repository.

Connect the repository to Claude Code on the web

The routine needs to be able to clone and push to this repo from the cloud. If you haven't connected GitHub to Claude.ai yet:

  • Go to Settings > Connectors on claude.ai, or
  • Run /web-setup in your terminal to sync your local gh token to your Claude account

See GitHub authentication options for the difference between the two methods.


Part 2: Create the routine

A routine is a saved Claude Code configuration — a prompt, one or more repositories, a cloud environment, and one or more triggers. Once saved, it runs automatically on its schedule. The official reference is Automate work with routines.

Draft the prompt with Claude Code first

Don't write the routine's prompt by hand. The prompt runs autonomously in the cloud with zero context about you, which means it must say everything about what to read, what format to write, where to commit, and how to post to Slack.

  1. In the same Claude Code session you used for the repo setup, ask: "Help me write a routine prompt that runs every weekday morning, reads [list your sources], writes a digest file to [target path in the repo], commits to main, and posts a short summary to [your Slack channel] via the Slack Web API using a bot token stored as SLACK_BOT_TOKEN."
  2. Iterate. Claude asks clarifying questions about format, tone, and edge cases. Answer them until the prompt feels self-contained.
  3. Copy the finished prompt. You'll paste it into the routine form next.

Create the routine

  1. Go to claude.ai/code/routines and click New routine.
  2. Name the routine — something like "Daily reading digest" — and paste the prompt you just drafted.
  3. Under Select repositories, add the repo from Part 1. If you want the routine to commit directly to main instead of a claude/-prefixed branch, toggle on Allow unrestricted branch pushes for that repository.
  4. Under Select an environment, leave the environment set to Default for now. You'll swap this in Part 5.
  5. Under Select a trigger, choose Schedule. Pick a frequency (weekdays, daily, etc.) and a time. Times are entered in your local zone and converted to UTC automatically.
  6. Under Review connectors, check which ones are pre-selected. By default, all of your connected MCP connectors are added to every new routine, so you'll likely see everything you've ever connected in Claude. Deselect anything the routine doesn't need, and specifically remove the Slack connector if it's there — it would post as you, not as a bot, which means no phone notification.
  7. Click Create.

Do not click Run now yet. The Slack plumbing isn't in place yet — it'll fail.


Part 3: Set up a custom cloud environment

A cloud environment is the sandbox configuration for your routine. It controls two things that matter here: what domains the routine can reach on the internet, and what secrets (like API tokens) it has access to. The full reference lives at The cloud environment.

Why the Default environment isn't enough

The Default environment uses the Trusted network access level. Trusted has a large default allowlist oriented toward developer tooling — GitHub, npm, PyPI, Docker Hub, major cloud providers, and dozens more. See the full list at Default allowed domains.

What Trusted doesn't include is slack.com. Service APIs like Slack are treated as intentional integrations, not default assumptions. To let the routine talk to Slack, you need a Custom environment that adds slack.com to the allowlist.

Every outbound request from a routine passes through Anthropic's security proxy. Requests to allowed domains pass through; everything else is blocked at the proxy. The proxy is the enforcement mechanism — see Security proxy for details.

Create the environment

  1. Go to claude.ai/code, open the environment selector at the top of any session, and select Add environment.
  2. Give it a descriptive name like digest-notifier. One environment per purpose is a good habit — it keeps your Slack-posting secrets separate from any other routines you run.
  3. Under Network access, select Custom.
  4. In the Allowed domains field, add slack.com on its own line.
  5. Check Also include default list of common package managers so the Trusted list (GitHub, npm, etc.) stays available alongside Slack.
  6. Leave Environment variables empty for now. You'll add the Slack bot token in Part 5 once you've generated it.
  7. Save the environment.

A warning about the Environment variables field: "Both environment variables and setup scripts are stored in the environment configuration, visible to anyone who can edit that environment" (source).

For a personal, single-user Claude account, this is the pragmatic place to store a bot token — your Claude account is the trust boundary. If you share the environment with teammates, every routine they write that uses this environment can read the token. For team setups, keep the token out of the environment config entirely and fetch it from a proper secrets manager inside a setup script at session start.


Part 4: Create the Slack bot

A bot token is a password that lets a Slack app post on its own behalf, instead of as you. With the bot posting, your phone actually pings when a new message lands. The official Slack reference is the Slack quickstart and Installing with OAuth.

Create the app

  1. Go to api.slack.com/apps and sign in.
  2. Click Create New App, then choose From scratch.
  3. Give the app a name your teammates (and future you) will recognize — for example, "AI Digest Bot". This is the name that shows up on every notification.
  4. Pick the Slack workspace you want to install it in.
  5. Click Create App. You'll land on the Basic Information page. Scroll to App Credentials — keep those values private; they're equivalent to passwords.

Add the right permissions

  1. In the left sidebar, select OAuth & Permissions.
  2. Scroll down to Scopes, then under Bot Token Scopes, click Add an OAuth Scope.
  3. Add chat:write. This is the minimum scope needed to post messages.
  4. Optionally add other scopes if your use case needs them:
    • chat:write.public — lets the bot post in channels without being manually invited. Slightly broader access, more convenient.
    • channels:history and channels:read — let the bot read past messages in a channel it's in.

Install the app and copy the token

  1. Scroll back up on the OAuth & Permissions page and click Install to Workspace.
  2. Review the permissions and click Allow.
  3. Copy the Bot User OAuth Token. It starts with xoxb-.

Treat this token like a password: don't paste it into chats, commits, or a visible screen recording. If you ever show it on screen, rotate it immediately from the same OAuth & Permissions page.

Invite the bot to your channel

In Slack, open the channel you want the digest to arrive in and type /invite @AI Digest Bot (replace with your bot's name). Without this step, your first run will fail with not_in_channel.


Part 5: Wire the token into the routine and test

Before you start Part 5: make sure the bot is already a member of your target Slack channel (from Part 4). Without that /invite, the first run will fail with not_in_channel.

Add the token to the environment

  1. Back at claude.ai/code, open the environment selector and select the settings icon next to digest-notifier.
  2. In the Environment variables field, add a new line: SLACK_BOT_TOKEN=xoxb-... — paste the token from Part 4 in place of xoxb-.... Environment variables use .env format: one KEY=value pair per line, no quotes around the value.
  3. Save.

Point the routine at the environment

  1. Go to claude.ai/code/routines and open your "Daily reading digest" routine.
  2. Click the pencil icon to edit.
  3. Change the Environment from Default to digest-notifier.
  4. Save.

Tighten the prompt (if you haven't already)

Make sure the routine's prompt is explicit that the agent should post to Slack using the Web API (not an MCP connector, not a webhook) with the token stored in SLACK_BOT_TOKEN. A line like the following, dropped into the prompt, is usually enough:

After writing the digest file, post a short summary to Slack channel #your-channel-name using a POST request to https://slack.com/api/chat.postMessage with the SLACK_BOT_TOKEN environment variable as the Bearer token in the Authorization header. Content-Type should be application/json and the body should include channel and text fields.

The official reference for this endpoint is chat.postMessage.

Run it

  1. On the routine detail page, click Run now.
  2. Open the session URL in a new tab. You'll see Claude clone the repo, read the sources, write the digest, commit it, and post to Slack — live.
  3. Check three places to confirm success: the Slack channel (message arrived), your GitHub repo (commit landed on main), and the routine's run history (session marked successful).

That's it. It'll fire on its own from now on — you don't need to babysit it.


Troubleshooting

Error What it means Fix
Host not in allowlist when posting to Slack slack.com isn't in the environment's allowed domains Open the digest-notifier environment → Network access → Custom → add slack.com
not_in_channel The bot isn't a member of the channel In Slack, run /invite @YourBotName in the target channel
invalid_auth or not_authed from Slack The token is missing, wrong, or revoked Check that SLACK_BOT_TOKEN is set on the environment (not the routine) and that the value starts with xoxb-. Regenerate the token in Slack if needed.
403 or DNS-related error when posting to Slack The prompt is using a webhook URL instead of the Web API Rewrite the prompt to use https://slack.com/api/chat.postMessage instead of a webhook
Routine fails at git push — "repository not found" GitHub isn't connected to your Claude account, or the repo isn't added to the routine Connect GitHub under Settings > Connectors on claude.ai, then check that the routine has the repo selected under Select repositories
Routine fails at git push — "protected branch" or refused push to main The routine is trying to commit to main but Allow unrestricted branch pushes is off Open the routine, find the repo under Select repositories, and toggle on Allow unrestricted branch pushes for that repo
Routine fails at git push — authentication error Your GitHub token has expired or been revoked Run /web-setup in your terminal to refresh the token, or reinstall the Claude GitHub App
Routine completed but no Slack message arrived The routine may have decided the step was optional, or the channel name was wrong Open the session URL from the run history and read the transcript — Claude will usually explain what it tried. Tighten the prompt so the Slack step is a hard requirement.

Where to go next

  • Add more sources. Edit the sources file in your GitHub repo, and the routine picks up the changes on the next run. No need to touch the routine itself.
  • Build a second routine with the same pattern. The digest-notifier environment is reusable — any new routine that points at the same environment can post to Slack with no setup.
  • Rotate the bot token periodically. From the OAuth & Permissions page in your Slack app, you can revoke the token and reinstall the app to generate a new one. Update the env var in Claude after rotation.
  • Watch for silent failures. If a run fails, the routine doesn't notify you by default — which is a problem if the one job of the routine is to notify you. A future tutorial will cover failure alerts.

Sources