hook-write-existing-file-guard

Block Write tool overwrites of existing files, forcing Edit tool usage.

Updated Apr 12, 2026
One-click install
npx skills add https://github.com/xuezhaojun/oh-your-opencode --skill hook-write-existing-file-guard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hook-write-existing-file-guard
Source: https://github.com/xuezhaojun/oh-your-opencode/tree/main/.opencode/skills/hook-write-existing-file-guard
Command: npx skills add https://github.com/xuezhaojun/oh-your-opencode --skill hook-write-existing-file-guard

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Blocks the Write tool from overwriting existing files with content, forcing the LLM to use the Edit tool instead. This prevents accidental full-file rewrites that lose content or introduce regressions.

Core Features & Use Cases

  • Prevents accidental overwrites by enforcing edits instead of rewrites.
  • Supports exemptions patterns (e.g., *.lock, .generated., *.min.js, *.min.css) to allow safe overwrites.
  • Easy configuration to enable or disable overwrite protection and tailor to project needs.

Quick Start

Configure the guard with your exemptions and options, then initialize it to start blocking overwrites.

Frequently Asked Questions about hook-write-existing-file-guard

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent accidental file overwrites in collaborative codebases?

To prevent accidental overwrites, configure a filesystem guard that blocks the Write tool from replacing existing files. This mechanism forces the LLM to use the Edit tool instead, ensuring modifications preserve original content and prevent regressions in collaborative codebases.

What's the best way to block full file rewrites while allowing generated files to be overwritten?

Blocking full file rewrites while allowing generated files is best handled by configuring exemption patterns. You can specify patterns like *.lock, *.generated.*, or *.min.js to safely permit overwrites for specific files while enforcing edits on the rest.

How does an overwrite guard work with the Edit and Write tools?

An overwrite guard works by intercepting the Write tool to block full file replacements, forcing the LLM to use the Edit tool instead. This ensures only targeted modifications are applied, protecting existing content from being lost.

Can I use overwrite protection in large repositories without blocking all file writes?

Yes, you can use overwrite protection in large repositories by enabling the guard with specific exemptions. Configuring exemption patterns allows safe overwrites for necessary files while maintaining overwrite protection across the broader codebase.

When should I not use a filesystem guard to block file overwrites?

You should not use a filesystem guard to block file overwrites when working with files that require full content regeneration, unless you have configured exemption patterns. Files like *.min.js or *.lock need full rewrites and must be exempted.