Skip to content

Add hooks for automatic code formatting on code change #25759

@kevinher7

Description

@kevinher7

Problem

Currently, opencode does not automatically format code when changes are made. This requires developers to manually run formatters after making edits, which can lead to inconsistent code style or forgotten formatting.

Proposed Solution

Add hooks that automatically format code whenever a file is changed/saved within opencode. This would:

  • Integrate with existing formatters (prettier, black, clang-format, etc.)
  • Run automatically on file save or after code generation
  • Support configurable formatting rules per project
  • Be opt-in or configurable to avoid interfering with existing workflows

Implementation Ideas

  1. File watcher hook - Listen for file save/change events and trigger the appropriate formatter
  2. Post-generation hook - Run formatter immediately after opencode generates or modifies code
  3. Configuration file - Allow users to specify formatters per language/file type

Benefits

  • Consistent code style across all changes
  • Reduced manual steps for developers
  • Cleaner commit history without separate formatting commits
  • Better developer experience

Related

This would complement existing linting and type-checking capabilities.

Metadata

Metadata

Assignees

Labels

needs:complianceThis means the issue will auto-close after 2 hours.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions