cs.LGMar 24, 2026

Steering Code LLMs with Activation Directions for Language and Library Control

Authors: Md Mahbubur Rahman, Arjun Guha, Harshitha Menon

Organizations: Iowa State University · Northeastern University · Lawrence Livermore National Laboratory

Abstract

Code LLMs often default to particular programming languages and libraries under neutral prompts. We investigate whether these preferences are encoded as approximately linear directions in activation space that can be manipulated at inference time. Using a difference-in-means method, we estimate layer-wise steering vectors for five language/library pairs and add them to model hidden states during generation. Across three open-weight code LLMs, these interventions substantially increase generation toward the target ecosystem under neutral prompts and often remain effective even when prompts explicitly request the opposite choice. Steering strength varies by model and target, with common ecosystems easier to induce than rarer alternatives, and overly strong interventions can reduce output quality. Overall, our results suggest that code-style preferences in LLMs are partly represented by compact, steerable structure in activation space.

Figures & tables

Explore similar work

CardsList
  1. Steer Like the LLM: Activation Steering that Mimics Prompting

    May 5, 2026Geert Heyman, Frederik VandeputteLanguage Model SteeringLLM Prompting

  2. LLMs program using Reusable and Composable Abstract Representations

    Oct 13, 2026Casper L. Christensen, Kyle J. Ray, Dmitry Manning-Coe +2LLM Code GenerationCompositional Representation Learning

  3. The Invisible Lottery: How Subtle Cues Steer Algorithm Choice in LLM Code Generation

    Jun 2, 2026Akanksha Narula, Mofasshara Binte Rafique, Laurent BindschaedlerPrompt SensitivityLLM Prompting