Ad-hoc prompting inside chat sidebars is an anti-pattern for professional software engineering. While typing freeform instructions into an AI chat window works for exploratory tasks, relying on it for daily refactoring produces inconsistent syntax, omitted edge cases, and continuous friction. Developers waste mental overhead repeatedly specifying conventions such as immutable data structures, mock frameworks, or docstring styles.
JetBrains AI solves this friction through its native Prompt Library, embedded directly into IDEs such as IntelliJ IDEA, PyCharm, WebStorm, and GoLand. By configuring reusable prompt templates backed by dynamic context variables like $SELECTION, engineering teams can convert manual refactoring recipes into one-click, deterministic IDE actions.
At 365Finds, our architectural stance is straightforward: treat prompts as versionable engineering assets. Individual developers should use the Prompt Library for instantaneous tactile invocation, while teams must anchor architectural standards using Git-tracked .aiassistant/rules to eliminate AI drift across codebases.
1. Anatomy of the JetBrains AI Prompt Library
The Prompt Library acts as an internal registry for both custom developer macros and built-in IDE actions. Instead of treating large language models as external conversational partners, JetBrains AI embeds them into the editor's native abstract syntax tree (AST) and context evaluation pipeline.
Accessing the Prompt Library
You can access and manage prompt templates through three entry points:
- Global IDE Settings: Open Settings (
Ctrl+Alt+Son Windows/Linux orCmd+,on macOS) and navigate to Tools | AI Assistant | Prompt Library. - Contextual Editor Popup: Select any code snippet, press
Alt+Enter(or right-click to open the context menu), choose AI Actions, and select Add your prompts. - Chat Persistence: When you construct an effective ad-hoc prompt in the AI Chat window, hover over your prompt message, click the kebab menu (
...), and select Save Current Prompt to commit it directly into your library.
+-----------------------------------------------------------------------+
| JetBrains AI Assistant: Prompt Library Settings |
+-----------------------------------------------------------------------+
| [Built-in Prompts] | [Custom Prompts] |
| - Explain Code | + Add New Prompt |
| - Suggest Refactoring |------------------------------------|
| - Generate Unit Tests | Name: Entity to DTO Converter |
| - Write Documentation | Parameters: |
| - Generate Commit Message | [x] Wait for user input |
| | [x] Show in 'AI Actions' popup |
+-----------------------------------------------------------------------+
Context Variables and Execution Parameters
When writing prompt templates, JetBrains AI provides macro placeholders and execution flags:
$SELECTION: The primary contextual macro. When executed, the IDE automatically captures the highlighted text or code block in your active editor, wraps it in a Markdown code fence, and attaches the language identifier (e.g.,java ...).- Wait for additional user input after invoking: When enabled, triggering the prompt opens the AI Chat window with your template pre-filled and pauses, allowing you to supply transient modifiers (e.g., target framework version or specific field exclusions) before submitting. When disabled, the template runs immediately for frictionless automation.
- Show prompt in 'AI Actions' popup: Determines whether the template appears inside the editor's
Alt+Enterintention actions and right-click context menu. - Order Management: The up and down arrow buttons in the settings panel control the visual hierarchy of custom prompts inside the AI Actions menu, ensuring high-frequency templates remain within immediate reach.
2. Production Refactoring Templates
Generic instructions yield generic code. To achieve enterprise-grade consistency, prompt templates must enforce explicit boundaries, architectural constraints, and output restrictions.
Below are three production-tested prompt templates designed for high-frequency refactoring routines.
Template 1: Domain Entity to Immutable DTO Converter
Transforming database entities into Data Transfer Objects (DTOs) is repetitive and error-prone. This template enforces immutability, builder patterns, and null safety.
- Prompt Name:
Refactor: Generate Immutable DTO - Execution Mode: Direct execution (
Wait for additional user inputdisabled) - Menu Visibility: Enabled (
Show prompt in 'AI Actions' popup)
Act as a principal software engineer. Convert the following entity class in $SELECTION into an immutable Data Transfer Object (DTO) according to these strict rules:
1. Class Design:
- Make all fields private and final.
- Do not generate public no-arg constructors; generate a single canonical constructor or builder pattern appropriate for the language (e.g., Record in Java 17+, dataclass(frozen=True) in Python, or readonly properties in TypeScript).
- Exclude internal database identifiers, audit timestamps, and ORM proxy metadata unless explicitly requested.
2. Mapping Utilities:
- Provide a static factory method `fromEntity(entity)` handling null-safety checks.
- Provide an instance method `toEntity()` where applicable.
3. Serialization:
- Add standard JSON property annotations matching camelCase serialization conventions.
Code to convert:
$SELECTION
Template 2: Enterprise Unit Test Scaffolding
Built-in test generation often creates naive happy-path tests. This template forces the model into an Arrange-Act-Assert (AAA) pattern with strict boundary condition coverage.
- Prompt Name:
Refactor: Generate AAA Unit Tests - Execution Mode: Interactive (
Wait for additional user inputenabled) - Menu Visibility: Enabled
Analyze the method or class provided in $SELECTION and generate an enterprise-grade unit test suite adhering to these engineering standards:
1. Structure & Conventions:
- Use the primary testing framework idiomatic to this project (e.g., JUnit 5 + Mockito, pytest + pytest-mock, or Vitest).
- Divide every test into explicit comments: `// Arrange`, `// Act`, and `// Assert`.
- Use clear test naming reflecting behavior: `should_<ExpectedBehavior>_when_<Condition>`.
2. Coverage Requirements:
- Happy path with realistic domain values.
- Boundary conditions (empty collections, null inputs, zero limits, extreme integer ranges).
- Exception handling and error branches; assert expected exception types and message patterns.
3. Isolation:
- Mock all external dependencies, network interfaces, and database repositories.
- Do not perform assertions against mock framework implementation details; assert domain outputs.
Code under test:
$SELECTION
Template 3: Strict Contract Documentation (Javadoc / TSDoc / Docstrings)
Manually writing comprehensive documentation comments for complex methods frequently slips past code review. This template standardizes contractual specifications without parroting function names.
- Prompt Name:
Refactor: Add Strict Contract Docstrings - Execution Mode: Direct execution
- Menu Visibility: Enabled
Generate professional contract documentation comments for the code in $SELECTION:
1. Content Requirements:
- Summarize the business purpose in one concise declarative sentence. Avoid tautological descriptions that simply restate the function signature.
- Document all parameters, return values, thrown exceptions, and side effects explicitly.
- State pre-conditions (e.g., non-null arguments, valid ranges) and post-conditions.
- If thread-safety, idempotency, or performance complexity (Big-O) is relevant, state it clearly.
2. Syntax:
- Use standard format (Javadoc for Java/Kotlin, TSDoc for TypeScript, Google-style docstrings for Python).
- Return only the updated code with the documentation comments inserted directly above the targets.
Target Code:
$SELECTION
3. Keyboard Integration and Editor Workflow
Saving seconds across dozens of daily refactoring cycles prevents developer context switching. JetBrains AI offers seamless keyboard integration:
[Highlight Code in Editor]
│
▼
[Press Alt+Enter / Option+Enter]
│
▼
[Type Custom Prompt Name (e.g. "DTO")]
│
▼
[Hit Enter -> Deterministic Refactoring Applied]
Direct Keymap Binding
If an engineering workflow involves triggering a specific refactoring action dozens of times daily, invoking the intention popup can be bypassed entirely:
- Open Settings | Keymap (
Ctrl+Alt+SorCmd+,). - Search for the name of your custom prompt in the search field (e.g.,
Refactor: Generate Immutable DTO). - Right-click the matching entry under AI Actions and select Add Keyboard Shortcut.
- Assign a dedicated shortcut (e.g.,
Ctrl+Alt+Shift+Don Windows/Linux orCmd+Option+Shift+Don macOS). - Ensure no collision with primary IDE refactoring chords (such as
Ctrl+Alt+Mfor Extract Method).
With this shortcut mapped, highlighting a class and pressing the assigned shortcut executes the transformation instantly.
4. Team-Wide Standardization and Multi-Project Sharing
A common question among engineering managers is: How do we sync these custom prompt templates across fifty developer laptops automatically?
The Current Platform Limitation
At present, JetBrains AI stores custom prompt templates within local IDE application configurations or personal Settings Sync accounts. The platform does not currently provide a native, one-click export/import mechanism for Prompt Library bundles, nor does it support checking .prompt files into source control directly from this specific menu. This requirement is tracked by JetBrains under YouTrack issue LLM-4067.
The 365Finds Solution: Combining Prompt Library with Project Rules
To standardise engineering workflows across a team today without manual copy-pasting, 365Finds recommends a dual-tier strategy:
+─────────────────────────────────────────────────────────────────────────+
| Tier 1: Project-Level Governance (.aiassistant/rules/*.md) |
| - Committed to Git repository root |
| - Controls architectural conventions, testing libraries, naming patterns|
| - Automatically injected into all JetBrains AI chat and refactor passes |
+───────────────────────────────────┬─────────────────────────────────────+
│ Governs execution baseline
▼
+─────────────────────────────────────────────────────────────────────────+
| Tier 2: Personal Tactile Triggers (Prompt Library) |
| - Local shortcuts with $SELECTION macros |
| - Fast keymap-bound triggers in Alt+Enter menus |
| - Prompts stay lean because global rules handle framework constraints |
+─────────────────────────────────────────────────────────────────────────+
-
Repository-Level Guardrails via
.aiassistant/rules:- In your project root, create a directory named
.aiassistant/rules/. - Add Markdown rule files, such as
refactoring-conventions.mdortest-standards.md. - In Settings | Tools | AI Assistant | Rules, verify these rules are set to
Alwaysor scopedBy file patterns(e.g.,*.java,src/**/*.ts). - Commit
.aiassistant/rules/to Git. Now, every engineer who checks out the repository inherits the same architectural constraints across all JetBrains AI actions.
- In your project root, create a directory named
-
Lean Custom Prompts:
- Because
.aiassistant/rulesenforces baseline constraints (e.g., "Always use JUnit 5 and assertJ; never use JUnit 4"), your custom prompt templates do not need hundreds of words of boilerplate rules. - A Prompt Library entry can remain as concise as:
Refactor $SELECTION to follow our repository DTO and domain conversion standards. - Provide a shared
ai-prompts.mdin the team's internal documentation or repositorydocs/folder, allowing engineers to paste standardized templates into their local Prompt Library during onboarding.
- Because
5. Strategic Comparison: Workflow Options
| Approach | Setup Effort | Team Consistency | Execution Speed | Maintenance Overhead |
|---|---|---|---|---|
| Ad-hoc Chat Prompting | Zero setup | Very low (prompts vary per developer) | Slow (requires typing and copy-pasting) | High cognitive debt |
| Prompt Library Alone | Low (configured per IDE) | Medium (relies on manual template sharing) | Extremely fast (single keystroke) | Low (stored in IDE settings) |
| Prompt Library + Project Rules (Recommended) | Medium (one-time Git commit) | Maximum (deterministic across entire repository) | Extremely fast (lean triggers + cached rules) | Minimal (version-controlled alongside code) |
6. Implementation Checklist for Engineering Leads
- Audit repetitive coding tasks (DTO mapping, error wrapping, docstring generation, test scaffolding).
- Establish repository-wide rules in
.aiassistant/rules/and commit them to version control. - Define standardized Prompt Library templates utilizing the
$SELECTIONmacro for each target routine. - Instruct developers to configure menu visibility and assign dedicated Keymap shortcuts for daily routines.
- Document shared templates in
docs/ai-workflows.mdto ensure seamless developer onboarding.
By parameterizing frequent refactorings with $SELECTION and anchoring coding rules directly in repository version control, development teams eliminate mechanical toil while keeping output rigorously standardized across the entire JetBrains ecosystem.
References
- Add and customize prompts | AI Assistant Documentation
- Configure project rules | AI Assistant Documentation
- AI Assistant in JetBrains IDEs | IntelliJ IDEA Documentation
- LLM-4067: Enhance the Prompt Library: Global Settings, Project Visibility, Export/Import
- JetBrains AI: AI Tools for Developers and Teams