Cursor

Cursor is an AI-powered code editor with built-in agent capabilities. Respan gives you hierarchical traces of every agent interaction including thinking blocks, file edits, shell commands, and MCP tool calls — captured in real-time via Cursor’s hook system.

Create an account at platform.respan.ai and grab an API key.

Run npx @respan/cli setup to set up with your coding agent.

Setup

Prerequisite: Cursor IDE installed, plus Python 3.8+ with requests.

1

Set environment variables

Add to your shell profile (.bashrc, .zshrc, or PowerShell $PROFILE):

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export TRACE_TO_RESPAN="true"
2

Download the hook script

$mkdir -p ~/.cursor/hooks
$curl -o ~/.cursor/hooks/respan_hook.py \
> https://raw.githubusercontent.com/respanai/respan-example-projects/main/python/dev-tools/cursor/respan_hook.py
3

Configure Cursor hooks

Create ~/.cursor/hooks.json:

1{
2 "version": 1,
3 "hooks": {
4 "beforeSubmitPrompt": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }],
5 "afterAgentThought": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }],
6 "afterAgentResponse": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }],
7 "afterShellExecution":[{ "command": "python ~/.cursor/hooks/respan_hook.py" }],
8 "afterFileEdit": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }],
9 "afterMCPExecution": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }],
10 "stop": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }]
11 }
12}
4

Restart Cursor

Restart Cursor IDE to apply the hooks configuration.

5

View your trace

Open the Traces page to see hierarchical agent traces with thinking, file edits, shell commands, and MCP tool calls.

Hooks reference

HookTriggerData captured
beforeSubmitPromptUser sends promptUser input, start time.
afterAgentThoughtAgent thinkingThinking text, duration.
afterShellExecutionShell command completesCommand, output, duration.
afterFileEditFile editedFile path, edits.
afterMCPExecutionMCP tool completesTool name, input, output, duration.
afterAgentResponseAgent respondsResponse text (creates root span).
stopAgent stopsCleanup.

Span types

Spanlog_typeDescription
RootagentThe complete agent turn.
ThinkinggenerationAgent reasoning blocks.
Shell / File / MCPtoolTool invocations.

Debugging

Check the log file for issues.

$tail -f ~/.cursor/state/respan_hook.log
IssueSolution
No traces appearingCheck TRACE_TO_RESPAN=true is set.
API errorsVerify RESPAN_API_KEY is correct.
Only root spanEnsure all hooks are configured in hooks.json.
Missing thinkingCheck afterAgentThought hook is active.