Skip to content

commandCode quality

Organize Imports

Sorts, groups and prunes imports in your changed files to match the project convention, then proves nothing broke.

npx workspacetemplates add organize-imports --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/organize-imports.md14 lines · 1.1 KBFile
---
description: Sorts, groups and prunes imports in your changed files to match the project convention, then proves nothing broke.
argument-hint: "[optional folder or extra rule]"
---

Organize the imports in the changed files. Scope or extra rules: $ARGUMENTS

1. Run `git diff --name-only HEAD` to get the files. Limit yourself to source files in that list.
2. Find the project's convention: look for an ESLint import/order rule, isort or ruff config, goimports, a Prettier plugin, or `.editorconfig`. If a tool exists, run it in fix mode on those files only. Otherwise infer the order from three untouched files.
3. Typical order: standard library, third-party, project aliases, relative paths, with a blank line between groups and alphabetical inside each.
4. Remove imports that nothing uses. Check for side-effect imports and type-only imports before deleting.
5. Never reorder imports whose order matters, such as polyfills or CSS that must load first. Leave a comment-marked block alone.

Run the type checker or build and the tests. Show `git diff --stat` and mention any file you skipped and why. Do not commit.

What it does

Import blocks drift: unused names, mixed ordering, relative paths where an alias exists. This command learns the convention the project already follows and applies it to the files you changed, not the whole repo.

It prefers the formatter or linter the project has configured, falls back to hand edits only where needed, and shows the diff before anything else happens.

Example

you › /organize-imports

agent › 6 changed files. Used the project's eslint import/order rule.
Removed 4 unused imports, regrouped 5 files, skipped src/polyfills.ts (order matters).
Typecheck and 38 tests pass. Diff is 6 files, +22 -31, not committed.

Questions

Will it touch files I have not changed?
No. It starts from the current git diff and stays inside that list unless you pass a folder.
What if the repo has no import tooling?
It copies the order seen in a few untouched files and tells you which pattern it inferred.
  • Add Error Handling

    CommandCode quality

    Free
  • Add Logging

    CommandCode quality

    Free
  • Add Types

    CommandCode quality

    Free
  • Extract Function

    CommandCode quality

    Free