| name | format-code |
| description | Reformats source code files to match a consistent style guide. Reads code files across the project and applies formatting corrections using Edit. Use when the user wants to enforce code style, reformat files, or fix formatting inconsistencies. |
Format Code
Reformat source code files to match a consistent style guide.
Workflow
- Accept a directory path and optional language filter from the user.
- Use Glob to find source files matching the language filter (e.g.,
**/*.py, **/*.js, **/*.ts).
- Use Read to read each file's contents.
- Analyze formatting against these rules:
- Consistent indentation (spaces vs tabs, indent width)
- Trailing whitespace removal
- Consistent line endings
- Blank line normalization (max 2 consecutive)
- Import/require statement ordering
- Use Edit to apply formatting corrections to each file.
- Report a summary of changes made.
Rules
- Only modify formatting โ never change logic, variable names, or
functionality.
- Work across the project directory as specified by the user.
- Process user-provided style preferences (indent width, tab vs space)
when given.
- All changes are in git-tracked files and can be reverted with
git checkout.