This paper proposes a persistent representation called the Repository Planning Graph (RPG) to address the challenge of creating a complete software repository from scratch. RPG integrates proposal and implementation planning into a single graph, encoding features, file structures, data flows, and functions, providing an explicit blueprint instead of ambiguous natural language. Building on this, we develop ZeroRepo, a graph-based framework for building repositories from scratch using RPG. ZeroRepo operates in three phases: constructing the graph through proposal planning and implementation refinement, generating code guided by the graph, and validating it through testing. Using a benchmark consisting of six real-world projects (1,052 tasks) called RepoCraft, we evaluate ZeroRepo. It generates an average of 36,000 lines of code, outperforming the existing best-performing benchmark (Claude Code) by approximately 3.9x and other benchmarks by approximately 64x. It also achieved a feature coverage rate of 81.5% and a pass rate of 69.7%, outperforming Claude Code by 27.3 and 35.8 percentage points, respectively. Further analysis demonstrates that RPG models complex dependencies, enables nearly linearly scalable planning, and enhances LLM's understanding of the storage, accelerating agent localization.