Think Anywhere in Code Generation
arXiv:2603.29957v1 Announce Type: new Abstract: Recent advances in reasoning Large Language Models (LLMs) have primarily relied on upfront thinking, where reasoning occurs before final answer. However, this approach suffers from critical limitations in code generation, where upfront thinking is often insufficient as problems' full complexity only reveals itself during code implementation. Moreover, it cannot adaptively allocate reasoning effort throughout the code generation process where difficulty varies significantly. In this paper, we propose Think-Anywhere, a novel reasoning mechanism that enables LLMs to invoke thinking on-demand at any token position during code generation. We achieve Think-Anywhere by first teaching LLMs to imitate the reasoning patterns through cold-start training
Authors:Xue Jiang, Tianyu Zhang, Ge Li, Mengyang Liu, Taozhi Chen, Zhenhua Xu, Binhua Li, Wenpin Jiao, Zhi Jin, Yongbin Li, Yihong Dong
View PDF HTML (experimental)
Abstract:Recent advances in reasoning Large Language Models (LLMs) have primarily relied on upfront thinking, where reasoning occurs before final answer. However, this approach suffers from critical limitations in code generation, where upfront thinking is often insufficient as problems' full complexity only reveals itself during code implementation. Moreover, it cannot adaptively allocate reasoning effort throughout the code generation process where difficulty varies significantly. In this paper, we propose Think-Anywhere, a novel reasoning mechanism that enables LLMs to invoke thinking on-demand at any token position during code generation. We achieve Think-Anywhere by first teaching LLMs to imitate the reasoning patterns through cold-start training, then leveraging outcome-based RL rewards to drive the model's autonomous exploration of when and where to invoke reasoning. Extensive experiments on four mainstream code generation benchmarks (i.e., LeetCode, LiveCodeBench, HumanEval, and MBPP) show that Think-Anywhere achieves state-of-the-art performance over both existing reasoning methods and recent post-training approaches, while demonstrating consistent generalization across diverse LLMs. Our analysis further reveals that Think-Anywhere enables the model to adaptively invoke reasoning at high-entropy positions, providing enhanced interpretability.
Subjects:
Software Engineering (cs.SE); Machine Learning (cs.LG)
Cite as: arXiv:2603.29957 [cs.SE]
(or arXiv:2603.29957v2 [cs.SE] for this version)
https://doi.org/10.48550/arXiv.2603.29957
arXiv-issued DOI via DataCite
Submission history
From: Xue Jiang [view email] [v1] Tue, 31 Mar 2026 16:24:03 UTC (169 KB) [v2] Thu, 2 Apr 2026 11:40:46 UTC (170 KB)
Sign in to highlight and annotate this article

Conversation starters
Daily AI Digest
Get the top 5 AI stories delivered to your inbox every morning.
Knowledge Map
Connected Articles — Knowledge Graph
This article is connected to other articles through shared AI topics and tags.
More in Models

The largest programming community on Reddit just banned all content related to AI LLMs — r/programming is prioritizing only high-quality discussions about AI
The largest programming community on Reddit just banned all content related to AI LLMs — r/programming is prioritizing only high-quality discussions about AI

Everyone Is Worshipping the Wrong AI Heroes—What Hidden Figures Teaches Us About This Moment
Three lessons from three Black women who changed history—and what they reveal about who we’re erasing in the AI revolution right now. https://commons.wikimedia.org/wiki/File:Hidden_Figures_cast_at_the_Kennedy_Space_Center_%2830765657104%29.jpg In 1962, John Glenn refused to board the Friendship 7 capsule until one person had manually verified the IBM computer’s orbital trajectory calculations. As part of the preflight checklist, Glenn asked engineers to “get the girl”—a 44-year-old Black mathematician named Katherine Johnson—to run the same orbital equations by hand on her desktop calculating machine [ 1 ]. His reported words: “If she says they’re good, then I am ready to go [ 2 ].” The space race story the world remembers is astronauts and rocket scientists. The story that kept Glenn aliv





Discussion
Sign in to join the discussion
No comments yet — be the first to share your thoughts!