Code without the clutter.

Code Janitor is two independently maintained extensions, one for Visual Studio and one for VS Code. They remove repetitive C# clutter, modernize syntax and apply shared rules, so nobody has to hunt for small issues by hand.

Platforms
Visual Studio 2026 · VS Code
Language
C#
License
LGPL-3.0

Why does it exist?

Large C# repositories do not become messy only through large mistakes. Over time they collect small inconsistencies: whitespace, usings in the wrong order, older syntax, missing explicit modifiers, regions, untidy namespaces and missing documentation. Each item is trivial, but fixing thousands of them by hand takes time and is rarely done consistently.

Code Janitor automates that repetitive part of the work. Instead of a one-off tidy-up just before review, you define rules, choose a scope and get a predictable set of changes to check.

Two editors, two feature sets.

Implementation

Visual Studio

GitHub ↗

An extension for cleaning, organizing and navigating code in Visual Studio 2026. It uses the Roslyn that Visual Studio ships, so cleanup sees the code the way the compiler does.

  • whitespace normalization, Visual Studio formatting, using organization and sorting; moving using directives into or out of the namespace with names resolved by the Roslyn semantic model
  • explicit access modifiers, namespace fixing, conversion to file-scoped namespaces (C# 10+) and region removal
  • .editorconfig-driven diagnostic cleanup: only rules the repository configures (suggestion, warning, error) are fixed, using the code fixes already in Visual Studio and the project’s analyzers; compiler diagnostics are never touched
  • post-cleanup verification: a fix that would add a compiler error is rejected, and unresolved diagnostics are reported
  • cleanup on demand, on save or for a selected scope with a one-time options dialog; C# changes previewed as a native diff with per-file and per-rule selection
  • safe Razor/Blazor formatting, including @if/@else, loops, @switch and @try/@catch/@finally
  • optional AI-assisted XML documentation with explicit scope, filters, budgets and secure settings
  • settings precedence .editorconfig → .codejanitor → user settings; more than 190 options in 21 categories under Tools › Options; export and import of the .codejanitor policy
  • navigation: active file in Solution Explorer, related files, recursive tree collapse, McCabe complexity

Requires Visual Studio 2026 (18.0 or newer; Community, Professional, Enterprise; 64-bit) and .NET Framework 4.7.2. Visual Studio 2022 is not supported and the installer rejects it: the extension uses Roslyn 5.0, first shipped with Visual Studio 2026. Install from the .vsix on GitHub Releases.

Implementation

VS Code

GitHub ↗

A lightweight local C# cleanup engine that needs no .NET runtime, with optional AI actions on demand.

  • cleanup of a single file, selection, multiple files, open files, Git-changed files or the whole workspace
  • cleanup-on-save for automatically keeping supported files tidy while you work
  • C# syntax modernization including var, pattern matching and collection expressions
  • generate/remove XML documentation, fix namespaces, format comments and remove regions
  • Split Top-Level Types for classes, interfaces, records, enums and delegates
  • repository policy through .codejanitor, with explicit VS Code settings taking precedence
  • coverage report analysis and test generation focused on uncovered code
  • optional Explain, Review, Refactor and Generate Tests through GitHub Copilot or a configured OpenAI/Claude-compatible endpoint

Runs on Windows, macOS and Linux. Basic cleanup needs no AI, account, .NET runtime or network access.

What both extensions share.

Basic cleanup runs locally and gives the same result every time. It needs no AI model or account and sends no source code to an external provider, which matters in repositories where code must not leave the development environment.

You choose the scope: a single file, selected files, a project, a workspace, Git-changed files or cleanup on save, depending on the editor. Rules can be set individually or stored as repository policy.

AI is optional and stays off until you turn it on. It is used for work that needs generation or analysis: XML documentation, review, refactoring and test generation.

Control over changes.

Cleaned-up code still deserves a review. In Visual Studio, C# changes can be inspected as a native diff before they are applied. In VS Code, review matters most for syntax modernization, because the engine does not use Roslyn semantic analysis.

The .codejanitor file lets a team share cleanup policy. Each developer can still override it with user settings where their environment requires that.

Where the project comes from.

Code Janitor for Visual Studio is a fork and independently maintained continuation of CodeMaid. It keeps what worked in the original and develops it for current Visual Studio, .NET and Razor.

The VS Code extension is a separate implementation. It shares the idea and the .codejanitor policy with the Visual Studio version, but has its own engine and a different feature set, which is why the lists above differ.