MegaCode: A Repository-Level Dataset for Long-Context Code Reasoning

Wenyang Luo, Shuang Sun, Yiwen Hu, Fei Bai, Yanzipeng Gao, Shuo Wang, Hongyu Lu, Xin Zhao, Ji-Rong Wen


Abstract
Code reasoning is essential for building AI systems that can understand, generate, and verify complex software. Yet most open-source code corpora focus on isolated snippets or single functions, failing to capture the long-range dependencies and cross-file interactions that define real-world repositories. We introduce MegaCode, a 300B repository-level corpus designed to support structured code reasoning and long-context modeling. MegaCode preserves full project structure—including build scripts, configuration files, and inter-file links—and is constructed through a multi-stage curation pipeline combining deduplication, rule-based filtering, and model-based quality assessment. Models pretrained on MegaCode demonstrate consistent gains on code reasoning and long-context benchmarks compared with those trained on flattened code datasets. Also, we validate the effectiveness of adding repo relevent infomation such as LSP, repo structure and repo summary. These results highlight the importance of maintaining repository structure for next-generation code intelligence. We release the dataset, curation pipeline, and evaluation suite to facilitate research on large-scale code pretraining and repository-level understanding.
Anthology ID:
2026.findings-emnlp.1484
Volume:
Findings of the Association for Computational Linguistics: EMNLP 2026
Month:
October
Year:
2026
Address:
Budapest, Hungary
Editors:
Hung-Yi Lee, Sunipa Dev, Jessy Li, Desmond Elliott
Venue:
Findings
SIG:
SIGDAT
Publisher:
Association for Computational Linguistics
Note:
Pages:
31608–31626
Language:
URL:
https://aclanthology.org/2026.findings-emnlp.1484/
DOI:
Bibkey:
Cite (ACL):
Wenyang Luo, Shuang Sun, Yiwen Hu, Fei Bai, Yanzipeng Gao, Shuo Wang, Hongyu Lu, Xin Zhao, and Ji-Rong Wen. 2026. MegaCode: A Repository-Level Dataset for Long-Context Code Reasoning. In Findings of the Association for Computational Linguistics: EMNLP 2026, pages 31608–31626, Budapest, Hungary. Association for Computational Linguistics.
Cite (Informal):
MegaCode: A Repository-Level Dataset for Long-Context Code Reasoning (Luo et al., Findings 2026)
Copy Citation:
PDF:
https://aclanthology.org/2026.findings-emnlp.1484.pdf