We conducted experiments to investigate in-cylinder light absorption by carbon dioxide (CO2) during homogeneous charge compression ignition (HCCI) engine combustion. The combustion was fuelled with dimethyl ether. An in situ laser infrared absorption method was developed. We used an optical fibre spark plug sensor and the light source was a 4.301 μm quantum cascade laser (QCL). We applied Lambert–Beer’s law in the case of a single absorption line of CO2. We were able to measure the transient CO2 formation during the HCCI combustion inside the engine cylinder. Our experiments showed that the laser light transmissivity level decreased with the intensity of the infrared (IR) signal. We compared the change in the transmissivity to the spatially integrated HCCI flame luminosity level and observed significant correlations between the flame luminosity level, heat release rate and transmissivity. Time-resolved experiments showed that the CO2 absorbance increases when the second peak of the rate of heat release (ROHR) is maximised. After combustion, the CO2 concentration was approximately 4 vol%, which agrees with the amount of CO2 formed during complete combustion.