Back to Rules

🧠 Cursor Rule — Follow Chain of References for Debugging and Comprehension

OfficialPopular
CursorCode Navigation & Refactoring
cursornavigationdebuggingcode-analysis

Goal

Trace logic across files and modules to understand data flow, function calls, and dependencies so you can debug confidently and refactor safely.

Rule Behavior

1️⃣ Start From a Clear Entry Point

  • Identify the initiating call (API route, event handler, or UI action)
  • Ask the Agent to list the entry function and its immediate callers or callees

2️⃣ Follow Calls Across Module Boundaries

  • Trace imports and exported functions to find the next hop in the chain
  • Continue until you reach persistence, side effects, or external I O
  • Mark places where data shape changes or is transformed

3️⃣ Map Data Flow and Transformations

  • Record how key objects move and change across functions
  • Note mutations, conversions, and where validation occurs
  • Highlight boundary crossings like serialization, network, or DB writes

4️⃣ Detect Hidden Side Effects and Shared State

  • Identify modules that mutate global state or rely on singletons
  • Flag implicit dependencies or hidden I O that affect reproducibility
  • Prefer pure function refactors where feasible

5️⃣ Document the Chain for Future Reference

  • Create a short chain summary with steps and key variables at each hop
  • Save the trace in the repo or PR to help reviewers and future debuggers

6️⃣ Use Execution to Validate the Trace

  • Run small, isolated executions of each hop to confirm assumptions
  • Ensure the observed runtime behavior matches the traced chain

Examples

  • "Follow chain of references from API handler to DB write and list every transformation."
  • "Trace this event emitter to all subscribers and show the order of operations."
  • "Show where this object is mutated across the codebase."

Tool Prompts

  • "Follow chain of references starting at src/api/orders.ts:placeOrder and summarize each step."
  • "List all files that import this function and indicate which ones call it."
  • "Produce a step by step trace including variable snapshots for each hop."

Quick Implementation Wins

  • Start by tracing the five most frequently failing endpoints
  • Attach chain summaries to PRs that modify core flows
  • Add small runnable snippets to validate each link in the chain
View Tool Page