| name | kr |
| description | Use when renaming Kotlin symbols (classes, methods, properties, parameters), moving Kotlin files to other packages, or analyzing Kotlin project structure (outline, find, deps, beans, hierarchy, unused). Triggers on rename, refactor, move, outline, find, analyze requests involving .kt files. |
| allowed-tools | Bash(kr *), Bash(which kr), Bash(brew install *), Bash(brew tap *), Bash(curl *), Bash(tar *), Bash(sudo mv *), Bash(chmod *) |
kr — Kotlin Renamer & Analyzer
Always use kr for renaming in Kotlin files or moving Kotlin files to other packages.
Use kr analysis commands to understand project structure before reading files.
kr uses word-boundary matching — renaming User never touches UserService.
Pre-flight: ensure kr is installed
Before running any kr command, check that it is available:
which kr
If kr is not found, install it:
brew install umuterturk/tap/kr
curl -L https://github.com/umuterturk/kotlin-renamer/releases/latest/download/kr_darwin_arm64.tar.gz | tar xz
sudo mv kr /usr/local/bin/
curl -L https://github.com/umuterturk/kotlin-renamer/releases/latest/download/kr_darwin_amd64.tar.gz | tar xz
sudo mv kr /usr/local/bin/
curl -L https://github.com/umuterturk/kotlin-renamer/releases/latest/download/kr_linux_amd64.tar.gz | tar xz
sudo mv kr /usr/local/bin/
Rename Capabilities
| Type | What it renames | Example |
|---|
class / interface / object | Declarations, usages, imports, generics, casts, annotations | kr rename --type class User UserAccount --project ./src |
method | fun declaration, call sites, ::methodRef | kr rename --type method calculateTotal computeTotal --project ./src |
property | val/var declaration, .prop access, assignments | kr rename --type property userId accountId --file UserService.kt |
parameter | Signature + body only, never leaks outside the function | kr rename --type parameter userId accountId --file UserService.kt |
move | Package decl, all imports project-wide, file location on disk | kr move UserService.kt com.example.services --project . |
Analysis Capabilities
| Command | What it does | Example |
|---|
beans | Scan for Spring beans (@Service, @Repository, @Controller, @Component, @Bean) | kr beans --project ./src |
find | Find symbol definition, usages, and implementations | kr find --type class UserService --project ./src |
outline | Structural summary (classes, methods, properties with signatures) | kr outline --project ./src |
deps | Import dependencies (what a file imports, what imports it) | kr deps --file UserService.kt --project ./src |
hierarchy | Type inheritance tree | kr hierarchy BaseRepository --project ./src |
unused | Unused classes, methods, and properties | kr unused --project ./src |
All analysis commands support --format json for structured output.
Examples
kr rename --type class User UserAccount --project ./src
kr rename --type class User UserAccount --project ./src --dry-run
kr rename --type interface Repository DataRepository --project ./src
kr rename --type method calculateTotal computeTotal --project ./src
kr rename --type method calculateTotal computeTotal --project ./src --class CartService
kr rename --type method fetchUser loadUser --file UserService.kt
kr rename --type property userId accountId --file UserService.kt
kr rename --type parameter pageSize limit --file PostService.kt
kr move UserService.kt com.example.services --project .
kr move UserService.kt com.example.services --project . --dry-run
kr beans --project ./src
kr outline --project ./src
kr outline --file UserService.kt
kr outline --project ./src --depth shallow
kr find --type class UserService --project ./src
kr find --type class UserService --usages --project ./src
kr find --type interface Repository --implementations --project ./src
kr deps --file UserService.kt --project ./src
kr hierarchy BaseRepository --project ./src
kr unused --project ./src
kr unused --project ./src --type class
kr beans --project ./src --format json
Rules
- Prefer
--project over --file — catches all call sites.
- Use
--file for parameter — parameters are single-file scope.
- Use
--class to narrow when two classes share a method/property name.
- Dry-run first: append
--dry-run, review, then run without it.
kr move always requires --project — needs to scan all imports.
- Don't mix
kr with sed/str_replace on the same symbol.
- Use
kr outline before reading files — understand structure first, then read selectively.
- Use
kr find instead of grep — word-boundary aware, no false positives.
- Use
kr beans for Spring projects — discover the full bean registry in one call.
Not supported
- Local variable rename, Java files, renames inside string literals or comments.