npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cloudflare-to-claude-fix

v1.0.8

Published

<p align="center"> <img width="400px" src="https://i.imgur.com/RQP3lma.png" /> </p>

Downloads

1,087

Readme

A Cloudflare Workers Queue consumer that fires a Claude Code routine whenever a Workers build fails. Required Workers Paid and Claude Pro.


Setup

1. Clone / copy this project

git clone <your-repo>
cd cloudflare-to-claude-fix
npm install

2. Create the Cloudflare Queue

# Main queue
wrangler queues create workers-build-events

# Dead-letter queue (catches messages that fail all 3 retries)
wrangler queues create workers-build-events-dlq

3. Enable Event Subscriptions on your target Worker

In the Cloudflare dashboard:

  1. Open Workers & Pages → select the Worker you want to monitor
  2. Go to SettingsEvent Subscriptions
  3. Set the queue to workers-build-events
  4. Enable: Build started, Build succeeded, Build failed, Build cancelled

This Worker only acts on status === "failed" events; the rest are acknowledged and discarded.

4. Create a Claude Code routine

  1. Go to claude.ai/code/routines
  2. Click New routine
  3. Configure:
    • Prompt: e.g. "A Cloudflare Workers build has failed. The build ID, branch, commit, author and error log are below. Investigate the error, identify the root cause, and push a fix to the branch. Summarise what you changed."
    • Repository: the repo that this Worker is deployed from
  4. Under Select a triggerAdd another trigger → choose API
  5. Click Generate token — copy the token (shown once)
  6. Copy the full fire URL shown in the modal (format: https://api.anthropic.com/v1/claude_code/routines/trig_<id>/fire)

5. Store secrets in Wrangler

# Required
wrangler secret put ROUTINE_FIRE_URL
# paste: https://api.anthropic.com/v1/claude_code/routines/trig_<id>/fire

wrangler secret put ROUTINE_FIRE_TOKEN
# paste: sk-ant-oat01-...

# Optional — post session link to Slack or Discord
wrangler secret put NOTIFY_WEBHOOK_URL
# paste: https://hooks.slack.com/services/... (Slack)
#    or: https://discord.com/api/webhooks/...  (Discord)

Never commit secrets to source control or paste them in plaintext anywhere.

6. Deploy

wrangler deploy

How it works

  1. Cloudflare Builds publishes a BuildEvent message to workers-build-events when a build status changes.
  2. This consumer Worker receives the batch. Non-failure messages are ack()-ed immediately.
  3. For status === "failed" messages the Worker:
    • Formats the build_id, worker_name, branch, commit_hash, author, timestamp, and error_messages into a single plaintext block (≤ 65,536 chars).
    • POSTs that block to the Claude Code routine /fire endpoint.
    • If NOTIFY_WEBHOOK_URL is set, posts the resulting claude_code_session_url to Slack/Discord so your team can watch the live debugging session.
  4. If the fire request fails, the message is retry()-ed up to 3 times (configured in wrangler.toml). After 3 failures the message lands in workers-build-events-dlq.

Claude Code routine /fire API quick-reference

POST https://api.anthropic.com/v1/claude_code/routines/{routine_id}/fire
Authorization: Bearer sk-ant-oat01-...
anthropic-version: 2023-06-01
anthropic-beta: experimental-cc-routine-2026-04-01
Content-Type: application/json

{ "text": "<up to 65,536 chars of context>" }

Response:

{
  "type": "routine_fire",
  "claude_code_session_id": "session_01...",
  "claude_code_session_url": "https://claude.ai/code/session_01..."
}

| Status | Cause | | ------- | -------------------------------------------------------------- | | 400 | Missing beta header, text > 65 536 chars, or routine is paused | | 401 | Wrong or missing bearer token | | 403 | Account doesn't have Claude Code on the web | | 404 | Routine ID not found | | 429 | Daily run allowance exhausted |


Revoking / rotating the routine token

  1. Open claude.ai/code/routines → edit the routine
  2. Click the API trigger → Generate token (this immediately revokes the old one)
  3. Update the secret: wrangler secret put ROUTINE_FIRE_TOKEN

Local testing

Send a synthetic failed-build message to the queue:

wrangler queues publish workers-build-events \
  --message '{
    "build_id": "build_test001",
    "status": "failed",
    "worker_name": "my-api",
    "branch": "feat/new-endpoint",
    "commit_hash": "abc1234",
    "author": "[email protected]",
    "error_messages": ["Error: Cannot find module '\''./utils'\''", "    at Object.<anonymous> (src/index.ts:3:1)"],
    "timestamp": "2026-05-01T19:00:00Z"
  }'

Then tail logs to verify:

wrangler tail cloudflare-to-claude-fix