Skip to Content
Launching the open-source gateway

Cursor (tracing)

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 .

Set up Respan

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

Paste this into your coding agent:

Help me set up Respan tracing with the Cursor integration. Follow https://www.respan.ai/docs/integrations/cursor.md

Setup

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

Set environment variables

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

Terminal
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY" export TRACE_TO_RESPAN="true"

Download the hook script

Terminal
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

Configure Cursor hooks

Create ~/.cursor/hooks.json:

JSON
{ "version": 1, "hooks": { "beforeSubmitPrompt": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }], "afterAgentThought": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }], "afterAgentResponse": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }], "afterShellExecution":[{ "command": "python ~/.cursor/hooks/respan_hook.py" }], "afterFileEdit": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }], "afterMCPExecution": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }], "stop": [{ "command": "python ~/.cursor/hooks/respan_hook.py" }] } }

Restart Cursor

Restart Cursor IDE to apply the hooks configuration.

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.

Terminal
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.

Gateway

See Cursor gateway setup  to route Cursor’s chat and agent requests through the Respan gateway.