v0 Platform API/Guides
Lock Files from AI Changes
Learn how to protect files from AI modifications in v0 chats
File locks allow you to protect specific files from AI modifications during code generation, giving you precise control over which parts of your codebase can be changed.
Overview
File locks in v0 protect specific files from AI modifications during generation. This is useful when you want to:
- Preserve configuration files - Keep package.json, tsconfig.json unchanged
- Protect existing code - Prevent AI from modifying working components
- Maintain file structure - Lock files that shouldn't be altered
- Control AI scope - Direct AI attention to specific files only
Setting File Locks During Initialization
Lock Individual Files
Lock All Files from Repository
Lock All Files from Zip
Updating File Locks
Update Files and Lock Status
Lock Existing Files
Common Use Cases
1. Protect Configuration Files
2. Preserve Working Components
3. Import and Selectively Protect
Best Practices
1. Lock Configuration Files
2. Protect Working Code
3. Use Descriptive Comments
4. Strategic Locking for Large Projects
File Lock Status
When files are locked:
- ✅ AI will not modify the file content during generation
- ✅ File remains available for reference and context
- ✅ You can still manually update locked files via API
- ✅ Lock status persists across chat sessions
When files are unlocked:
- ⚠️ AI can freely modify the file content
- ⚠️ Changes may overwrite your existing code
- ✅ AI uses file for context when generating other files
- ✅ You can lock again at any time
File locks give you precise control over what the AI can and cannot change, ensuring your important code stays protected while still allowing AI assistance where you need it.