Keywords AI
Cursor and Claude Code are AI coding assistants that think, edit files, run shell commands, and call tools on your behalf. But you have no visibility into what they're doing. Every thinking block, tool call, and file edit happens without any way to inspect it.
This guide covers how to set up hooks that capture agent activity and send hierarchical traces to Keywords AI.

When you use Cursor or Claude Code, the agent:
Without observability, you can't answer basic questions:
With Keywords AI, every agent turn becomes a hierarchical trace:
cursor_abc123_xyz789 (38.9s) ├── Thinking 1 (0.5s) - "Let me analyze the code..." ├── Thinking 2 (0.3s) - "I should update the function..." ├── Edit: utils.py (0.1s) ├── Shell: npm test (4.1s) ├── MCP: list_logs (0.8s) └── Thinking 3 (0.2s) - "Tests passed, done."
Now you can see exactly what happened in each agent turn.
Both Cursor and Claude Code provide hooks, which are extension points that fire during agent execution:
| Event | Description |
|---|---|
| Before prompt | User submits a message |
| After thinking | Agent produces a reasoning block |
| After tool call | Agent uses a tool (file, shell, MCP) |
| After response | Agent completes its turn |
| Stop | Agent stops (user cancels or completion) |
Our integration uses these hooks to capture events in real-time and send them to Keywords AI as structured traces.
The mental model:
Agent Event → Hook Fires → Python Script → Keywords AI API

Cursor provides rich hooks that fire during agent execution. The architecture captures events as they happen:
| Hook | Trigger | Data Captured |
|---|---|---|
beforeSubmitPrompt | User sends prompt | User input, start time |
afterAgentThought | Agent produces thinking | Thinking text, duration |
afterShellExecution | Shell command completes | Command, output, exit code |
afterFileEdit | File edited | File path, edits, diff |
afterMCPExecution | MCP tool completes | Tool name, input, output |
afterAgentResponse | Agent responds | Response text (creates root span) |
Cursor hooks fire in real-time. Each event arrives as it happens, so you get streaming observability into agent behavior.
Setting up Cursor observability takes just 3 steps:
KEYWORDSAI_API_KEY, TRACE_TO_KEYWORDSAI)~/.cursor/hooks/
Claude Code takes a different approach. Instead of real-time hooks, it stores conversation transcripts as JSONL files. The hook fires after the agent response completes:
Claude Code uses a Stop hook that triggers after each agent turn. The hook script:
This post-hoc approach means Claude Code captures richer metadata (like token counts) that aren't available during streaming.
Setting up Claude Code observability takes just 3 steps:
KEYWORDSAI_API_KEY, TRACE_TO_KEYWORDSAI)~/.claude/hooks/👉 Full Claude Code Setup Guide →
Both integrations capture rich observability data and organize them as hierarchical spans:
| Span | log_type | Description |
|---|---|---|
| Root | agent | The complete agent turn |
| Thinking | generation | Reasoning blocks |
| Tool | tool | File/shell/MCP invocations |
| Data | Description |
|---|---|
| User prompt | What you asked the agent |
| Assistant response | The agent's final response |
| Thinking blocks | Reasoning/planning content |
| Tool calls | File reads, writes, shell commands, MCP tools |
| Timing | Start time, end time, duration per span |
Claude Code captures additional metrics not available in Cursor:
| Data | Description |
|---|---|
| Token usage | Prompt tokens, completion tokens, cache tokens |
| Model name | Which model was used (e.g., claude-sonnet-4-20250514) |
| Cache info | Cache creation and read tokens |
Example workflows:
When you ask the agent to solve a problem differently:
| Feature | Cursor | Claude Code |
|---|---|---|
| Hook type | Multiple real-time hooks | Single Stop hook |
| Data source | JSON via stdin | JSONL transcript files |
| Timing | Real-time (as events happen) | Post-hoc (after response) |
| Token usage | Not available | Full usage details |
| Cache info | Not available | Cache creation/read tokens |
| MCP support | Yes | Yes |
Both tools give you full observability into agent behavior. The main difference is that Claude Code also captures token usage, which is useful for cost tracking.
With Keywords AI hooks, you get:
Setup takes about 5 minutes.