Skip to main content
Glama

find_dead_code

Identify C/C++ functions defined but never called across the indexed codebase, using global reference analysis to distinguish dead code from possible indirect-call targets.

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: A function with zero references in the index — no calls, no function-pointer assignments, no indirect call sites. This is a single-layer reference check, not a reachability analysis from entry points (main, ISR, exported symbols). A function that is only called by another dead function will NOT be marked as dead (it has a reference). If you need transitive reachability, manually trace from your entry points using find_callees_recursive.

Returns two categories of results, each with a status field:

  • "dead" — no references at all (neither calls nor function pointer assignments). Likely unused.

  • "possibly_dead" — the function is assigned to a function pointer (Phase 1 ref_kind="indirect") but no call site through that pointer was resolved (Phase 3). This means the function MIGHT be called through unindexed code or a type-erased API. LLM should treat this as uncertain, not as confirmed dead code. Verify each hit with find_indirect_targets before deleting.

Implicit constructor calls through global/static object and member-field initialization are detected as implicit_construct references. Known remaining false positives: constructors called via factories, ISRs, virtual method overrides, and weak-aliased symbols. Always verify before deleting.

By default, SDK/vendor paths are auto-excluded via the is_project column (which respects project config vendor_paths and project_paths). Use project_only=False to see all results including vendor code.

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. limit: Maximum results (default 100). 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.

Returns: list of dicts, each with: name, qualified_name, kind, file, line, status ("dead" or "possibly_dead"), and reason (str — explains why the function is classified as dead or possibly dead).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageNoSysbuild image name within the variant (multi-project). Omit for all images of the variant.
limitNoMaximum results (default 100).
variantNoBuild variant name (multi-project). Omit to use default_variant or fail-closed. Use '*' for all variants.
project_onlyNoWhen 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.
project_rootNoProject root. Auto-detected if omitted.
exclude_pathsNoAdditional LIKE patterns to exclude. Merged with defaults from config. E.g. ['lib/%'].

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior5/5

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

With no annotations provided, the description fully carries the transparency burden. It discloses read-only behavior, the exact definition of 'dead' (zero references), the two result statuses with their implications, implicit constructor handling, and known false positives (factories, ISRs, virtual overrides, weak aliases). This is exceptionally transparent.

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

Conciseness5/5

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

The description is long but every sentence earns its place. It uses clear section labels ('What "dead" means', 'Returns two categories', 'Known remaining false positives') and front-loads the core purpose. No filler or tautology—each paragraph adds distinct, actionable information.

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?

The description is complete for a complex tool: it covers the exact semantics of dead vs possibly_dead, the return format, false positives, index prerequisites, and when to use alternative tools. Given the rich output schema and no annotations, this description leaves little ambiguity for an agent to invoke and interpret results.

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 description coverage is 100%, so the baseline is 3. The description adds meaningful nuance for `project_only` (mentions the `is_project` column and config respect), clarifies `exclude_paths` as a user-supplied parameter (not config), and explains the default vendor path exclusion behavior. It does not cover `image` and `variant`, but those are already well-documented in the schema.

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?

The description opens with a specific verb+resource: 'Find C/C++ functions that are defined but never called — libclang-powered dead code detection across the entire indexed codebase.' It clearly distinguishes from text-based search and other sibling tools by emphasizing global reference analysis, so the purpose is unmistakable.

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?

The description gives explicit guidance on when to use this tool vs alternatives: it warns that 'text-based search cannot determine whether a function is actually reachable,' and points to `find_callees_recursive` for transitive reachability and `find_indirect_targets` for verifying uncertain hits. It also instructs to always verify before deleting, providing clear usage boundaries.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/turbyho/fw-context-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server