This file contains important workflow instructions for Claude (AI assistant) to follow when working with projects that use the image optimization script.
IMPORTANT: Always check for and optimize images before committing changes.
When working on projects that contain image files, Claude MUST follow this workflow:
Before any commit operations, check for image files:
# Check if there are any image files that need optimization
find . -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" | head -5If images are found, ALWAYS ask the user:
Found X image files that may need optimization:
- path/to/image1.jpg
- path/to/image2.png
These images should be optimized before committing to:
• Reduce file sizes and prevent repository bloat
• Resize large images to reasonable dimensions
• Strip metadata for privacy and size reduction
Would you like me to run the image optimization script?
Options:
1. Yes - Run optimization automatically
2. Manual - You'll run it yourself
3. Skip - Commit without optimization (not recommended)
If user approves, run the optimization:
# For git repositories (recommended - respects .gitignore)
git add .
./optimize-images.sh --git-only --auto
# Or for simple processing (all images)
./optimize-images.sh --auto
# Or if script is in different location
./scripts/optimize-images.sh --git-only --autoAfter optimization, show the results to the user:
# Check what changed
git status
# Show file size differences if helpful
git diff --statApply this workflow in these situations:
- Before any git commit that includes image files
- After copying/adding new images to a project
- When images are modified or replaced
- During project migration (like Bitbucket to GitHub)
- When setting up image optimization in a new project
When setting up image optimization in a project:
- Copy the
optimize-images.shscript to the project root orscripts/directory - Make it executable:
chmod +x optimize-images.sh - Add this workflow to the project's CLAUDE.md file
- Document the script usage in README.md
The script can be located in:
- Project root:
./optimize-images.sh - Scripts directory:
./scripts/optimize-images.sh - As a git submodule or copied from the standalone repository
I found 3 image files in this commit:
- source/img/hero-image.jpg (2.4MB, 5000x3000px)
- assets/photo.png (1.8MB, 4200x2800px)
- content/screenshot.jpg (900KB, 2400x1600px)
These should be optimized before committing. The script will:
• Resize images >3840px to fit within 3840x3840
• Compress to 85% quality
• Strip metadata
Run image optimization?
1. Git mode (recommended - respects .gitignore)
2. Process all images
3. Skip optimization
Choice (1/2/3):
✅ Image optimization completed:
• Processed: 3 images
• Total size reduction: 4.1MB → 2.3MB (-44%)
• All images now optimized for web use
• Mode: Git-aware (respects .gitignore)
Files are ready for commit.
If the optimization script is not found:
Image optimization script not found at ./optimize-images.sh
Options:
1. Download from: https://github.com/kitikonti/script-image-optimizer
2. Skip optimization for now (not recommended)
3. Process images manually
Would you like me to download the script or proceed without optimization?
For projects using pre-commit hooks, the workflow can be automated:
#!/bin/bash
# .git/hooks/pre-commit
# Check for staged images
staged_images=$(git diff --cached --name-only --diff-filter=A | grep -E '\\.(jpg|jpeg|png)$')
if [ ! -z "$staged_images" ]; then
echo "Optimizing staged images..."
./optimize-images.sh --git-only --auto
git add . # Re-stage optimized images
fiFor projects with build processes, add image optimization as a build step:
# In package.json scripts or Makefile
"prebuild": "./optimize-images.sh --auto src/images/"- Script Repository: https://github.com/kitikonti/script-image-optimizer
- ImageMagick Installation: Required dependency for the script
- Documentation: Full usage examples in repository README.md
Note to Claude: This workflow prevents repository bloat and ensures optimal image sizes. Always prioritize image optimization in web development projects, as large unoptimized images significantly impact loading performance and repository size.