Context Matters: Improving LLM-Based Code Summarization with Hierarchical Information
Not on the map. Why?
Abstract (arXiv)
Source code documentation plays an important role in software quality activities, such as code review, program comprehension, maintenance, and bug fixing. However, it is often fragmented across individual code elements and focuses on local implementation details, providing little information about their surrounding context. This limits both developers' understanding of software systems and the effectiveness of Large Language Models (LLMs), whose reasoning is constrained by finite context windows. Enriching documentation with hierarchical context has the potential to improve software comprehension and support downstream, quality-related tasks for both developers and LLM-based tools. In this paper, we present an in silico study that showcases the impact of augmenting context on the generation of code-level documentation, using a variety of LLMs. By varying the function, class, and module hierarchy visible to the LLMs, we assess whether this variation produces a significant difference in the resulting code documentation compared with the existing documentation, which serves as a proxy for developer intent. Our results show that Documentation-Aware prompts with class or module-level context consistently yield summaries that are closest to the original documentation. Adding surrounding documentation yields statistically significant improvements over the baseline across models, with effect sizes ranging from negligible (DeepSeek) through weak (GPT-4o-mini) to medium (Gemini). We restrict the study to this immediate hierarchical context; call-graph traversal and cross-module dependency context fall outside our scope and are left to future work. These findings provide a clear path to improve automated documentation tools and enhance LLMs' ability to reason about codebases for downstream tasks, such as code retrieval.
Key facts. No citing papers in the map yet (data through 24 Nov 2026). Builds on 7 of its 28 references that are in the map. Submitted 13 Nov 2026.
Builds on
7 of 28 references.
References · 7
- 2023Judging LLM-as-a-Judge with MT-Bench and Chatbot Arenacited by 9,360
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,337
- 2018code2vec: Learning Distributed Representations of Codecited by 255
- 2025Beyond the Surface: Measuring Self-Preference in LLM Judgmentscited by 38
- 2025On the Effectiveness of LLM-as-a-judge for Code Generation and Summarizationcited by 23
- 2024Analyzing the Performance of Large Language Models on Code Summarizationcited by 21
- 2025Code Summarization Beyond Function Levelcited by 9
Built on by
Not cited yet.
Similar, not cited
Close in wording, no citation either way
- 2026Prompt-Driven Code Summarization: A Systematic Literature Review
- 2024Source Code Summarization in the Era of Large Language Models
- 2025Code Semantic Zooming ↗
- 2024Can Large Language Models Serve as Evaluators for Code Summarization?
- 2024Iterative Refinement of Project-Level Code Context for Precise Code Generation with Compiler Feedback
- 2026Context-as-AI-Service: Surfacing Cross-File Dependency Chains for LLM-Generated Developer Documentation
- 2025Uncovering Code Insights: Leveraging GitHub Artifacts for Deeper Code Understanding
- 2026When LLMs Lag Behind: Knowledge Conflicts from Evolving APIs in Code Generation