---
title: Claude Routines
description: Fire an AgentPing heartbeat at the end of every Claude Routines run.
section: integrations
order: 7
---

# Claude Routines

Claude Routines runs your Claude on a schedule. Add one HTTP call at the end of the routine and AgentPing tracks every fire: cost from the routine's token usage, status from the routine's exit, schedule monitoring from [Pulse](/docs/pulse).

## The setup

In your routine's tool list, give Claude access to an `http_request` tool (or use the bash tool if your routine has shell access). At the bottom of the routine prompt, add a heartbeat step:

> After completing the task above, fire a heartbeat: `curl 'https://eu.ingest.agentping.io/v1/ping?key=$AGENTPING_PING_TOKEN&agent=daily-research&status=ok'`. If you encountered any errors, use `status=fail` instead.

Store the per-agent ping token in your routine's environment variables; don't paste it into the prompt.

## Recipe

A research routine that summarises 5 news sources every morning:

```
Each morning at 09:00 UTC, fetch the top 3 stories from each of these sources:
- TechCrunch (https://techcrunch.com)
- The Information (https://theinformation.com)
- Hacker News (https://news.ycombinator.com)

Write a one-paragraph summary per source. Save it to my Notes app.

Then fire this heartbeat with the appropriate status:
- If all 3 sources succeeded: curl 'https://eu.ingest.agentping.io/v1/ping?key=$AGENTPING_PING_TOKEN&agent=morning-research&status=ok'
- If any source failed: curl 'https://eu.ingest.agentping.io/v1/ping?key=$AGENTPING_PING_TOKEN&agent=morning-research&status=fail&metadata=source_failed'
```

The heartbeat lands within a second; [Pulse](/docs/pulse) compares it against the routine's cron and pages you if a morning fire was missed.

## Adding cost

Claude Routines surfaces token usage in the routine's run summary. To capture that in the heartbeat, ask Claude to read its own usage figure before the curl:

```
After saving the summary, retrieve your total token usage for this routine.
Then fire this heartbeat with the cost:
curl 'https://eu.ingest.agentping.io/v1/ping?key=$AGENTPING_PING_TOKEN&agent=morning-research&status=ok&cost_usd=<your computed cost>'
```

Computing cost client-side is rough; the cleaner pattern is to skip `cost_usd` and let AgentPing's [rate card](/docs/spend) price the run when Anthropic's billing reconciles. For Claude Routines today, status + duration is the right level of detail.

## Why this works

Claude Routines is best-effort scheduling: Claude doesn't guarantee your routine runs at exactly the cron you set. AgentPing's schedule monitoring is the safety net. Set the same cron on the agent in the dashboard; if a routine misses its window, you get paged.

## Failure cases

If the routine itself fails before reaching the heartbeat step (Claude crashes, network drops, the routine exceeds its time budget), no curl fires. That's the right answer: Pulse sees the missed window and pages.

The only failure mode that needs extra wiring is "Claude completed the work but couldn't reach AgentPing." In practice this is rare.

:::warning
Paste the ping token (`ping_...`), not the team API key (`apk_...`), into the routine's environment. Ping tokens are agent-scoped; if the routine ever leaks the token, the blast radius is one agent. See [Authentication](/docs/api/auth).
:::
