Skip to main content
Glama

find_dead_code

Detects C/C++ functions defined but never called or referenced across the indexed codebase, distinguishing dead and possibly dead symbols from usage so you can verify candidates before deletion.

Instructions

Find C/C++ functions that are defined but never called — libclang-powered dead code detection across the entire indexed codebase. Distinguishes called from uncalled symbols globally, not just within a single file — text-based search cannot determine whether a function is actually reachable.

What "dead" means: zero references of any ref_kind in the index — no call, no read, no function-pointer use, no vector slot. Only functions, methods, constructors, and destructors with a definition are checked. This is a single-layer reference check, NOT a reachability analysis from the entry points (main, ISR, exported symbols): a function that only a second dead function calls still has a reference, thus this tool does not mark it. For transitive reachability, trace from your entry points with find_callees_recursive.

The status field splits the results:

  • "dead" — no reference at all. Likely unused.

  • "possibly_dead" — assigned to a function pointer (ref_kind="indirect") and never called directly, but no call site through that pointer resolved. Unindexed code or a type-erased API can still call it. Treat it as uncertain, and check each hit with find_indirect_targets before you delete anything.

A call that reaches a function by its type only (origin "type_only" in find_callers) is a call too: the function is not reported, also when no code really calls it through that pointer.

fw-context records the constructor call of an object at namespace or class scope as an implicit_construct reference, and the constructor call of a local object, a new-expression or a member initializer as a call. A construction that the source does not write has no reference: the default construction of a member that a constructor does not name, and the member constructions of an implicit constructor. A constructor that only such constructions call can show as dead; check its class with find_references before you delete it.

ISRs: a handler that an assembly vector table names (.word) has a vector reference, and one that NVIC_SetVector installs has a runtime_vector reference, thus neither is reported. A handler in a table that the build generates in C has an indirect reference and can show as possibly_dead. A handler that no readable table names (a slot with a linker-resolved address; arm64, Xtensa, MIPS tables of branch instructions) shows as dead. Use get_vector_table to check.

Other known false positives: constructors from factories, virtual method overrides, and weak-aliased symbols. Always verify before you delete.

project_only=True (default) excludes the SDK and vendor paths through the is_project column, which follows the vendor_paths and project_paths config. Set project_only=False to see the vendor results too. No config default is added to exclude_paths.

Read-only. No side effects. Requires the reference index (fw-context index — refs on by default).

Args: project_root: Project root. Auto-detected if omitted. project: Project name or project_id — call list_projects to get them. Use it to ask about a project that is not the project of the current directory. It is an alternative to project_root, which takes a root path. Give one of the two, not both. limit: Maximum results of one page (default 100, max 200). offset: Skip this many results. Reads the next page; the page notice names the offset to use. exclude_paths: Additional LIKE patterns to exclude (user-supplied tool parameter, not config). E.g. ['lib/%']. project_only: When True (default), filters to is_project = 1 symbols. Set False to see all results. variant: Variant of the build (a board, or a PlatformIO environment). On a project of more than one build, give the arguments of one build as the refusal lists them: the variant, the image, or the two. fw-context does not select a build. One query answers for ONE build. image: Image of the build: a separate program, such as the application or the bootloader. Give it when the build has an image name.

Returns: The page notice first — total, offset, shown, more — then a dict per function with: name, qualified_name, kind, signature, file (str — absolute), line, status ("dead" or "possibly_dead"), and reason (str — explains why the function is classified as dead or possibly dead). A "possibly_dead" row also holds indirect_refs (str — up to 3 file:line pointer uses, absolute paths, joined with ", "). "dead" rows come first.

Never empty: one dict with ``error`` or ``info`` replaces an empty
result.  Check both keys first.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "find_dead_code"
  }
}

Input Schema

NameRequiredDescriptionDefault
imageNoImage of the build: a separate program, such as the application or the bootloader. On a project of more than one build, give it when that build has an image name, as the refusal lists it.
limitNoMaximum results of one page (default 100, max 200).
offsetNoSkip this many results. Reads the next page of a long report.
projectNoProject name or project_id — call list_projects to get them. Use it to ask about a project that is not the project of the current directory. It is an alternative to project_root, which takes a root path. Give one of the two, not both.
variantNoVariant of the build (a board, or a PlatformIO environment). On a project of more than one build, give the arguments of one build as the refusal lists them: the variant, the image, or the two. fw-context does not select a build for you. One query answers for ONE build.
project_onlyNoWhen True (default), keeps only project code (is_project, from the vendor_paths/project_paths config and SDK detection). Set False to see all results.
project_rootNoProject root. Auto-detected if omitted. This field also accepts a project name or a project_id, but project is the clear field for those.
exclude_pathsNoLIKE patterns on the project-relative file path to exclude, on top of project_only. E.g. ['lib/%'].

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.32.1
    • changedInput schema / properties / exclude_paths / description
      Previous value: -"Additional LIKE patterns to exclude. Merged with defaults from config. E.g. ['lib/%']."New value: +"LIKE patterns on the project-relative file path to exclude, on top of project_only. E.g. ['lib/%']."
    • changedInput schema / properties / image / description
      Previous value: -"Sysbuild image within the variant. Required when the variant holds several: each image is a separate program."New value: +"Image of the build: a separate program, such as the application or the bootloader. On a project of more than one build, give it when that build has an image name, as the refusal lists it."
    • changedInput schema / properties / project_only / description
      Previous value: -"When True (default), auto-excludes SDK/vendor paths based on the detected build system and applies project config exclude_paths. Set False to see all results."New value: +"When True (default), keeps only project code (is_project, from the vendor_paths/project_paths config and SDK detection). Set False to see all results."
    • changedInput schema / properties / variant / description
      Previous value: -"Build variant (multi-build project). Omit to use default_variant. One query answers for ONE build."New value: +"Variant of the build (a board, or a PlatformIO environment). On a project of more than one build, give the arguments of one build as the refusal lists them: the variant, the image, or the two. fw-context does not select a build for you. One query answers for ONE build."
  2. Changed5 schema fields changedv0.32.0
    • changedInput schema / properties / image / description
      Previous value: -"Sysbuild image name within the variant (multi-project). Omit for all images of the variant."New value: +"Sysbuild image within the variant. Required when the variant holds several: each image is a separate program."
    • changedInput schema / properties / limit / description
      Previous value: -"Maximum results (default 100)."New value: +"Maximum results of one page (default 100, max 200)."
    • addedInput schema / properties / limit / minimum
      Added value: +1
    • addedInput schema / properties / offset
      Added value: +{
      +  "default": 0,
      +  "description": "Skip this many results. Reads the next page of a long report.",
      +  "minimum": 0,
      +  "title": "Offset",
      +  "type": "integer"
      +}
    • changedInput schema / properties / variant / description
      Previous value: -"Build variant name (multi-project). Omit to use default_variant or fail-closed. Use '*' for all variants."New value: +"Build variant (multi-build project). Omit to use default_variant. One query answers for ONE build."
  3. Changed3 schema fields changedv0.30.0
    • addedInput schema / additionalProperties
      Added value: +false
    • addedInput schema / properties / project
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Project name or project_id — call list_projects to get them. Use it to ask about a project that is not the project of the current directory. It is an alternative to project_root, which takes a root path. Give one of the two, not both.",
      +  "title": "Project"
      +}
    • changedInput schema / properties / project_root / description
      Previous value: -"Project root. Auto-detected if omitted."New value: +"Project root. Auto-detected if omitted. This field also accepts a project name or a project_id, but project is the clear field for those."
  4. Changed2 schema fields changedv0.25.3
    • addedInput schema / properties / image
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Sysbuild image name within the variant (multi-project). Omit for all images of the variant.",
      +  "title": "Image"
      +}
    • addedInput schema / properties / variant
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Build variant name (multi-project). Omit to use default_variant or fail-closed. Use '*' for all variants.",
      +  "title": "Variant"
      +}
  5. Changed1 schema field changedv0.18.2
    • changedInput schema / properties / project_only / description
      Previous value: -"When True (default), auto-excludes SDK/vendor paths (mbed-os/%, .pio/%, zephyr/%, build/%) and applies project config exclude_paths. Set False to see all results."New value: +"When True (default), auto-excludes SDK/vendor paths based on the detected build system and applies project config exclude_paths. Set False to see all results."
  6. Changed2 schema fields changedv0.5.0
    • changedInput schema / properties / exclude_paths / description
      Previous value: -"File path LIKE patterns to exclude. E.g. ['mbed-os/%', 'zephyr/%'] for SDK paths. No default — pass explicitly to filter vendor noise."New value: +"Additional LIKE patterns to exclude. Merged with defaults from config. E.g. ['lib/%']."
    • addedInput schema / properties / project_only
      Added value: +{
      +  "default": true,
      +  "description": "When True (default), auto-excludes SDK/vendor paths (mbed-os/%, .pio/%, zephyr/%, build/%) and applies project config exclude_paths. Set False to see all results.",
      +  "title": "Project Only",
      +  "type": "boolean"
      +}
  7. Changed1 schema field changedv0.2.4
    • addedInput schema / properties / exclude_paths
      Added value: +{
      +  "anyOf": [
      +    {
      +      "items": {
      +        "type": "string"
      +      },
      +      "type": "array"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "File path LIKE patterns to exclude. E.g. ['mbed-os/%', 'zephyr/%'] for SDK paths. No default — pass explicitly to filter vendor noise.",
      +  "title": "Exclude Paths"
      +}
  8. First observedv0.1.0

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are supplied, so the description carries the whole burden and does so: read-only with no side effects, requires the reference index (fw-context index, refs on by default), and a precise definition of "dead" (zero references of any ref_kind, single-layer only, not reachability). It proactively enumerates known false positives (factories, virtual overrides, weak aliases, implicit constructions, vector tables) and warns to verify before deletion.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core statement, then cleanly sectioned (definition of dead, status split, ISR caveats, false positives, Args, Returns), so an agent can stop reading once it has what it needs. It is long, and the Args block repeats schema text that already has 100% description coverage, which is the main wasted space.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an 8-parameter tool with subtle classification semantics, nothing an agent needs is missing: result ordering (dead rows first), the never-empty error/info dict contract, per-row fields including indirect_refs, and the exact meaning of both status values. The Returns section is documented alongside the output schema rather than left implicit.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; the description goes beyond it on the hard parameters — variant/image are mutually-scoped to ONE build with the refusal dict naming them, project vs project_root are stated as mutually exclusive alternatives, and exclude_paths is called out as a tool parameter distinct from config. The limit/offset text largely restates the schema, and the Args block duplicates it verbatim.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ("Find C/C++ functions that are defined but never called") and immediately names the mechanism (libclang, whole-index reference check). It explicitly distinguishes itself from text search and from the sibling that does the complementary job ("For transitive reachability, trace from your entry points with find_callees_recursive").

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit routing rules to alternatives for each ambiguous case: find_callees_recursive for reachability, find_indirect_targets to verify possibly_dead hits, find_references for constructors that only implicit constructions call, get_vector_table for unreadable ISR tables. It also states when to flip project_only and that variant/image must be supplied for multi-build projects.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.