trace-endpoint

A command that starts with part of an API URL and shows its handler plus the methods that handler calls, up to four steps away. An API URL is the web address software uses to receive requests.

In plain words
What is it for?
Use it to trace routes such as /users, see their handler methods, and inspect the related classes and code they reach.
Why use it?
It removes the need to manually follow code to understand what an endpoint affects. This helps with change-impact checks, security reviews, and learning how a feature works.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/cognitx-leyton/codegraph/trace-endpoint
Clone the repo
git clone --depth 1 https://github.com/cognitx-leyton/codegraph

Made for: Claude Code.

Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 691 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00014 $0.00691
Opus 5 $0.00007 $0.00345
Sonnet 5 $0.00003 $0.00138
Haiku 4.5 $0.00001 $0.00069

Measured 2d ago against content hash ab4c9375ef8c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

trace-endpoint scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/trace-endpoint.md · 60 lines

How it starts

The opening of the file, as written. The whole thing — 60 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Usage

/trace-endpoint <url_substring>

Matches against :Endpoint.path CONTAINS $ARGUMENTS — so partial matches work (/users picks up /users/:id, /users/profile, etc.).

Runs two queries in sequence:

  1. Surface — the matched endpoints and their handler methods (the API shape).
  2. Reach — every method reachable within 4 CALLS hops from each handler, grouped by enclosing class (the data-and-compute reach).

Useful for impact analysis ("what breaks if I change this URL?"), security review ("what does this public endpoint touch?"), and onboarding ("show me a feature end-to-end").

What this does

codegraph query "
MATCH (m:Method)-[:HANDLES]->(e:Endpoint)
WHERE e.path CONTAINS '$ARGUMENTS'
OPTIONAL MATCH (ctrl:Class)-[:HAS_METHOD]->(m)
RETURN 'surface' AS layer,
       e.method AS http_method,
       e.path AS route,
       ctrl.name AS controller,
       m.name AS handler,
       e.file AS file
ORDER BY e.path
LIMIT 20
"

codegraph query "
MATCH (m:Method)-[:HANDLES]->(e:Endpoint)
WHERE e.path CONTAINS '$ARGUMENTS'
MATCH path = (m)-[:CALLS*1..4]->(target:Method)
MATCH (enclosing:Class)-[:HAS_METHOD]->(target)
WITH DISTINCT enclosing.name AS class, target.name AS method, target.file AS file
RETURN 'reach' AS layer, class, method, file
ORDER BY class, method
LIMIT 100
"

Caveats

  • Python has no :Endpoint nodes yet. Stage 1 Python only captures classes / functions / imports / decorators; FastAPI / Flask / Django route detection lands in Stage 2. Running this against a URL from a Python-only project returns zero rows. Document the gap rather than pretending the graph has coverage it doesn't.
  • Only typed CALLS resolve reliably. Python's name-resolved calls (obj.foo() where obj's type isn't known) may miss. TS: this.x() resolves; dynamic dispatch may not.
  • 4-hop bound is a trade-off. Deep call chains (e.g. orchestrator → saga → worker → DB) may exceed it. Raise to *1..6 if you're doing deep security review — slower but more complete.
  • CALLS_ENDPOINT is the inverse — that's the edge for outgoing HTTP calls to an endpoint (e.g. frontend fetching from backend). If you want "who hits this endpoint from elsewhere", query CALLS_ENDPOINT instead.

Read the full file on GitHub · 60 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 60 lines · 14 tokens per session scan A ab4c9375ef8c

Subscribe to this mod's changes

trace-endpoint is a command published in the GitHub repository cognitx-leyton/codegraph (11 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 14 tokens to every session and 691 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.