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.

Square stepping cubes curving across a still blue lake at golden hour, one central stone caught by warm sunlight

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.

Minecraft 1.20.4 catalog row with OptiFine HD U I7, Mirror and Forge 49.0.31.
Choose the Mirror on the I7 release row.

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.

Expanded Minecraft 1.20.4 Preview versions showing I8 pre4 and Forge 49.0.31.
Expand Preview versions and pick I8 pre4 for the changes in that preview line.

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.

Forge 49.0.31 sits between 49.0.32 and 49.0.30 with its Installer link outlined.
In the expanded Forge list, choose Installer on the 49.0.31 row.

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