codegraph: Command for Claude Code

.claude/commands/dead-code.md

dead-code is a command for Claude Code from cognitx-leyton/codegraph. It costs 19 tokens per session (968 once invoked), scanned A, original, Apache-2.0.

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

Written for Claude Code: allowed-tools in frontmatter.

This is cognitx-leyton/codegraph's own configuration. It tells Claude Code how to work on codegraph itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything codegraph configures →

Reuse

Borrowing it

Nothing to install: this file belongs to cognitx-leyton/codegraph. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/cognitx-leyton/codegraph/main/.claude/commands/dead-code.md
Clone the repo
git clone --depth 1 https://github.com/cognitx-leyton/codegraph

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for dead-code

README.md
[![agentmods](https://agentmods.dev/badge/commands/cognitx-leyton/codegraph/dead-code/github.svg)](https://agentmods.dev/commands/cognitx-leyton/codegraph/dead-code)
Your own site
<a href="https://agentmods.dev/commands/cognitx-leyton/codegraph/dead-code"><img src="https://agentmods.dev/badge/commands/cognitx-leyton/codegraph/dead-code/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for dead-code

Your own site · 80×15
<a href="https://agentmods.dev/commands/cognitx-leyton/codegraph/dead-code"><img src="https://agentmods.dev/badge/commands/cognitx-leyton/codegraph/dead-code.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
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. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00019 $0.00968
Opus 5.5 $0.00008 $0.00387
Sonnet 5.5 $0.00004 $0.00194
Haiku 4.5 $0.00002 $0.00097

Measured 2mo ago against content hash 94fac24ff205, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 2mo 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/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. 2mo ago 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 (12 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 19 tokens to every session and 968 once invoked, about $0.0001 per session on Opus 5.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.