Reasoning Patterns for Efficient AI Coding: An Empirical Study
Organizations: Shanghai Jiao Tong University, China
Abstract
Large Reasoning Models (LRMs) generate long reasoning traces that expose intermediate inference behavior, offering opportunities to study and control reasoning in AI coding. However, the underlying patterns in these traces and their potential for analyzing and guiding coding models remain poorly understood, limiting systematic characterization and inference-time control of LRM reasoning. We conduct an empirical study of reasoning patterns across four representative coding tasks. We transform reasoning traces into structured action sequences and mine recurring fragments using within-task support, cross-task contrasts, and valid--invalid support contrasts. We characterize four general reasoning patterns by coding agents: design-to-implementation for code generation, state tracing for execution reasoning, evidence--fix--recheck for debugging, and semantic mapping for translation. We further identify positive and negative patterns associated with valid and invalid reasoning traces, respectively. Positive patterns reflect verification-driven convergence, whereas negative patterns reflect repeated design revision, reflection, and knowledge recall without closure. To demonstrate their practical utility, we evaluate three pattern-based applications: task identification, pattern-guided prompting, and pattern-aware early stopping. Features capturing general reasoning patterns enable accurate task identification from reasoning traces without accessing task descriptions or final answers. Prompting guided by positive and negative patterns improves the overall accuracy of downstream tasks, while negative pattern-aware early stopping substantially reduces API-reported token usage with only a modest decrease in pass@1. All three applications also generalize to previously unseen models, showing that reasoning patterns can support both the analysis and control of LRM behavior in AI coding.
Figures & tables
| Abbr. | Reasoning Action | Description |
| PU | Problem understanding | Understanding and clarifying the problem requirements. |
| SD | Solution design | Designing the high-level solution approach and strategy. |
| IP | Implementation planning | Planning the detailed implementation steps and logic. |
| CC | Code construction | Writing and refining the actual code. |
| VV | Verification and validation | Testing, debugging, and validating the solution. |
| KR | Knowledge retrieval | Retrieving and applying relevant knowledge. |
| Task | General Pattern | Representative Signature | Support (within-task vs. cross-task) | |
| R1-0528 | R1-Qwen3-8B | |||
| Generation | Design-to-implementation | 91.4% vs. 17.0% | 88.0% vs. 22.0% | |
| Execution Reasoning | State tracing | 45.9% vs. 2.2% | 53.5% vs. 3.4% | |
| Debugging | Evidence-fix-recheck | 68.1% vs. 21.5% | 70.8% vs. 20.4% | |
| Translation | Semantic mapping-to-implementation | 36.5% vs. 9.5% | 30.1% vs. 16.2% | |
| Metric | R1-0528 | R1-Qwen3-8B | ||
| Valid | Invalid | Valid | Invalid | |
| Reasoning tokens | 3,690 | 6,609 | 4,330 | 6,991 |
| Raw action length | 18.58 | 24.96 | 22.64 | 32.21 |
| Collapsed action length | 11.78 | 14.91 | 15.97 | 21.99 |
| Closure share | 0.414 | 0.241 | 0.330 | 0.219 |
| Drift share | 0.247 | 0.391 | 0.313 | 0.464 |
| Task | Model | Positive/Negative Pattern | Representative Signature |
| Generation | R1-0528 | Plan-verify-close | IP VV AUX |
| Plan-verify iteration | IP VV IP VV IP | ||
| Knowledge-verify-reflect detour | KR VV MR | ||
| Design-knowledge detour | SD KR IP | ||
| R1-Qwen3-8B | Verify-plan-reverify | VV IP VV | |
| Extended verify-plan | VV IP VV IP |
| Direct | Transferred | ||||||||
| Task | Method | R1-0528 | R1-Qwen3-8B | DS-V4-F | GLM-5.1 | ||||
| P@1 | Tok. | P@1 | Tok. | P@1 | Tok. | P@1 | Tok. | ||
| Generation | Default | 72.46 | 14.9 | 56.21 | 17.9 | 80.78 | 13.0 | 90.29 | 16.5 |
| Positive-only | 73.14 | 15.2 | 55.86 | 18.3 | 84.36 | 13.5 | 90.06 | 13.2 | |
| Negative-only | 72.08 | 14.6 | 56.39 | 17.6 | 79.84 | 12.5 | 90.74 | 13.0 | |
| PN guidance | 74.49 | 15.6 | 56.88 | 17.3 | 87.80 | 12.2 | 91.17 | 12.9 | |
| Task | Model | Full Reasoning | Pattern-Aware Stop | ||||
| P@1 | Tok. | P@1 | Tok. | P@1 (pp) | Tok. (%) | ||
| Generation | R1-Qwen3-8B | 56.21 | 17.89K | 52.14 | 10.64K | ||
| DS-V4-F | 80.78 | 13.00K | 73.36 | 8.43K | |||
| GLM-5.1 | 90.29 | 16.54K | 88.06 | 7.85K | |||
| Execution Reasoning | R1-Qwen3-8B | 44.24 | 3.43K | 40.58 | 2.10K | ||
| DS-V4-F | 56.81 | 2.13K | 51.57 | 0.85K | |||
Efficient Language Model Reasoning
Efficient language model reasoning studies how to improve problem-solving accuracy while reducing inference, memory, latency, and training costs.
See all 371 papers