Background and purposeScanned carbon beam therapy offers advantageous dose distributions and an increased biological effect. Treating moving targets is complex due to sensitivity to range changes and interplay. We propose a 4D treatment planning concept that considers motion during particle number optimization. Material and methodsThe target was subdivided into sectors, one for each motion phase of a 4D-CT. Each sector was non-rigidly transformed to its motion phase and there targeted by a dedicated raster field (RST). Therefore, the resulting 4D-RST compensated target motion and range changes. A 4D treatment control system (TCS) was needed for synchronized delivery to the measured patient motion. 4D-optimized plans were simulated for 9 NSCLC lung cancer patients and compared to static irradiation at end-exhale. A prototype TCS was implemented and successfully tested in a film experiment. ResultsThe 4D-optimized treatment plan resulted in only slightly lower dose coverage of the target compared to static optimization, with V95% of 97.9% (median, range 96.5–99.4%) vs. 99.3% (98.5–99.8%), with negligible overdose. The conformity number was comparable at 88.2% (85.1–92.5%) vs. 85.2% (79.9–91.2%) for 4D and static, respectively. ConclusionWe implemented and tested a 4D treatment plan optimization method resulting in highly conformal dose delivery.