This makes the agent run
even when your browser is closed. A tiny script on Cloudflare's servers calls Slack + Claude every 6h, stores results, and posts a digest to your Slack DM. The dashboard reads stored results instead of calling APIs live.
- In Cloudflare dashboard β Workers & Pages β Create Worker
- Paste the worker script below β click Deploy
- Go to Settings β Triggers β Add Cron Trigger β set 0 */6 * * * (every 6h)
- Add environment variables: ANTHROPIC_API_KEY, SLACK_TOKEN
- The worker posts your digest to Slack DM automatically
// Cloudflare Worker β paste into worker editor
export default {
async scheduled(event, env, ctx) {
const since = Math.floor(Date.now()/1000) - 6*3600;
const res = await fetch('https://api.anthropic.com/v1/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': env.ANTHROPIC_API_KEY,
'anthropic-version': '2023-06-01'
},
body: JSON.stringify({
model: 'claude-sonnet-4-20250514',
max_tokens: 1000,
system: 'Extract inventory tasks from Slack. Return JSON with tasks array.',
messages: [{ role: 'user',
content: `Read channels C05QQJ08QQK and C03JGRN227M since ${since}. Return tasks for U09K3U5QG74.`
}],
mcp_servers: [{ type: 'url', url: 'https://mcp.slack.com/mcp', name: 'slack' }]
})
});
const data = await res.json();
const text = data.content?.find(b=>b.type==='text')?.text || 'No new tasks.';
// Post digest to your Slack DM
await fetch('https://slack.com/api/chat.postMessage', {
method: 'POST',
headers: { 'Authorization': 'Bearer ' + env.SLACK_TOKEN, 'Content-Type': 'application/json' },
body: JSON.stringify({ channel: 'U09K3U5QG74', text: 'π¦ *Inventory Agent digest*\n' + text })
});
}
};