Skip to content

Add --system-prompt-extras option to append file content to system prompt#4818

Open
mykolarudenko wants to merge 4 commits intoAider-AI:mainfrom
mykolarudenko:feature/system-prompt-extras
Open

Add --system-prompt-extras option to append file content to system prompt#4818
mykolarudenko wants to merge 4 commits intoAider-AI:mainfrom
mykolarudenko:feature/system-prompt-extras

Conversation

@mykolarudenko
Copy link

Summary

Add a new --system-prompt-extras CLI option that reads a file and appends its content to the system prompt before each LLM request.

Motivation

Many LLMs treat system prompts and user messages differently. To ensure the model strictly follows instructions, they should be added to the system prompt rather than user messages. This option allows users to inject custom instructions into the system prompt via an external file.

Closes #4817

Changes

  • aider/args.py: Added --system-prompt-extras argument in the "Other settings" group, accepting a file path
  • aider/coders/base_coder.py:
    • Added system_prompt_extras_file parameter to __init__
    • Modified fmt_system_prompt() to read the extras file and append its content to the system prompt on each call
  • aider/main.py: Pass args.system_prompt_extras to Coder.create()

Behavior

  • The file is read dynamically before each LLM request (not cached at startup), so changes to the file take effect immediately
  • If the file is not found or unreadable, a warning is displayed but aider continues to work normally
  • Compatible with CLI, YAML config (system-prompt-extras), and environment variables (AIDER_SYSTEM_PROMPT_EXTRAS)

Usage Example

# Create an extras file with custom system-level instructions
cat > extras.txt << 'EOF'
When a user makes a remark or comment, append it to ./aider_lore/user_comments.md.
If the user points out a mistake or you discover you made one, record the details
in ./aider_lore/my_mistakes.md so you do not repeat it and the user does not have
to flag the same issues multiple times.
EOF

# Run aider with the new option
aider --system-prompt-extras extras.txt

…ompt

- Add new CLI argument --system-prompt-extras in 'Other settings' group
- Read extras file dynamically before each LLM request in fmt_system_prompt()
- Fail gracefully with warning if file is not found or unreadable
- Support for CLI, YAML config, and environment variables

Closes Aider-AI#4817
Copilot AI review requested due to automatic review settings February 10, 2026 02:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for injecting additional instructions into the system prompt by specifying a file whose contents get appended before LLM requests.

Changes:

  • Added --system-prompt-extras CLI/config option to accept a file path.
  • Plumbed the option through main into coder creation.
  • Appended the file’s content during system prompt formatting.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
aider/args.py Adds the new --system-prompt-extras argument.
aider/main.py Passes args.system_prompt_extras into Coder.create().
aider/coders/base_coder.py Stores system_prompt_extras_file and appends file content during prompt formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1226 to 1231
# Add extra system prompt content from file if specified
if self.system_prompt_extras_file:
extras_content = self.io.read_text(self.system_prompt_extras_file)
if extras_content:
prompt = prompt + "\n\n" + extras_content.strip()

Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appending extras inside fmt_system_prompt() causes the extras file to be read and appended for every call (main system prompt, each example message, system reminders, etc.). This can duplicate the extras multiple times per request and even inject it into non-system example messages. Consider reading the extras file once per request (eg when assembling main_sys / system messages in format_chat_chunks()) and appending it only to the actual system prompt content.

Copilot uses AI. Check for mistakes.
if self.system_prompt_extras_file:
extras_content = self.io.read_text(self.system_prompt_extras_file)
if extras_content:
prompt = prompt + "\n\n" + extras_content.strip()
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extras_content.strip() changes the file’s content (removes leading/trailing whitespace/newlines). Since the option is described as appending the file content, it’s safer to preserve the text exactly (or at most rstrip a single trailing newline) so users can control formatting precisely.

Suggested change
prompt = prompt + "\n\n" + extras_content.strip()
# Preserve extras content formatting; at most remove a single trailing newline
if extras_content.endswith("\n"):
extras_content = extras_content[:-1]
prompt = prompt + "\n\n" + extras_content

Copilot uses AI. Check for mistakes.
Comment on lines 1227 to 1230
if self.system_prompt_extras_file:
extras_content = self.io.read_text(self.system_prompt_extras_file)
if extras_content:
prompt = prompt + "\n\n" + extras_content.strip()
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InputOutput.read_text() reports failures via tool_error; with the current placement this can emit an error message repeatedly on every prompt formatting when the file is missing/unreadable. To match the intended “warning but continue” behavior (and avoid spamming/inflating error counters), read silently and emit a tool_warning once (or throttle/reuse the last error).

Copilot uses AI. Check for mistakes.
auto_copy_context=args.copy_paste,
auto_accept_architect=args.auto_accept_architect,
add_gitignore_files=args.add_gitignore_files,
system_prompt_extras_file=args.system_prompt_extras,
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new CLI/config option introduces new behavior in prompt construction; please add/extend tests to cover that the extras file content is appended to the system prompt and that missing/unreadable files only produce a warning without breaking requests.

Copilot uses AI. Check for mistakes.
Read the extras file once per request and append only to the main
system prompt, avoiding duplication across example messages and
system reminders.
Only remove a single trailing newline instead of strip() to let
users control formatting precisely.
- test_system_prompt_extras_file: verify extras content is appended to system prompt
- test_system_prompt_extras_file_missing: verify graceful handling of missing file
- test_system_prompt_extras_file_reread_each_request: verify file is re-read dynamically
@CLAassistant
Copy link

CLAassistant commented Feb 10, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option: --system-prompt-extras to always append file content to system prompt for coder mode

2 participants