Perform Static Call Graph Trace Before Modifying Code

Generate a clear visual map of function calls and file dependencies to identify exactly where your changes will ripple before you type a single line of code.

Agent prompt for Claude and ChatGPT

Prompt

Prompt
You are a senior software architect. Before we modify any code in this repository, perform a static call-graph trace for the specific function or class I will identify. Follow these rules: 1. Trace the execution path across all affected files. 2. For every step, list the file path, the function name, and the specific variables being passed. 3. Visualize the flow using a text-based hierarchy. 4. Identify potential side effects or breaking changes in downstream dependencies. 5. Do not suggest code changes yet; only provide the structural analysis. Please start by asking me: 1. What is the entry point function or class method? 2. What is the specific goal of the modification you are planning? This analysis is not a substitute for running a debugger or unit tests; always verify changes in a local dev environment. Wait for my answers before proceeding.

Example output

Call flow from calculateDiscountOrder of calls traced before changing the method
  1. calculateDiscountEntrycartService.js, takes cartId and couponCode
  2. getCartByIdCall 1cartModel.js, returns CartObject
  3. validateCouponCall 2pricingEngine.js, returns DiscountObject
  4. updateCartTotalCall 3cartService.js, takes cartId and newTotal

Example for: modifying the calculateDiscount method in a Node.js e-commerce backend. ### Call Graph Analysis: calculateDiscount

  1. Entry Point: src/services/cartService.js -> calculateDiscount(cartId, couponCode)

    • Variables: cartId (UUID), couponCode (String)
  2. Dependency 1: src/models/cartModel.js -> getCartById(cartId)

    • Variables: cartId
    • Returns: CartObject (includes items and subtotal)
  3. Dependency 2: src/utils/pricingEngine.js -> validateCoupon(couponCode, subtotal)

    • Variables: couponCode, subtotal (Number)
    • Returns: DiscountObject (percentage, expiryDate)
  4. Dependency 3: src/services/cartService.js -> updateCartTotal(cartId, newTotal)

    • Variables: cartId, newTotal (Number)
Execution Flow

[cartService.js] calculateDiscount
|--> [cartModel.js] getCartById
|--> [pricingEngine.js] validateCoupon
|--> [cartService.js] updateCartTotal

Potential Risks
  • Modifying calculateDiscount will impact the internal state of CartObject in cartModel.js.
  • The pricingEngine.js expects a numeric subtotal; if calculateDiscount returns a float, rounding errors may occur in updateCartTotal.
  • Downstream: The checkoutController.js relies on the return value of updateCartTotal to trigger payment processing; changing this signature will break the controller.
Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces a structural view before implementation.
  • Requires explicit variable tracking across files.
  • Identifies downstream dependency risks early.

Use this in Cursor or Claude to understand complex codebases before refactoring. Paste the prompt, answer the two questions, and verify the generated map against your IDE's actual file structure. Works best in Cursor Chat or Composer.

Common edits

  • Add a rule to list specific line numbers for each function call.
  • Ask the model to include a list of relevant unit tests to check after the change.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

More in Cursor
Coding

Trace an execution path from entry to database

Map out the complete end-to-end execution path of a single user request across layers in an unfamiliar codebase.

Decompose Framework Migrations into Subagent Work Batches

You get a structured task graph that maps migration steps into isolated, low-risk subagent work batches with defined file boundaries and interface contracts.

Coding

Refactor Pasted Code for Readability Without Changing Its Behavior

Returns a cleaner version of your code plus a change log that explains each edit, why behavior is preserved, and which edge cases you should test.

Coding

Plan an incremental refactor for legacy code

Break down monolith or fragile legacy modules into safe, testable milestones using branch-by-abstraction patterns.

Automation & Workflows

Decompose monolithic automation into modular subflows

Restructure overly complex, branched automations into clean parent-child workflows. Use this when your workflow breaks frequently, times out, or has become impossible to maintain.

Compare Three Feature Architectures Against Module Boundaries

Get a scored trade-off matrix comparing three feature architectures by file touchpoints, coupling risks, and rollback cost before running Cursor Composer.