dead-code

A command that finds functions, classes, state definitions, and endpoints with no detected connections to the rest of a codebase. These are possible unused pieces of code, while known framework entry points are excluded.

In plain words
What is it for?
Use it to scan a selected path, list orphaned functions, classes, state atoms, and endpoints, and review the file and code element behind each result.
Why use it?
It helps locate code that may be safe to remove or investigate. This can make cleanup more targeted than searching files manually.

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/dead-code
Clone the repo
git clone --depth 1 https://github.com/cognitx-leyton/codegraph

Made for: Claude Code.

Per session 19 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 968 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.00019 $0.00968
Opus 5 $0.00010 $0.00484
Sonnet 5 $0.00004 $0.00194
Haiku 4.5 $0.00002 $0.00097

Measured yesterday against content hash 94fac24ff205, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

dead-code 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 yesterday.

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/dead-code.md · 69 lines

How it starts

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

Usage

/dead-code [path_prefix]

Scope defaults to codegraph/codegraph/ if no prefix is given. Pass any string that matches a :File.path prefix to scope elsewhere (e.g. packages/twenty-server/src/engine/).

Returns four categories of orphan, each tagged with a kind column so you can scan them together:

Kind What it means
orphan_function :Function with no incoming CALLS / RENDERS and no outgoing DECORATED_BY (i.e. not a Typer / MCP / pytest entry point)
orphan_class :Class with no incoming EXTENDS, INJECTS, RESOLVES, or IMPORTS_SYMBOL
orphan_atom :Atom with no READS_ATOM or WRITES_ATOM consumers (React state defined but never used)
orphan_endpoint :Endpoint with no HANDLES method (route declared but unhooked)

What this does

PREFIX="${ARGUMENTS:-codegraph/codegraph/}"

codegraph query "
MATCH (f:Function)
WHERE f.file STARTS WITH '$PREFIX'
  AND NOT EXISTS { ()-[:CALLS]->(f) }
  AND NOT EXISTS { ()-[:RENDERS]->(f) }
  AND NOT EXISTS { (f)-[:DECORATED_BY]->(:Decorator) }
RETURN 'orphan_function' AS kind, f.name AS name, f.file AS file
UNION ALL
MATCH (c:Class)
WHERE c.file STARTS WITH '$PREFIX'
  AND NOT EXISTS { ()-[:EXTENDS]->(c) }
  AND NOT EXISTS { ()-[:INJECTS]->(c) }
  AND NOT EXISTS { ()-[:RESOLVES]->(c) }
  AND NOT EXISTS { (:File)-[:IMPORTS_SYMBOL {symbol: c.name}]->(:File) }
RETURN 'orphan_class' AS kind, c.name AS name, c.file AS file
UNION ALL
MATCH (a:Atom)
WHERE a.file STARTS WITH '$PREFIX'
  AND NOT EXISTS { ()-[:READS_ATOM]->(a) }
  AND NOT EXISTS { ()-[:WRITES_ATOM]->(a) }
RETURN 'orphan_atom' AS kind, a.name AS name, a.file AS file
UNION ALL
MATCH (e:Endpoint)
WHERE e.file STARTS WITH '$PREFIX'
  AND NOT EXISTS { (:Method)-[:HANDLES]->(e) }
RETURN 'orphan_endpoint' AS kind, (e.method + ' ' + e.path) AS name, e.file AS file
ORDER BY kind, file, name
LIMIT 100
"

Caveats

  • Decorator exclusion is load-bearing. Without the DECORATED_BY filter, every @mcp.tool(), @app.command(), @pytest.fixture, @staticmethod function shows up as "orphan" because framework dispatchers invoke them via reflection. Keep the filter even if it occasionally hides a genuinely-dead decorated function.
  • Python module-level callers aren't tracked. The Python parser doesn't emit CALLS from top-level code (Stage 1 limitation — resolver's Phase 4 requires a method-scoped caller). So a Python function called only from module-level if __name__ == "__main__": blocks will appear as orphan. Spot-check before deleting.
  • Interface / Protocol implementations. A class that only "satisfies" a duck-typed protocol (no EXTENDS edge, no explicit import) will show as orphan_class. For abstract-base-class compliance, use /graph "MATCH (c:Class {name:'Foo'})-[:EXTENDS]->(p:Class) RETURN p" to double-check.
  • 100-row limit. Raise it for exhaustive cleanup passes.

Read the full file on GitHub · 69 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. yesterday First seen · 69 lines · 19 tokens per session scan A 94fac24ff205

Subscribe to this mod's changes

dead-code is a command published in the GitHub repository cognitx-leyton/codegraph (11 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 19 tokens to every session and 968 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.