Code Cubes are scattered about Planet Popstar. Collecting a specified number of them unlocks the bossdoors for each of the game's levels, and finding every Code Cube in a level opens a path to that level's secret EX stage. According to HAL Laboratory, Code Cubes "contain the code to open up the pathway to the boss." There are 100 Code Cubes in total. Code Cubes that have already been collected are replaced with transparent replicas the next time the stage is entered. These cubes are worth ten stars.
When Kirby visits later areas in the Access Ark, he finds that a number of things, such as doors and floors, are composed of black Code Cubes. During their respective battles, Star Dream and Star Dream Soul OS summon massive Code Cubes from portals and launch them at Kirby's HalberdRobobot Armor. Kirby can shoot these down, absorb the debris, and fire a volley of stars back at the Mother Computer.
These are hidden throughout each stage. Collect a certain number of them to advance through the security barrier to the boss stage. If you collect a lot of Code Cubes, you can even unlock bonus stages.”