The Cassegrain location of the High Resolution Optical Spectrograph (HROS) for the 8-metre Gemini telescope presents a difficult challenge in controlling mechanical flexure. This is especially the case for a high-resolution spectrograph, which requires large and heavy optical components. In HROS, to achieve the required spectrum stability of 2.0 mu m/hr (1/20(th) of the resolution element per hour of tracking), we developed a closed-loop monitoring and correction system capable of measuring the spectrograph flexure in as it happens and actively compensating for image motion. The result is the Active Flexure Compensation (AFC) system, which is fully integrated in the design of the spectrograph. The system relies on an IR laser source propagated through all the spectrograph components to provide an optical reference for the flexure measurement and on a fine steering of the spectrograph echelle grating to restore the spectrum in the original position. One of the key decisions in the design was to use infrared light at 1.523 mu m for the optical reference to prevent contamination of the science data by scattered light. The system can then operate in a closed feedback loop during astronomical observations, providing monitoring and correction in real time. Here we present the final optical design of the AFC system, together with its expected performance.