Proper energy storage system design is important for performance improvements in solar power shared building communities. Existing studies have developed various design methods for sizing the distributed batteries and shared batteries. For sizing the distributed batteries, most of the design methods are based on single building energy mismatch, but they neglect the potentials of energy sharing in reducing battery capacity, thereby easily causing battery oversizing problem. For sizing the shared batteries, the existing design methods are based on a community aggregated energy mismatch, which may avoid battery oversizing but cause another severe problem, i.e., excessive electricity losses in the sharing process caused by the long-distance power transmissions. Therefore, this study proposes a hierarchical design method of distributed batteries in solar power shared building communities, with the purpose of reducing the battery capacity and minimizing the energy loss in the sharing process. The developed design method first considers all the distributed batteries as a virtual ‘shared’ battery and searches its optimal capacity using genetic algorithm. Taking the optimized capacity as a constraint, the developed method then optimizes the capacities of the distributed batteries for minimizing the energy loss using non-linear programming. Case studies on a building community show that compared with an existing design method, the proposed design can significantly reduce the battery capacity and electricity loss in the sharing process, i.e. 36.6% capacity reduction and 55% electricity loss reduction. This study integrates the considerations of aggregated energy needs, local PV power sharing, advanced community control, and battery storage sharing, which will be useful to optimize three functions (energy efficiency, energy production and flexibility) in a positive energy district towards energy surplus and climate neutrality.