# Post Slack Alerts When GitHub Actions Workflows Fail

Yes. An agent adds one workflow_run notifier that posts to Slack through an incoming webhook whenever any of your CI workflows fails on main, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-slack-failure-alerts/github-actions/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads every workflow before it decides where an alert belongs. In a repository like actions/typescript-action, `.github/workflows/` has `ci.yml`, named `Continuous Integration`, with a `test-typescript` job that runs `npm ci`, the Prettier check, ESLint and Jest on the Node version in `.node-version`, and a `test-action` job that runs the action itself; `check-dist.yml`, named `Check Transpiled JavaScript`, rebuilds `dist/` and fails on a diff; `linter.yml`, named `Lint Codebase`, runs `super-linter` with the repository's `.yaml-lint.yml`, which warns past 80 columns; `codeql-analysis.yml`, named `CodeQL`, on pull requests, pushes and a weekly cron; and `licensed.yml` on `workflow_dispatch` only. All of them run on `pull_request` and `push` to `main` with `permissions: contents: read`, and none of them mentions Slack. `dependabot.yml` groups action updates weekly.

Rather than add an `if: failure()` step to each of four workflows, which would drift and miss a job that fails before its steps start, the agent writes one `.github/workflows/notify-failure.yml` on `workflow_run` with `workflows` listing the four names exactly as their `name:` fields spell them and `types: [completed]`. Its single job runs only when `github.event.workflow_run.conclusion == 'failure'` and `head_branch == 'main'`, so a failing pull request, which already shows its red check to its author, does not page the channel, while a broken `main` does. `permissions` is an empty map, since the job reads only the event payload.

The job uses `slackapi/slack-github-action` at its v2 major with `webhook: ${{ secrets.SLACK_WEBHOOK_URL }}` and `webhook-type: incoming-webhook`, and a YAML `payload` whose `text` is the fallback line and whose `blocks` hold the workflow name, the branch, the short commit SHA, the actor and a button to `workflow_run.html_url`, all taken from the event rather than from the notifier's own run, which is what a reader expects to click. Lines stay under the 80 columns `.yaml-lint.yml` warns about, because `super-linter` will lint this file on the pull request too.

The sandbox has no Slack webhook, so the agent does not send a message; it runs `actionlint` on the new file, runs `yamllint` with the repository's config, and checks each `workflows:` entry against the `name:` of the file it refers to, since a misspelled name silently never triggers. It adds a short `Slack alerts` section to `README.md` that says which secret to create and where, and opens the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add Slack alerts for failed GitHub Actions workflows to this repository. Read every file under .github/workflows and the lint configuration at the repository root first. Write one workflow_run notifier that triggers when any of the existing CI, dist check, lint and CodeQL workflows completes, runs only when the conclusion is failure on the main branch, and posts through slackapi/slack-github-action v2 with an incoming webhook stored in a SLACK_WEBHOOK_URL secret. The message must name the workflow, branch, commit, actor and link to the failed run. Keep lines within the repository's yamllint limit, run actionlint and yamllint in your sandbox, document the secret in the README, and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch that adds `.github/workflows/notify-failure.yml` and changes `README.md`. The description lists the four workflow names the notifier watches, shows the message payload, explains why pull request failures are excluded, and pastes the `actionlint` and `yamllint` output from the sandbox.

The repository's own `Lint Codebase` workflow runs on the pull request and lints the new file with the same `super-linter` settings as everything else, so a reviewer sees it pass before merge. The run's record keeps the sandbox commands with their output beside the diff.

Before merging, a reviewer creates the incoming webhook for the right channel and saves it as `SLACK_WEBHOOK_URL` in the repository's secrets, and decides whether the notifier should also cover failures on release tags. A `workflow_run` trigger only fires from the workflow file on the default branch, so the first real alert can only follow a failure after the merge.

## Run it on every Linear issue labelled ci

In the console, an automation in the Project that has the repository, with a `linear` trigger on `linear.issue.labeled` and `labels` set to `ci`, starts one run per issue with the issue as its context after the prompt; the saved prompt is the whole instruction, and the trigger fills in no placeholder. A later issue that asks for a second channel, alerts on `cancelled` conclusions, or a mention of the on-call group is one run that edits the notifier and its payload.

From your own tracker, a handler sends one `POST /o/{org}/sessions` with this body, the repository in `resources` and a `request_id` that is a UUID v5 of the issue id, so a repeated delivery returns the run already started. With a `webhook_url` on the key, Rush posts `run.completed` with the `session_url` when the pull request is up.

## Why run it on Rush?

A Slack notifier is a small file whose failures are silent: a workflow name copied with one word different never triggers, a payload line past the linter's limit fails the repository's own lint check, and a link to the notifier's run instead of the failed one sends the reader to a green page. The agent reads the real workflow names and lint rules, builds the payload from the event, and lints the file in its own sandbox before the pull request exists.

Every command and its output stays in the run's record, so the reviewer sees the `actionlint` and `yamllint` results rather than a sentence about them. Several repositories can get the same notifier at once in separate sandboxes, each ending in its own pull request that names its own workflows.

## Frequently asked questions

### Why workflow_run instead of a failure step in each workflow?

One file watches all four workflows by name, including a job that fails before its first step, and adding a fifth workflow later means adding one name. A per-workflow step has to be copied into each file and kept in sync, and it never runs when the job cannot start.

### Will it alert on failing pull requests?

No. The job checks `head_branch == 'main'`, so a red check on a pull request stays with its author and only a broken `main` reaches the channel. Remove that condition, or add `release/*`, if you want more.

### Can the agent test the message from the sandbox?

It has no webhook URL, so it does not post. It lints the workflow and payload, verifies each watched name against the real `name:` fields, and the first message arrives on the first `main` failure after the merge, because `workflow_run` reads the notifier from the default branch.

### Where does the webhook URL live?

In a repository or organization secret named `SLACK_WEBHOOK_URL`, created from a Slack incoming webhook for the channel you choose. The workflow reads it with `secrets.SLACK_WEBHOOK_URL` and never prints it; the README section the pull request adds says exactly this.

## More GitHub Actions jobs

- [Add zizmor to CI for Your GitHub Actions Workflows](https://getrush.ai/run/add-zizmor-to-ci/github-actions/)
- [Fix "docker-compose: command not found" in GitHub Actions](https://getrush.ai/run/fix-docker-compose-command-not-found/github-actions/)
- [Fix a Failing check-dist Job in a TypeScript GitHub Action](https://getrush.ai/run/fix-failing-ci/github-actions/)

## The same job on other stacks

- [Add Slack Alerts on Task Failure to Airflow DAGs](https://getrush.ai/run/add-slack-failure-alerts/airflow/)
- [Add Slack Alerts on Failed Runs to a Dagster Project](https://getrush.ai/run/add-slack-failure-alerts/dagster/)

## More jobs like this: Turn a Linear label into a PR

- [Add Slash Commands to a discord.py Bot](https://getrush.ai/run/add-slash-command/discord-py/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
