OptiFine 1.20.4, 1.20.2 and 1.20.6: builds and Forge
Start with OptiFine I7 for Minecraft 1.20.4. Use I8 pre4 for its preview fixes. Both list Forge 49.0.31. If your launcher shows 1.20.2 or 1.20.6, choose a separate JAR.

For Minecraft: Java Edition 1.20.4, use the OptiFine HD U I7 release and Forge 49.0.31 if you play on Forge. Use I8 pre4 when you need a fix in the preview series. OptiFine lists the same Forge build for both files.
Find the I7 release on optifine.net
Read the exact version in Installations in Minecraft Launcher. Open Show all versions on the official OptiFine catalog and find Minecraft 1.20.4. Choose (Mirror) on the I7 row. The download page names OptiFine 1.20.4 HD U I7 and the file is OptiFine_1.20.4_HD_U_I7.jar.

I would start with I7 for a new 1.20.4 profile. The I7 changelog includes a fix for the BlockEntity Forge patch and a fix for shader shadows when ticks are frozen. A modpack pinned to Minecraft 1.20.1 needs a separate 1.20.1 JAR, even if a guide for 1.20.4 appears in the results.
Pick I8 pre4 for a specific preview fix
Under Minecraft 1.20.4, expand + Preview versions. Choose preview_OptiFine_1.20.4_HD_U_I8_pre4.jar if the preview changes address your issue. The I8 pre2 changelog records the moving-piston crash fix, mouse-wheel scrolling in Shaders, and Quick Info in place of Show FPS. Pre4 carries those changes forward. Its own changelog adds custom entity model attachments and fixes the Quick Info All OFF button.

Use one OptiFine file in each game directory. To compare I7 and I8 pre4 in a Forge pack, make a separate copy and change only that JAR so you can return to the working setup.
Install Forge 49.0.31, then add the JAR
Expand Show all Versions on Forge's 1.20.4 download list. Choose Installer at 49.0.31. Run the Forge installer and select Install client. Launch the resulting Forge profile once and quit. Install the OptiFine JAR with Forge using the game folder for this profile.

Under Installations, use the folder icon on that profile to open its game directory. Put the intact OptiFine JAR in that directory's mods folder and launch Forge again. If the pack already uses a different Forge version, keep the pack intact and use a separate copy for the documented pairing.
Use the matching profile for standalone and shaders
For standalone OptiFine, run your exact vanilla Minecraft version once until the title screen, then quit. Open the OptiFine JAR and choose Install. Select the OptiFine installation in Minecraft Launcher. If a double-click opens an archive app, run java -jar "OptiFine_1.20.4_HD_U_I7.jar" from the download folder. Replace the filename in quotes with the exact JAR you chose. The terminal keeps Java’s first error visible if the installer fails.
With the OptiFine installation active, open Options > Video Settings > Shaders… > Shaders Folder. Use a pack whose requirements cover Minecraft 1.20.4. Return to Shaders and select it, following the OptiFine pack-loading steps.
Use a separate file for 1.20.2 or 1.20.6
- Minecraft 1.20.2. Use the I7 pre1 preview in a standalone installation. The pre1 changelog marks direct Forge compatibility as unavailable. Follow the 1.20.2 standalone steps in your official launcher.
- Minecraft 1.20.5. The catalog has no matching OptiFine build. If the server and all mods allow it, move a copy to 1.20.6. Mojang requires Java 21 and a 64-bit operating system from 1.20.5. Back up your world before opening it in the updated installation.
- Minecraft 1.20.6. Use the J1 pre18 preview. OptiFine pairs it with Forge 50.1.19. If you use Fabric, the Reforged 1.1.9 compatibility table lists J1 pre18. The maintainer’s 1.20.6 requirements specify Fabric Loader 0.19.3 or newer and Java 21 or newer. For the official launcher and Forge, follow the 1.20.6 installation steps.


