Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Automated Format-on-Save for Non-Editor File Writes

Description and use

The 'onwrite' tool automates code formatting for files created by scripts or agents. It leverages existing project configurations (Prettier, Ruff) and ensures atomic file replacement, preventing style inconsistencies and errors.

Problem

Files generated by scripts, shell commands, or coding agents are not automatically formatted, leading to style inconsistencies detected later by pre-commit hooks or CI.

Outcome

The 'onwrite' tool successfully intercepts file writes from generators and agents, applying existing project formatters (Prettier, Ruff, etc.) automatically. It handles edge cases like partial writes and formatter loops, ensuring code consistency at the point of creation.

Workflow

  • Install the 'onwrite' tool via the provided shell script.
  • Run 'onwrite doctor' to verify tool detection and configuration.
  • Wrap generation commands with 'onwrite run -- <command>' to auto-format changed files.
  • Use 'onwrite watch' for monitoring file writes that cannot be wrapped directly.
  • For coding agents, use the hook to notify the agent of formatting changes so it can re-read the updated file.

Evidence

onwrite run waits for the wrapped command to finish, works out which files it changed, and formats only those files.

Source

The implementation is deliberately cautious. A formatter never receives the real source file. The contents go in through stdin, the result comes back through stdout, and the file is replaced atomically only after the formatter chain has succeeded.

Source

The first release has 87 tests, including partial writes, hanging tools, ignored files and write-loop cases.

Source

  • Record date: 2026-09-06T23:22:16.053Z