Lune

AAAI2025Top-tier venue

Hierarchical Context Pruning: Optimizing Real-World Code Completion with Repository-Level Pretrained Code LLMs

Lei Zhang, Yunshui Li, Jiaming Li, Xiaobo Xia, Jiaxi Yang, Run Luo, Minzheng Wang, Longze Chen, Junhao Liu, Qiang Qu, Min Yang

Abstract

Some of the latest released Code Large Language Models (Code LLMs) have been trained on repository-level code data, enabling them to perceive repository structures and utilize cross-file code information. This capability allows us to directly concatenate the content of repository code files in prompts to achieve repository-level code completion. However, in real development scenarios, directly concatenating all code repository files in a prompt can easily exceed the context window of Code LLMs, leading to a significant decline in completion performance. Additionally, overly long prompts can increase completion latency, negatively impacting the user experience. In this study, we conducted extensive experiments, including completion error analysis, topology dependency analysis, and cross-file content analysis, to investigate the factors affecting repository-level code completion. Based on the conclusions drawn from these preliminary experiments, we proposed a strategy called Hierarchical Context Pruning (HCP) to construct high-quality completion prompts. We applied the HCP to six Code LLMs and evaluated them on the CrossCodeEval dataset. The experimental results showed that, compared to previous methods, the prompts constructed using our HCP strategy achieved higher completion accuracy on five out of six Code LLMs. Additionally, the HCP managed to keep the prompt length around 8k tokens (whereas the full repository code is approximately 50k tokens), significantly improving completion throughput. Our code and data will be publicly available.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

10 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • In Line with Context: Repository-Level Code Generation via Context Inlining cites OpenCodeInterpreter: Integrating Code Generation with Execution and Refinement
  • In Line with Context: Repository-Level Code Generation via Context Inlining cites Repository-Level Prompt Generation for Large Language Models of Code
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers10

  1. Continual Multimodal Contrastive LearningXiaohao Liu, Xiaobo Xia, See-Kiong Ng, Tat-Seng ChuaNeurIPS 2025 · 25 citations
  2. L-MTP: Leap Multi-Token Prediction Beyond Adjacent Context for Large Language ModelsXiaohao Liu, Xiaobo Xia, Weixiang Zhao, Manyi Zhang et al.NeurIPS 2025 · 16 citations
  3. OpenOmni: Advancing Open-Source Omnimodal Large Language Models with Progressive Multimodal Alignment and Real-time Emotional Speech SynthesisRun Luo, Ting-En Lin, Haonan Zhang, Yuchuan Wu et al.NeurIPS 2025 · 5 citations
  4. Chiseling Out Efficiency: Structured Skeleton Supervision for Efficient Code GenerationYu Yu, Zhihong Sun, Jia Li, Yao Wan et al.FSE 2026
  5. In Line with Context: Repository-Level Code Generation via Context InliningChao Hu, Wenhao Zeng, Yuling Shi, Beijun Shen et al.FSE 2026

Builds on8

  1. SWE-agent: Agent-Computer Interfaces Enable Automated Software EngineeringJohn Yang, Carlos E. Jimenez, Alexander Wettig, Kilian Lieret et al.NeurIPS 2024 · 2,059 citations
  2. Efficient Streaming Language Models with Attention SinksGuangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han et al.ICLR 2024 · 1,714 citations
  3. Repository-Level Prompt Generation for Large Language Models of CodeDisha Shrivastava, Hugo Larochelle, Daniel TarlowICML 2023 · 184 citations
  4. Lemur: Harmonizing Natural Language and Code for Language AgentsYiheng Xu, Hongjin Su, Chen Xing, Boyu Mi et al.ICLR 2024 · 92 citations
  5. OpenCodeInterpreter: Integrating Code Generation with Execution and RefinementTianyu Zheng, Ge Zhang, Tianhao Shen, Xueling Liu et al.ACL Findings 2024 · 46 citations

Related papers

  1. Aligning LLMs to Fully Utilize the Cross-file Context in Repository-level Code CompletionJia Li, Hao Zhu, Huanyu Liu, Xianjie Shi et al.ASE 2025 · 2 citations
  2. M2RC-EVAL: Massively Multilingual Repository-level Code Completion EvaluationJiaheng Liu, Ken Deng, Congnan Liu, Jian Yang et al.ACL 2025 · 19 citations
  3. AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code CompletionTianyue Jiang, Yanlin Wang, Yanli Wang, Daya Guo et al.ASE 2025 · 2 citations
  4. CodeRAG: Finding Relevant and Necessary Knowledge for Retrieval-Augmented Repository-Level Code CompletionSheng Zhang, Yifan Ding, Shuquan Lian, Shun Song et al.EMNLP 2025 · 3 citations
  5. RepoBench: Benchmarking Repository-Level Code Auto-Completion SystemsTianyang Liu, Canwen Xu, Julian J. McAuleyICLR 2024 · 338 citations
Dusk over the sea between two cliffs drawn in fine vertical lines