{"id":47663194,"url":"https://github.com/michimani/vscode-clangd-include-cleaner","last_synced_at":"2026-07-05T05:01:24.861Z","repository":{"id":346483920,"uuid":"1189835091","full_name":"michimani/vscode-clangd-include-cleaner","owner":"michimani","description":"A VS Code extension that automatically removes unused #include directives in C/C++ files on save, using clangd diagnostics.","archived":false,"fork":false,"pushed_at":"2026-07-02T00:48:44.000Z","size":154,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-02T02:24:41.707Z","etag":null,"topics":["c-plus-plus","clangd","cpp","language-server","vscode-extension"],"latest_commit_sha":null,"homepage":"https://marketplace.visualstudio.com/items?itemName=michimani.cpp-unused-includes-remover","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michimani.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-23T18:01:17.000Z","updated_at":"2026-07-02T00:48:33.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/michimani/vscode-clangd-include-cleaner","commit_stats":null,"previous_names":["michimani/vscode-clangd-include-cleaner"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/michimani/vscode-clangd-include-cleaner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michimani%2Fvscode-clangd-include-cleaner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michimani%2Fvscode-clangd-include-cleaner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michimani%2Fvscode-clangd-include-cleaner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michimani%2Fvscode-clangd-include-cleaner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michimani","download_url":"https://codeload.github.com/michimani/vscode-clangd-include-cleaner/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michimani%2Fvscode-clangd-include-cleaner/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35143802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-05T02:00:06.290Z","response_time":100,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","clangd","cpp","language-server","vscode-extension"],"created_at":"2026-04-02T11:44:57.068Z","updated_at":"2026-07-05T05:01:24.851Z","avatar_url":"https://github.com/michimani.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C++ Unused Includes Remover\n\n[![Version](https://vsmarketplacebadges.dev/version/michimani.cpp-unused-includes-remover.png)](https://marketplace.visualstudio.com/items?itemName=michimani.cpp-unused-includes-remover)\n[![Installs](https://vsmarketplacebadges.dev/installs/michimani.cpp-unused-includes-remover.png)](https://marketplace.visualstudio.com/items?itemName=michimani.cpp-unused-includes-remover)\n[![Downloads](https://vsmarketplacebadges.dev/downloads/michimani.cpp-unused-includes-remover.png)](https://marketplace.visualstudio.com/items?itemName=michimani.cpp-unused-includes-remover)\n[![Rating](https://vsmarketplacebadges.dev/rating-star/michimani.cpp-unused-includes-remover.png)](https://marketplace.visualstudio.com/items?itemName=michimani.cpp-unused-includes-remover)\n[![License: MIT](https://img.shields.io/github/license/michimani/vscode-clangd-include-cleaner)](https://github.com/michimani/vscode-clangd-include-cleaner/blob/main/LICENSE)\n[![CI](https://img.shields.io/github/actions/workflow/status/michimani/vscode-clangd-include-cleaner/ci.yml?label=CI)](https://github.com/michimani/vscode-clangd-include-cleaner/actions)\n\nA VS Code extension that automatically removes unused `#include` directives from C/C++ files using diagnostics from **clangd**.\n\n## Features\n\n| Feature | Description |\n|---------|-------------|\n| **Auto-remove on save** | Removes unused includes every time you save a C/C++ file |\n| **Command: current file** | Manually apply to the active file |\n| **Command: workspace** | Apply to all C/C++ files in the workspace at once |\n| **Debug: dump diagnostics** | Print all diagnostics for the active file to the Output panel |\n\n## Prerequisites\n\n- [clangd VS Code extension](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) (`llvm-vs-code-extensions.vscode-clangd`)\n- clangd binary installed on the system (clangd 17+ recommended for `-std=c++23` support)\n\n### Installing the clangd binary\n\nThe VS Code clangd extension requires the **clangd binary** to be installed separately.\n\n**Debian/Ubuntu (via LLVM apt repository):**\n```bash\n# Add LLVM GPG key\nwget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key \\\n  | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc \u003e /dev/null\n\n# Add repository (adjust codename: bookworm, jammy, etc.)\necho \"deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-19 main\" \\\n  | sudo tee /etc/apt/sources.list.d/llvm.list\n\nsudo apt-get update \u0026\u0026 sudo apt-get install -y clangd-19\nsudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-19 100\n```\n\n\u003e **Note:** The version provided by `apt-get install clangd` (without a version suffix) is typically outdated.\n\u003e Use the LLVM apt repository to get a recent version.\n\n### Enabling unused-includes diagnostics\n\nCreate a `.clangd` file at your project root:\n\n```yaml\nDiagnostics:\n  UnusedIncludes: Strict\n```\n\nTo also set the C++ standard:\n\n```yaml\nCompileFlags:\n  Add: [-std=c++23]\nDiagnostics:\n  UnusedIncludes: Strict\n```\n\n\u003e **Note:** `compile_commands.json` is not strictly required, but clangd's accuracy improves significantly with it.\n\u003e For CMake projects: `cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build`\n\u003e For Make-based projects: `bear -- make`\n\n### Using clangd alongside Microsoft C/C++ extension\n\nIf the Microsoft C/C++ extension is also installed, disable its IntelliSense engine to avoid conflicts:\n\n```jsonc\n// .vscode/settings.json\n{\n  \"C_Cpp.intelliSenseEngine\": \"disabled\"\n}\n```\n\nWith this setting, clangd handles all language features and the Microsoft C/C++ extension provides only its debugger.\n\n## Installation\n\n### From VSIX\n\n```bash\nnpm install\nnpx vsce package\n```\n\nThen install the generated `.vsix` file via `Extensions: Install from VSIX...` in the Command Palette.\n\n### Development (F5)\n\n```bash\nnpm install\nnpm run compile\n```\n\nPress `F5` in VS Code to launch the Extension Development Host.\n\n## Configuration\n\n```jsonc\n{\n  // Enable auto-removal on save (default: true)\n  \"cppUnusedIncludes.enableOnSave\": true,\n\n  // Diagnostic source name to match against (default: \"clangd\")\n  \"cppUnusedIncludes.diagnosticSource\": \"clangd\",\n\n  // Milliseconds to wait after save before reading diagnostics (default: 100)\n  // Increase if includes are not removed (language server still analyzing).\n  \"cppUnusedIncludes.waitForDiagnosticsMs\": 100,\n\n  // Glob pattern for files targeted by the workspace-wide command\n  \"cppUnusedIncludes.workspaceFileGlob\": \"**/*.{cpp,cc,cxx,c,h,hpp,hxx}\"\n}\n```\n\n## Commands\n\n| Command | Description |\n|---------|-------------|\n| `C++: Remove Unused Includes in Current File` | Remove unused includes from the active file |\n| `C++: Remove Unused Includes in Workspace` | Apply to all C/C++ files in the workspace |\n| `C++: Dump Diagnostics to Output (Debug)` | Print diagnostics for the active file to the Output panel |\n\nRun commands from the Command Palette (`Ctrl+Shift+P` / `Cmd+Shift+P`).\n\n## Troubleshooting\n\n### Includes are not being removed\n\n1. Open the Output panel (`View \u003e Output`) and select **C++ Unused Includes Remover** from the dropdown.\n2. Save a C++ file and check the log.\n\n**`no diagnostics`** — clangd is not providing diagnostics. Check that:\n- The clangd VS Code extension is installed and active.\n- The clangd binary is installed (`clangd --version` in the terminal).\n- A `.clangd` file with `UnusedIncludes: Strict` exists at the project root.\n- The file has been open long enough for clangd to finish analyzing.\n\n**`0 unused include(s) to remove`** — Diagnostics are present but none match. Run `C++: Dump Diagnostics to Output (Debug)` and verify that `source=\"clangd\"` entries appear.\n\n### Timing issues\n\nIf diagnostics are not ready when the extension reads them, no includes will be removed. Increase the wait time:\n\n```jsonc\n{\n  \"cppUnusedIncludes.waitForDiagnosticsMs\": 500\n}\n```\n\n## How It Works\n\n```\nFile saved\n    │\n    ▼\nWait waitForDiagnosticsMs (default: 100ms)\n    │\n    ▼\nvscode.languages.getDiagnostics() — fetch diagnostics\n    │\n    ▼\nFilter: source === \"clangd\"\n        AND (code === \"unused-includes\" OR message contains \"unused\"+\"include\")\n    │\n    ▼\nSort by line number descending (prevents line-number drift)\n    │\n    ▼\nDelete each #include line via WorkspaceEdit\n    │\n    ▼\nSave document\n```\n\n## Development\n\n### Using Dev Container (recommended)\n\nThis repository includes a [Dev Container](https://containers.dev/) configuration. You can develop the extension in a fully pre-configured environment without installing anything locally.\n\n**Requirements:** Docker and either VS Code with the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) or [GitHub Codespaces](https://github.com/features/codespaces).\n\n1. Open the repository in VS Code.\n2. When prompted, click **Reopen in Container** (or run `Dev Containers: Reopen in Container` from the Command Palette).\n3. The container will automatically run `npm install` via `postCreateCommand`.\n4. Once the container is ready, press `F5` to launch the Extension Development Host.\n\n### Local Setup\n\n```bash\n# Install dependencies\nnpm install\n\n# Compile TypeScript\nnpm run compile\n\n# Watch mode (recompile on change)\nnpm run watch\n\n# Lint / format\nnpm run check\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichimani%2Fvscode-clangd-include-cleaner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichimani%2Fvscode-clangd-include-cleaner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichimani%2Fvscode-clangd-include-cleaner/lists"}