ozgrozer/ai-renamer
Sobre
Uma CLI do Node.js que usa modelos do Ollama e do LM Studio (Llava, Gemma, Llama etc.) para renomear arquivos de forma inteligente com base em seu conteúdo.
IA e aprendizado de máquinaCrescimento medido de estrelas
- em 24 h
- 0
- em 7 dias
- +6
- em 15 dias
- +4
- em 1 mês
- +2
Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.
README.md
Originalai-renamer
A Node.js CLI that renames your files by what is in them. It reads images, videos, audio, PDFs, office documents, ebooks, emails, code and text, and asks an AI model for a good name. It works with local models in Ollama and LM Studio, and with OpenAI, OpenRouter, Google AI Studio or any OpenAI compatible server.
Desktop
For the desktop app, visit airenamer.app
Preview
Rename videos
https://github.com/user-attachments/assets/502aedba-044e-4ed5-a1c7-bca84af2f3ce
Rename images
https://github.com/ozgrozer/ai-renamer/assets/651938/0d229179-8385-4f17-a9fb-44d40c79d1e9
Rename files
https://github.com/user-attachments/assets/f8b37c3a-9cc0-48fc-aaea-f25f7b6ee4cc
What it reads
| Kind | Extensions | What the AI sees |
|---|---|---|
| Images | jpg, jpeg, png, webp, gif, tif, tiff, bmp, avif, heic, heif | The picture, made smaller |
| Camera raw | cr2, cr3, nef, nrw, arw, raf, orf, rw2, pef, dng, 3fr, erf, x3f | The preview picture inside the file |
| Videos | mp4, mov, m4v, mkv, avi, webm, wmv, flv, 3gp, mts, m2ts, mpg, mpeg, mxf, ogv and more | A grid of frames and the video's tags |
| Audio | mp3, wav, m4a, aac, flac, ogg, opus, wma, aiff, amr and more | What is said in the first minute, the tags like title and artist, and the length |
| PDFs | The title and text, or a picture of the first page for scans | |
| Documents | doc, docx, xls, xlsx, ods, pptx, odt, odp, rtf, epub | The text |
| Emails | eml | The subject, people, date and text |
| Text and code | txt, md, csv, json, html, srt, ics, vcf, js, py and 74 more | The start of the text |
Photos also send their date, camera and lens to the AI (never the place they were taken). Hidden files and folders, like .git, are skipped.
Install
Upgrading from version 1? Version 2 needs Node.js 22.13 or newer, check yours with
node -v. Version 1 ran on older Node.js versions, so if you can't update Node.js yet, keep using it withnpx ai-renamer@1 /path. The first run of version 2 moves your saved settings from~/ai-renamer.jsonto~/.ai-renamer/config.json, so version 1 starts without them after that.
You need Node.js 22.13 or newer, and one of these:
- Ollama or LM Studio with a model. Pick a vision model (like
gemma3,qwen2.5vlorllava) to rename images and videos too - An API key of OpenAI, OpenRouter or Google AI Studio
- Any server with an OpenAI compatible API, like LiteLLM or Groq
To rename videos and audio files you also need ffmpeg.
Run it with npx
npx ai-renamer /path
Or install it
npm install -g ai-renamer
ai-renamer /path
Docker
The Docker image has ffmpeg in it. Mount the folder to rename at /files, and keep the settings and logs in a volume so --undo and the saved settings work in the next runs. It uses Ollama on your computer.
docker run --rm -it \
-v "$PWD:/files" \
-v ai-renamer:/root/.ai-renamer \
ghcr.io/ozgrozer/ai-renamer /files --dry-run
On Linux, add --add-host=host.docker.internal:host-gateway so the container can reach Ollama. For LM Studio, add --provider=lm-studio --base-url=http://host.docker.internal:1234. To undo, run the same command with --undo in place of /files --dry-run.
To build the image yourself:
docker build -t ai-renamer .
Try it safely first
--dry-run shows the new names without renaming anything. --confirm asks before each rename, answer with y (yes), n (no), a (yes to all) or q (quit).
npx ai-renamer ~/Downloads --dry-run
npx ai-renamer ~/Downloads --confirm
A dry run saves the names it shows in ~/.ai-renamer/plans. When you like them, --apply renames the files to exactly those names, without asking the AI again. A file is skipped when it is gone or its new name is taken by then.
npx ai-renamer ~/Downloads --dry-run
npx ai-renamer --apply
# or the names of a plan file
npx ai-renamer --apply ~/.ai-renamer/plans/2026-11-29_14-03-22.csv
Every run saves the old and new names in a csv file in ~/.ai-renamer/logs. To put the names of the last run back:
npx ai-renamer --undo
# or the run of a log file
npx ai-renamer --undo ~/.ai-renamer/logs/2026-11-29_14-03-22.csv
Pick the files
Give one or more files and folders. -s takes the files in subfolders too. --pattern (or -g) renames only the files that match, it can be given more than once.
npx ai-renamer photo.jpg ~/Desktop ~/Downloads
npx ai-renamer ~/Photos -s
npx ai-renamer ~/Desktop --pattern "Screenshot*"
npx ai-renamer ~/Photos -s -g "*.{jpg,jpeg,heic}"
npx ai-renamer ~/Projects -s -g "invoices/**/*.pdf"
# A regular expression between slashes
npx ai-renamer ~/Photos -g "/^IMG_\d+\.(jpe?g|heic)$/i"
In a pattern, * is any text in a name, ** is any folders, ? is one letter, [abc] is one of these letters and {a,b} is either word. Letter case is ignored. A pattern between slashes is a regular expression, matched against the filename and the path inside the folder, add i after it to ignore letter case. Put the pattern in quotes, so your shell does not read it.
Providers
Ollama
Ollama is the default provider. Without --model it picks a vision model you have, so images work too.
npx ai-renamer /path
npx ai-renamer /path --provider=ollama --model=gemma3
LM Studio
Start the server in the Developer tab of LM Studio. Without --model it picks the loaded model, a vision model first.
npx ai-renamer /path --provider=lm-studio
OpenAI
Without --model it picks the newest mini model.
npx ai-renamer /path --provider=openai --api-key=OPENAI_API_KEY
npx ai-renamer /path --provider=openai --model=gpt-4o-mini
OpenRouter
Without --model it picks the newest Gemini Flash model.
npx ai-renamer /path --provider=openrouter --api-key=OPENROUTER_API_KEY
npx ai-renamer /path --provider=openrouter --model=openai/gpt-4o-mini
Google AI Studio
Without --model it picks the newest Gemini Flash model.
npx ai-renamer /path --provider=google --api-key=GEMINI_API_KEY
Custom servers
custom works with any OpenAI compatible server. The base URL can end with /v1 or not.
# LiteLLM
npx ai-renamer /path --provider=custom --base-url=http://127.0.0.1:4000 --model=gpt-4o
# Groq
npx ai-renamer /path --provider=custom --base-url=https://api.groq.com/openai/v1 --api-key=GROQ_API_KEY --model=MODEL_NAME
The API keys can also come from the OPENAI_API_KEY, OPENROUTER_API_KEY and GEMINI_API_KEY environment variables.
Models that think
Some local models, like gemma4 and qwen3, think step by step before they answer. Naming a file doesn't need that, and without it they answer many times faster (in a test with gemma-4-12b in LM Studio, 0.8 instead of 13 seconds). So ai-renamer asks LM Studio and Ollama to skip the thinking. To let them think, add --thinking, and --no-thinking turns it off again.
If Ollama or LM Studio uses another port, give its base URL:
npx ai-renamer /path --provider=ollama --base-url=http://127.0.0.1:11434
npx ai-renamer /path --provider=lm-studio --base-url=http://127.0.0.1:1234
Name templates
A template decides how a name is put together. The AI only fills in its fields, so the names of invoices, receipts or photos always look the same. A template is a pattern of {fields}, or the name of a template you saved.
npx ai-renamer ./invoices --template "{date}_{company}_{amount}_{number}"
# 2024-07-16_acme_1250.00-EUR_INV-001.pdf
npx ai-renamer ./photos --template "{taken}_{title}"
# 2024-07-16_family-picnic.jpg
npx ai-renamer ./scans --template "{date} - {person} - {title}" --date-format DD.MM.YYYY
# 16.07.2024 - jane-doe - rental-agreement.pdf
Save your templates
Save a pattern under a name with --save-template, then use it by its name.
npx ai-renamer --template "{date}_{company}_{amount}_{number}" --save-template invoices
npx ai-renamer ./invoices --template invoices
# List your templates
npx ai-renamer --templates
# Delete one
npx ai-renamer --delete-template invoices
The templates are saved in ~/.ai-renamer/config.json. A field of your own, like {policy-number}, asks the AI for "the policy number". To tell the AI more, add a description to the saved template in that file:
"templates": {
"insurance": {
"pattern": "{date}_{company}_{policy-number}",
"dateFormat": "YYYY-MM-DD",
"fields": [
{ "key": "policy-number", "description": "the insurance policy number, like P-1234" }
]
}
}
Fields
The AI reads these fields from the file:
| Field | What it is |
|---|---|
{title} |
A short description of what the file is |
{date} |
The main date in the file, like the invoice, letter or photo date |
{company} |
The company or organization that issued or sent it |
{person} |
The main person it is for or about |
{amount} |
The total amount with its currency, like 1250.00 EUR |
{number} |
The document number, like an invoice, order or case number |
{type} |
The kind of file, like Invoice, Receipt, Contract or Photo |
These come from the file itself, a template of only these needs no AI:
| Field | What it is |
|---|---|
{original} |
The original name |
{created} |
The date the file was created |
{modified} |
The date the file was last changed |
{taken} |
The date a photo was taken |
{today} |
Today's date |
Any other word is a field of its own, {author} asks the AI for the author. A field without a value is left out with the text in front of it. Without a date in the file, {date} is the photo or created date.
To keep the original name, use --template "{original}_{title}" or "{title}_{original}".
--chars limits the whole name. With a template it is 60 unless you set it. When a name is too long the title is shortened first, dates, amounts and numbers are never cut.
Audio files
Audio files are named by what is said in their first minute. A speech to text model writes it down, and the AI names the file from that text and the file's tags.
With OpenAI this is on by default, with whisper-1. Other servers that have an OpenAI compatible speech to text API need --transcribe-model. Ollama and LM Studio have no speech to text, so give another server with --transcribe-url, like OpenAI, Groq or a local speaches server.
# OpenAI, whisper-1 is used
npx ai-renamer ./recordings --provider=openai --api-key=OPENAI_API_KEY
# Ollama names the files, OpenAI writes down what is said
npx ai-renamer ./recordings --transcribe-url=https://api.openai.com --transcribe-key=OPENAI_API_KEY --transcribe-model=whisper-1
# Everything on your computer, with a local speaches server
npx ai-renamer ./recordings --transcribe-url=http://127.0.0.1:8000 --transcribe-model=Systran/faster-whisper-small
# Turn it off
npx ai-renamer ./recordings --transcribe-model=off
Without speech to text, audio files are named by their tags (like title, artist and album) and length.
Watch a folder
With --watch ai-renamer keeps running and renames the files that come into the folders, like new downloads or screenshots. The files that are already there are left alone, so run it once without --watch to rename them. Stop it with Ctrl+C.
npx ai-renamer ~/Downloads --watch
npx ai-renamer ~/Desktop --watch --pattern "Screenshot*"
A file is renamed once it has stopped growing, so downloads are renamed when they are done. A file you rename yourself in the folder is not renamed again. The renames of a watch are saved in one log, so --undo puts them all back.
More options
# The case style, the length and the language of the names
npx ai-renamer /path --case=snake-case --chars=30 --language=Turkish
# Extra instructions for the AI
npx ai-renamer /path --custom-prompt="Start with the name of the person in the photo"
# Name files only by their content, or only by cleaning up their names
npx ai-renamer /path --source=content
npx ai-renamer /path --source=filename
# See what the AI answered and how long it took
npx ai-renamer /path --verbose
In a terminal, a progress bar under the files shows how many are done and the time left.
When a new name is taken by another file, the AI is asked for a different one, then a number is added like beach-sunset-2.jpg. A file the AI gives the same name again is left alone, it is not renamed to beach-sunset-2.jpg.
Case styles, done with the change-case library. Before 2.0 they were written like kebabCase, that still works:
# value: result
camel-case: twoWords
capital-case: Two Words
constant-case: TWO_WORDS
dot-case: two.words
kebab-case: two-words
no-case: two words
pascal-case: TwoWords
pascal-snake-case: Two_Words
sentence-case: Two words
snake-case: two_words
train-case: Two-Words
Saved settings
The flags you give are saved in ~/.ai-renamer/config.json and used in the next runs, so you only give them once. The model, API key and base URL are saved for each provider. Give an empty value like --model="" to clear one, or clear them all with --reset. One-off flags like --dry-run, --confirm, --watch and --pattern are never saved.
Settings saved by versions before 2.0 in ~/ai-renamer.json are moved over on the first run.
Export and import
--export saves all your settings in one json file: the provider, the model, API key and base URL of each provider, the templates and every other setting. --import adds them to the settings of another computer, or of a friend.
# Saves ai-renamer-settings.json in the current folder
npx ai-renamer --export
# Or to a file you name
npx ai-renamer --export ~/backups/ai-renamer.json
# Adds the settings and templates of the file to yours
npx ai-renamer --import ai-renamer-settings.json
# Replaces your settings with the ones in the file
npx ai-renamer --reset --import ai-renamer-settings.json
An import adds the templates and providers of the file one by one, so the ones you have that are not in the file stay. When the file has a mistake, like a template without fields, nothing is imported and you see what to fix. The exported file has your API keys in it, so keep it private, or delete the apiKey lines before you share it.
Params
npx ai-renamer --help
Usage: ai-renamer <files or folders..> [options]
Options:
-h, --help Show help [boolean]
-p, --provider The AI provider: ollama, lm-studio, custom,
openai, openrouter, google [string]
-a, --api-key The API key of openai, openrouter, google or a
custom server [string]
-u, --base-url The API address, like http://127.0.0.1:11434 for
Ollama [string]
-m, --model The model, like gemma3, llava:13b or
gpt-4o-mini. Picked for you when not set[string]
-f, --frames How many frames of a video the AI sees, 1 to 9
(default 4) [number]
-c, --case The case style: camel-case, capital-case,
constant-case, dot-case, kebab-case, no-case,
pascal-case, pascal-snake-case, sentence-case,
snake-case, train-case (default kebab-case)
[string]
-x, --chars The most characters in a new name (default 20,
or 60 with a template) [number]
-l, --language The language of the names, like English or
Turkish (default English) [string]
-s, --include-subdirectories Rename the files in subfolders too [boolean]
-r, --custom-prompt Extra instructions for the AI, like "Only
describe the background" [string]
-t, --template A name template: a pattern like
"{date}_{company}_{amount}", or the name of one
you saved [string]
-d, --date-format How template dates are written, like YYYY-MM-DD
or DD.MM.YYYY [string]
--save-template Save the --template under a name, then use it
like --template <name> [string]
--delete-template Delete a saved template [string]
--templates List the saved templates [boolean]
--thinking Let local models that think before they answer,
like gemma4, do so. It is off, as naming is
faster without it [boolean]
--source What a name is based on: both, content, filename
(default both, the content and the original
filename) [string]
--transcribe-model The speech to text model for audio files, like
whisper-1. On by default with openai, "off"
turns it off [string]
--transcribe-url The OpenAI compatible server that transcribes
audio, when it is not the provider, like
https://api.openai.com [string]
--transcribe-key The API key of the --transcribe-url server
[string]
-g, --pattern Only rename files that match, like
"Screenshot*", "*.{png,jpg}" or a regular
expression like "/^IMG_\d+/". Can be used more
than once [string]
-w, --watch Keep running and rename the new files that come
into the folders [boolean]
-n, --dry-run Show the new names without renaming anything
[boolean]
--confirm Ask before each rename [boolean]
--apply Rename the files to the names of the last
--dry-run, or of a plan file, without asking the
AI again [string]
--undo Undo the last run, or the run of a log file
[string]
-v, --verbose Show the answer of the AI and how long it took
[boolean]
--export Save every setting and template in a json file
(default ai-renamer-settings.json) [string]
--import Add the settings and templates of a file made
with --export to yours [string]
--reset Forget the saved settings [boolean]
--version Show version number [boolean]
Examples:
ai-renamer ~/Downloads Rename the files in Downloads with
Ollama
ai-renamer ~/Photos -s --dry-run See the new names of every photo,
subfolders too
ai-renamer ./invoices --template Name invoices like
"{date}_{company}_{amount}" 2024-07-16_acme_1250.00-EUR
ai-renamer . -g "Screenshot*" --confirm Rename screenshots, asking before
each one
ai-renamer ~/Downloads --watch Rename new downloads as they come
ai-renamer --apply Rename the files to the names of the
last dry run
ai-renamer --undo Put back the names of the last run
Development
pnpm install
pnpm test
pnpm lint
The tests use Node's own test runner (node:test) and coverage, no other test tools. They make sample files of every kind and run the CLI against a fake Ollama and OpenAI server, so they need no model, only ffmpeg. pnpm test fails when less than 100% of the lines and functions or less than 85% of the branches are covered.
Contribution
Feel free to contribute. Open a new issue, or make a pull request. A pull request is merged when its code follows the style of this project and pnpm lint and pnpm test pass.
Use pnpm, not npm or yarn
Write JavaScript Standard Style: no semicolons, single quotes and 2 spaces.
pnpm lintchecks itWrite plain JavaScript with
requireandmodule.exports, no TypeScriptKeep lines in stairs order: narrow lines on top and wide lines at the bottom. This goes for
requirelines (and the names in their braces), object keys, destructured parameters and JSX props. Single lines come first by their length, then the lines that take more than one line, and a blank line starts a new group. Never reorder arrays, function arguments, statements or objects whose order matters, like the ones read withObject.keysconst path = require('path') const fs = require('fs').promises const readPdf = require('./read-pdf') const { formatTags, probeMedia } = require('./ffmpeg')Write functions as consts with arrow functions, and give a new function one object parameter, so its arguments are named
const renameFile = async ({ filePath, newPath }) => {}Name files in kebab-case, like
read-image.js, and put them in the folder of their job:cli,files,convert,models,namingorrename. Onlyindex.jsstays insrcKeep files under 500 lines, a new feature goes in a new file
Use
console.logfor every message, notconsole.errorWrite comments that say why the code does what it does, in plain words
Add tests for every change in
test, so the coverage stays at 100%. Use the fake server intest/helpers, never a real model or the internetWrite short commit messages like "Add progress bar" or "Fix brackets"
License
Explore projetos relacionados
Carregando…