Tired of polling the Claude API for updates? The 2025 webhooks feature delivers real-time notifications for message events, tool calls, and workspace changes—perfect for enterprise-scale apps.
Hey there, Claude enthusiasts! If you're building production apps with the Anthropic Claude API, you know the drill: long-running conversations, tool calls that take time to process, or workspace updates that need instant reactions. Polling? So 2024. Enter Claude API Webhooks—Anthropic's game-changing feature rolled out in early 2025. These bad boys push real-time events straight to your server, letting you react instantly without wasting API calls or compute.
In this guide, we'll walk through everything: from setup to code examples in TypeScript and Python, handling key events like message completions, tool executions, and workspace changes. Whether you're a dev automating HR workflows or scaling AI agents for sales teams, this'll level up your integrations. Let's dive in!
Traditional APIs force you to poll endpoints like /messages or /workspaces—inefficient, costly, and latency-heavy. Webhooks flip the script: Claude hits your endpoint when stuff happens.
Key Benefits for Enterprise:
Pro tip: Webhooks pair perfectly with Claude's 200k+ token context windows in Opus—ideal for enterprise agents processing massive docs.
Before coding:
pip install anthropicnpm install @anthropic-ai/sdkYou'll need a server to receive POST requests from hooks.anthropic.com.
Webhooks are tied to your account or specific workspaces. Use the SDK to create one.
import anthropic
import os
client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
webhook = client.webhooks.create(
name="enterprise-notifications",
url="https://yourapp.com/claude-webhook",
events=["message.completed", "tool_called", "workspace.updated"],
workspace_id="ws_123" # Optional: scope to a workspace
)
print(f"Webhook ID: {webhook.id}")
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const webhook = await client.webhooks.create({
name: 'enterprise-notifications',
url: 'https://yourapp.com/claude-webhook',
events: ['message.completed', 'tool_called', 'workspace.updated'],
workspaceId: 'ws_123' // Optional
});
console.log(`Webhook ID: ${webhook.id}`);
Boom—your endpoint is live! Claude will POST JSON payloads on triggers.
Your server must:
event_id).All payloads look like:
{
"event_id": "evt_abc123",
"type": "message.completed",
"data": {
"message_id": "msg_456",
"content": [...],
"workspace_id": "ws_123"
},
"timestamp": 1735689600,
"signature": "sha256=..."
}
from flask import Flask, request, abort
import hmac
import hashlib
app = Flask(__name__)
WEBHOOK_SECRET = os.getenv("WEBHOOK_SECRET") # From webhook creation
@app.route('/claude-webhook', methods=['POST'])
def webhook():
sig = request.headers.get('X-Anthropic-Signature')
body = request.get_data()
# Verify signature
expected_sig = 'sha256=' + hmac.new(
WEBHOOK_SECRET.encode(), body, hashlib.sha256
).hexdigest()
if not hmac.compare_digest(sig, expected_sig):
abort(401)
event = request.json
if event['type'] == 'message.completed':
print(f"Message {event['data']['message_id']} done!")
# e.g., notify Slack
elif event['type'] == 'tool_called':
tool_result = event['data']['tool_result']
# Process tool output
elif event['type'] == 'workspace.updated':
print(f"Workspace {event['data']['workspace_id']} changed.")
return '', 200
import express from 'express';
import crypto from 'crypto';
const app = express();
app.use(express.raw({ type: 'application/json' }));
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET!;
app.post('/claude-webhook', (req, res) => {
const sig = req.headers['x-anthropic-signature'] as string;
const body = Buffer.from(req.body);
const expectedSig = 'sha256=' + crypto
.createHmac('sha256', WEBHOOK_SECRET)
.update(body)
.digest('hex');
if (!crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expectedSig))) {
return res.status(401).send('Invalid signature');
}
const event = JSON.parse(body.toString());
switch (event.type) {
case 'message.completed':
console.log(`Message ${event.data.message_id} completed`);
// Integrate with n8n/Zapier
break;
case 'tool_called':
console.log('Tool result:', event.data.tool_result);
break;
case 'workspace.updated':
// Sync to your DB
break;
}
res.status(200).send('OK');
});
Test with ngrok: ngrok http 3000 and update your webhook URL.
Start a long message or tool call:
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[{"role": "user", "content": "Analyze this 50k doc..."}],
tools=[{"name": "fetch_data", "input_schema": {...}}],
webhook_id="wh_abc" # Ties to your webhook
)
Watch your logs—events fire on completion/tool use/workspace edits (e.g., via Console).
High Availability:
Security:
Integrations:
slack-sdk to post on message.completed.Monitoring: Log event_id for deduping. Use Datadog/Prometheus for webhook uptime.
Edge Cases:
message.stream_end event.tool.failed with retry payloads.workspace.member_added.Claude API Webhooks are a 2025 must-have for any serious integration. You've got the code—now build! Drop questions in the comments or hit up Anthropic's Discord. For more, check our Claude Code and API SDK guides.
Happy coding! 🚀
(Word count: ~1450)
Build natural voice agents combining Claude API's superior reasoning with ElevenLabs' lifelike TTS. This end-to-end guide creates a conversational web app with STT, AI chat, and speech synthesis.
As data volumes explode in 2025, choosing between Claude's reasoning depth and Mistral Large 2's efficiency is critical. We benchmark SQL generation, visualizations, and large datasets to reveal the w
In the high-stakes world of cybersecurity, rapid threat modeling and incident response can mean the difference between containment and catastrophe. Discover how Claude Enterprise empowers security tea
Refactoring sprawling codebases manually? Harness Claude Code's power in VS Code with custom commands to automate AI-driven refactors across TypeScript and Python projects—saving hours of drudgery.
Build blazing-fast smart contract auditing agents in Rust using the Claude SDK. Harness Claude's reasoning to scan Solidity code for vulnerabilities like reentrancy and overflows.
Elevate team productivity with Claude Artifacts in multi-user projects—enable real-time iterative editing for code reviews and docs without leaving the interface.
Workflows from the Neura Market marketplace related to this Claude resource