[Bug] The documented formatter command "$FILE" silently does nothing on Windows
Description
The formatter docs tell users to write commands like npx biome format --write "$FILE". On Windows, formatter and hook commands run through cmd.exe (shell: true), and cmd.exe expands %FILE%, not $FILE. So the formatter receives the literal text $FILE, the file stays unformatted, and the tool result says nothing. The docs only mention cmd.exe once, and every example is written for sh.
Environment
- OS: Windows 11 (10.0.26300)
- Node version: 22.22.3
- Nanocoder version: 1.31.0 (main at 6eaff7af)
- Provider / Model: not relevant (reproduced by calling
formatWrittenFiledirectly)
Steps to Reproduce
- On Windows, create a project with
fmt.js. It saves its first argument toformatter-received.txtand upper-cases that file if it exists. - Add to
agents.config.json:{"nanocoder": {"formatters": [{"match": ["**/*.js"], "command": "node fmt.js \"$FILE\"", "name": "fmt"}]}}. - Let the agent write
a.js. - Change the command to
node fmt.js \"%FILE%\"and repeat.
Expected Behavior
The command shown in the docs formats the file, or the docs show the form that works on Windows.
Actual Behavior
With "$FILE" the formatter gets the literal text and the file is not touched:
command : node fmt.js "$FILE"
received: argv[2]="$FILE"
file now: "const hello = \"world\";\n"
tool note: "File written."
With "%FILE%" it works:
command : node fmt.js "%FILE%"
received: argv[2]="C:\\...\\proj\\a.js"
file now: "CONST HELLO = \"WORLD\";\n"
tool note: "File written.\n\nNote: a.js was reformatted by fmt. ..."
Suggested Fix
- Docs: in
docs/configuration/index.md(examples at lines 455-456, explanation at line 462) anddocs/features/hooks.md(line 67 and the examples), add a short Windows note: use"%FILE%"and"%NANOCODER_FILE%"on Windows, or run a script withnode script.js. - Code, optional:
source/services/formatters.ts(theenvblock near therunHookCommandcall) only passes the path through environment variables. It could also substitute$FILEitself, but be careful to quote it safely. The comment insource/services/lifecycle-hooks.ts:563-567explains why onlyhook.commandmay be parsed by the shell. - Add a Windows-only test like the one above, based on
source/services/formatters.spec.ts.
Additional Context
- Formatters came from #1567 and #1483. Related: #1652 (formatter errors are only written to the log in
runmode). - I used a stand-in script, not Biome. Hook commands use the same runner, so
$NANOCODER_FILEindocs/features/hooks.mdshould have the same problem. I did not test hooks separately. - [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder
I'd like to pick this up — planning to substitute $FILE with a properly quoted path before running the formatter (following the cmd.exe quoting from #1108), so it works on Windows without changing POSIX behaviour. Will open a PR shortly.
Thanks @TheNetherWatcher for the fix in #1693, gonna review it this time. For next time: please comment on an issue and wait to be assigned before opening a PR, even for a small fix. It keeps two people from working on the same thing.