SDK

Claude Agent SDK

The stillrunning-claude-agent-sdk package monitors Claude Agent SDK runs. Wrap query once and StillRunning gets a ping on every run with its duration, tokens, cost, model, and tool-call count, and alerts you the moment one fails, runs too long, or costs too much.

Install

terminal
npm install stillrunning-claude-agent-sdk

The Claude Agent SDK is your own dependency. This package wraps the queryyou already import, so there's no version to keep in lockstep.

30-second quickstart

1. Create a workflow at stillrunning.ai/app/new and copy its token. 2. Set STILLRUNNING_TOKEN. 3. Wrap query:

agent.ts
import { query } from '@anthropic-ai/claude-agent-sdk'
import { stillrunning } from 'stillrunning-claude-agent-sdk'

const sr = stillrunning() // reads STILLRUNNING_TOKEN
const monitoredQuery = sr.wrap(query)

for await (const message of monitoredQuery({ prompt: 'fix the failing test' })) {
  // use messages exactly as before — a ping fires when the run completes
}

monitoredQuery is a drop-in for query: same arguments, the same message stream, and the same control methods (interrupt(), setPermissionMode()). It just watches the run go by.

What it captures

On completion the wrapper reads the SDK's final resultmessage and pings StillRunning with the run's duration, total_cost_usd, input/output tokens (including cache reads and writes), the dominant model, and a count of tool calls. Turn count, session id, and terminal reason ride along as metadata.

A run that ends on an error_* result, or throws mid-stream, pings fail (and the error rethrows untouched). A failed run still reports the tokens and cost it spent before failing.

Grouping multi-step agents

Wrap several runs in withTrace so they share one traceId and stitch into a single outcome chain:

trace.ts
import { stillrunning, withTrace } from 'stillrunning-claude-agent-sdk'
const sr = stillrunning()
const query = sr.wrap(baseQuery)

await withTrace(async () => {
  for await (const _ of query({ prompt: 'plan the work' })) {}
  for await (const _ of query({ prompt: 'execute step 1' })) {}
}) // both runs share one traceId

Configuration

options.ts
stillrunning({
  token,         // ping token; defaults to process.env.STILLRUNNING_TOKEN
  baseUrl,       // defaults to https://stillrunning.ai
  computeCost,   // ({ model, inputTokens, outputTokens }) => number — override the SDK cost
  awaitPing,     // default true; false = fire-and-forget (lowest latency)
  pingTimeoutMs, // default 3000
  onError,       // (err) => void — observe ping delivery failures
  fetch,         // custom fetch (testing / non-global-fetch runtimes)
})

Monitoring never throws into your code: a failed ping routes to onError and is otherwise swallowed, bounded by pingTimeoutMs so a slow StillRunning never hangs your agent. Messages stream through unchanged.

Requirements

Node 18+. The Claude Agent SDK as a peer dependency. Ships ESM + CJS with TypeScript types.

You're set

Open your dashboard to watch agent runs land with duration, cost, tool counts, and anomaly alerts.

Open dashboard
stillrunning

Heartbeat monitoring for AI workflows and agent scripts.

Product

Company

Legal

© 2026 StillRunning. All rights reserved.
hello@stillrunning.ai