pub struct SystemPromptGenerator { /* private fields */ }cli-integration only.Expand description
System prompt generator with output style support.
§System Prompt Structure
The generated system prompt follows this structure:
-
CLI Identity (required for CLI OAuth authentication)
- “You are Claude Code, Anthropic’s official CLI for Claude.”
- This MUST be included when using CLI OAuth and cannot be replaced
-
Base System Prompt (always included after identity)
- Tone and style, professional objectivity, task management
-
Tool Usage Policy (always included)
- Tool-specific guidelines
-
Coding Instructions (if
keep_coding_instructions: true)- Software engineering instructions
- Git commit/PR protocols
-
Custom Prompt (if output style has custom content)
- Style-specific instructions
-
Environment Block (always included)
- Working directory, platform, model info
Implementations§
Source§impl SystemPromptGenerator
impl SystemPromptGenerator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new generator with default style. CLI identity is NOT required by default.
Sourcepub fn with_cli_identity() -> Self
pub fn with_cli_identity() -> Self
Create a generator that requires CLI identity. Use this when using Claude CLI OAuth authentication.
Sourcepub fn require_cli_identity(self, required: bool) -> Self
pub fn require_cli_identity(self, required: bool) -> Self
Set whether CLI identity is required. CLI identity MUST be included when using Claude CLI OAuth.
Sourcepub fn with_style(self, style: OutputStyle) -> Self
pub fn with_style(self, style: OutputStyle) -> Self
Set the output style directly.
Sourcepub fn with_working_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn with_working_dir(self, dir: impl Into<PathBuf>) -> Self
Set the working directory for environment block.
Sourcepub fn with_model(self, model_id: impl Into<String>) -> Self
pub fn with_model(self, model_id: impl Into<String>) -> Self
Set the model information.
Sourcepub fn with_model_name(self, name: impl Into<String>) -> Self
pub fn with_model_name(self, name: impl Into<String>) -> Self
Set the model name explicitly.
Sourcepub async fn with_style_name(self, name: &str) -> Result<Self>
pub async fn with_style_name(self, name: &str) -> Result<Self>
Load and set an output style by name.
Searches in priority order:
- Project styles (.claude/output-styles/) - highest priority
- User styles (~/.claude/output-styles/)
- Built-in styles - lowest priority
Sourcepub fn generate(&self) -> String
pub fn generate(&self) -> String
Generate the system prompt.
§Prompt Assembly Logic
- CLI Identity: Only if
require_cli_identity: true(CLI OAuth) - Base System Prompt: Always included
- Tool Usage Policy: Always included
- Coding Instructions: Only if
keep_coding_instructions: true - Custom Prompt: Only if style has non-empty prompt
- Environment Block: Always included
Sourcepub fn generate_with_context(&self, additional_context: &str) -> String
pub fn generate_with_context(&self, additional_context: &str) -> String
Generate the system prompt with additional dynamic context.
This is used when rules or other dynamic content needs to be appended.
Sourcepub fn style(&self) -> &OutputStyle
pub fn style(&self) -> &OutputStyle
Get the current output style.
Sourcepub fn has_coding_instructions(&self) -> bool
pub fn has_coding_instructions(&self) -> bool
Check if coding instructions are included.
Trait Implementations§
Source§impl Clone for SystemPromptGenerator
impl Clone for SystemPromptGenerator
Source§fn clone(&self) -> SystemPromptGenerator
fn clone(&self) -> SystemPromptGenerator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SystemPromptGenerator
impl Debug for SystemPromptGenerator
Auto Trait Implementations§
impl Freeze for SystemPromptGenerator
impl RefUnwindSafe for SystemPromptGenerator
impl Send for SystemPromptGenerator
impl Sync for SystemPromptGenerator
impl Unpin for SystemPromptGenerator
impl UnwindSafe for SystemPromptGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more