danny-sg/internals-viewer / .claude/skills/unused-code
unused-code
VerifiedFinds unused types and members in Internals Viewer projects by Roslyn reachability from production code, where code reached only from tests or from other unused code counts as unused, then removes them without losing test coverage. Use whenever the user asks whether a type or member is used, asks to find, review or remove unused, dead, leftover or test-only code in a project, or says unused types keep being missed, even when they name only one type.
Unused code
A type is unused when no live production code reaches it. Searching for its name is not enough. MemoryHistorySummary
was named in production code, but only by MemoryHistoryStore.GetSummary, and only tests called that. A name search
also cannot tell overloads apart, so a hit for GetRanges says nothing about the one-argument GetRanges.
The analyser in scripts/UnusedCodeAnalyser loads the whole solution with Roslyn and follows references from production
code. It reports what nothing reaches. Every finding still gets checked by hand before it goes in the report.
Run the analyser
Pass the assembly names to review. Every other non-test project in the solution counts as a user of them, so UI.App and the MCP server keep alive whatever they call.
dotnet run --project .claude/skills/unused-code/scripts/UnusedCodeAnalyser -- src/InternalsViewer.slnx <output directory> InternalsViewer.Query InternalsViewer.Query.FullTrace
Put the output directory in the scratchpad. A run takes one to two minutes, so give the command a 10 minute timeout.
The analyser builds the source generators into bin\analysis and obj\analysis, then loads every project with those
folders as its output. It never touches the default bin and obj folders, and it deletes the analysis folders when it
finishes. The analysis runs in a child process because the generator DLLs stay locked until that process exits.
Check the project lines before reading the reports. Every project should show 0 errors. Exit code 2 means a project
did not compile. References from its broken code are then missing, so a finding may be false. Workspace messages about
.vcxproj files and unresolved assemblies are filtered out because they are expected.
| File | What it lists |
|---|---|
types.txt | Types nothing live reaches, with who still names them |
members.txt | Members of live types that nothing live reaches, including positional and layout ones |
members-by-file.txt | The same members grouped by file, without positional record properties or native layout fields |
removals.tsv | The members-by-file.txt list as input for the remover |
implemented-only.txt | Interfaces that types implement but nothing uses as a type |
never-constructed.txt | Live classes that no live code constructs |
registration-only.txt | Types whose only use is a DI registration |
Each finding has a status. no references means nothing names it. tests only means only tests use it. only from dead code means production code names it, but only from code that is itself unused.
Check every finding
The analyser follows syntax, so verify each finding before reporting it.
- Types. Search non-test
srcfor the name, including.xaml. Read each hit and confirm it is the same type and not another type of the same name. - Members. Search for the name. A hit is often a different overload or another type's member, so read the call before deciding the analyser is wrong. When the analyser and a name search disagree, the analyser is usually right.
implemented-only.txt. These are real findings.IEventParser<TEvent>was implemented by 13 parsers, but everyMapwas called on the concrete class.never-constructed.txt. These are mostly not findings. DI creates services registered inApp, marshalling createsSafeHandletypes,Activatorcreates the export converters, and some classes only have static members. A class that only has static members is worth mentioning, because it could be astatic class.registration-only.txt. These are types registered in DI that nothing injects. Check the registration code before calling one unused.
These look unused to the analyser but are not:
- Positional record properties. Record equality and hashing read them, and records such as
SymbolKeyandLockIdentityare dictionary keys. They are left out ofmembers-by-file.txtandremovals.tsv. - Native layout fields. Fields such as
Reservedkeep the struct layout the native bridge writes. These are also left out. - Properties read by reflection. System.Text.Json serialises exported types.
ExportPackagefinds every non-abstractEngineEventandLogRecordtype withGetTypes. Before removing a property from a type reachable fromQueryExport, check whether removing it changes the export. - String bindings in code-behind. XAML
{x:Bind}and{Binding}names are counted, but aPropertyPath("Name")built in C# is not. Search for the name in quotes.
Report
The review ends with a report. Remove nothing until the user agrees. Use this shape:
- A table of unused types: the type as a link to its declaration, and why nothing live reaches it.
- For each cluster, the members that would go with it. For example, removing a type also removes the test-only method that returns it.
- The members from
members-by-file.txt, summarised by area with counts and the most notable ones. Give the path of the full file. - What the run could not see: projects that did not compile, properties that may be serialised, and the fact that a use from unused code in another project still counts as a use.
Remove
Work in this order. Each removal can leave more code unused, so the last step loops back.
-
Whole types. Delete the file of a top-level type. Remove a nested type with the remover by giving the line its name is declared on.
-
Members. Trim
removals.tsvto what the user agreed to remove. Then run the remover withsrcas the root:dotnet run --project .claude/skills/unused-code/scripts/MemberRemover -- src <path to removals.tsv>It removes each member with its doc comment and keeps the file's line endings and BOM. It refuses a file when a line does not declare the named member. Line numbers only match the run that wrote
removals.tsv, so run the analyser again after editing a file and before removing more from it. -
Follow-ups the remover cannot make.
- Remove
usingdirectives that are no longer needed. - A primary constructor parameter that only fed a removed property is now unread.
KeyHashLookuplost its logger this way and became astatic class. - Data that only fed a removed reader can go too.
TraceRowReturnMarkMapkept a second copy of every mark forGetCountandGetMarks, so removing them removed the copy, andCountnow comes fromTicks.
- Remove
-
Build the reviewed projects, then build every test project that references them.
-
Fix the tests. A test of a removed feature goes, or only its assertion goes when the rest of the test covers live code. A test that used a removed convenience overload to set up or observe live code keeps its coverage:
- Switch it to the production overload when one exists.
ParseEvent(string)becameParseEvent(buffer, length). - Otherwise move the overload into the tests. Make it an extension method in the project's existing helper class, so
the call sites do not change.
TraceCallStore.Builder.Add(span)moved toTraceCallRowHelperandTraceCallRows. For a static method or a property, add a helper at the test project root, asFunctionSignatureHelperandTraceTickSeriesHelperdid. - A helper that needs private state may make that member
internal, since the test projects haveInternalsVisibleTo. Say so in the summary.
- Switch it to the production overload when one exists.
-
Run the analyser again and repeat until it finds nothing new.
-
Run the affected test suites. The
testingskill has the commands and the known failures. -
Final checks.
- Every edited file keeps its line endings. Use the remover or Python with
newline="", neversed -i. - Lines stay within 140 characters. A rename shifts the continuation lines aligned under a call, so realign them.
- Search for comments and
crefs that name removed members. Comments belong to their author, so list them for the user rather than editing them.
- Every edited file keeps its line endings. Use the remover or Python with
Limits
- The reviewed projects need users. UI.App and the MCP server are entry points, so this cannot review them. Reflection, XAML and the MCP SDK reach their code in ways the analyser does not see.
- Code in another project counts as a use even when that code is itself unused.
- Unused
usingdirectives and unread parameters are not reported.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |