add optional system prompt environment injection #1279

Open
opened 2026-02-16 17:30:16 -05:00 by yindo · 5 comments
Owner

Originally created by @Jacubeit on GitHub (Aug 13, 2025).

Originally assigned to: @thdxr on GitHub.

Agents can have their custom system prompt. Environment system prompt gets added regardless.
Making this optional would reduce tokens and increase prompt adherence if this info is not needed for the agent to fulfill its task.

if (process.env.OPENCODE_NO_ENV_PROMPT !== 'true') {
  system.push(...(await SystemPrompt.environment()))
}

Or even better: per agent in config, as system prompts can be defined there anyways:

 "agent": {
    "build": {
      "mode": "primary",
      "model": "anthropic/claude-sonnet-4-20250514",
      "prompt": "{file:./prompts/build.txt}",
      "envinfo": false
      ...
   }
}
Originally created by @Jacubeit on GitHub (Aug 13, 2025). Originally assigned to: @thdxr on GitHub. Agents can have their custom system prompt. Environment system prompt gets added regardless. Making this optional would reduce tokens and increase prompt adherence if this info is not needed for the agent to fulfill its task. ``` if (process.env.OPENCODE_NO_ENV_PROMPT !== 'true') { system.push(...(await SystemPrompt.environment())) } ``` Or even better: per agent in config, as system prompts can be defined there anyways: ``` "agent": { "build": { "mode": "primary", "model": "anthropic/claude-sonnet-4-20250514", "prompt": "{file:./prompts/build.txt}", "envinfo": false ... } } ```
Author
Owner

@calvinalkan commented on GitHub (Oct 1, 2025):

Yes, this is very important to keep a clean context window.

The environent information is injected AFTER a custom Agent prompt, which puts limits on how you can end it.

I think, what makes much more send is having a placerholder in the prompt that gets replaced if it's present. Similar to arguments with / commands.

@calvinalkan commented on GitHub (Oct 1, 2025): Yes, this is very important to keep a clean context window. The environent information is injected AFTER a custom Agent prompt, which puts limits on how you can end it. I think, what makes much more send is having a placerholder in the prompt that gets replaced if it's present. Similar to arguments with / commands.
Author
Owner

@rekram1-node commented on GitHub (Oct 1, 2025):

that's an interesting idea, kinda like it

@rekram1-node commented on GitHub (Oct 1, 2025): that's an interesting idea, kinda like it
Author
Owner

@taqtiqa-mark commented on GitHub (Oct 14, 2025):

The environent information is injected AFTER a custom Agent prompt

Still getting my bearings, but shouldn't any system prompt be added separately:

    const result = await generateObject({
      model: openai('gpt-4o'),
      system: `You are a SQL (postgres) ...`, // SYSTEM PROMPT AS ABOVE - OMITTED FOR BREVITY
      prompt: `Generate the query necessary to retrieve the data the user wants: ${input}`,
      schema: z.object({
        query: z.string(),
      }),
    });

Also rather than optionally inject a hardcoded system prompt wouldn't it be better to allow users to define a SYSTEM.md per agent, say for the hypothetical IDE agent:

agent/ide.md
agent/ide/SYSTEM.md
agent/ide/create-ticket.md
...

This suggests there are three prompt types: Primary, System and Sub-Agents

@taqtiqa-mark commented on GitHub (Oct 14, 2025): > The environent information is injected AFTER a custom Agent prompt Still getting my bearings, but shouldn't any system prompt be [added separately](https://ai-sdk.dev/cookbook/guides/natural-language-postgres#create-a-server-action): ```ts const result = await generateObject({ model: openai('gpt-4o'), system: `You are a SQL (postgres) ...`, // SYSTEM PROMPT AS ABOVE - OMITTED FOR BREVITY prompt: `Generate the query necessary to retrieve the data the user wants: ${input}`, schema: z.object({ query: z.string(), }), }); ``` Also rather than ***optionally*** inject a hardcoded system prompt wouldn't it be better to allow users to define a `SYSTEM.md` per agent, say for the hypothetical IDE agent: ```bash agent/ide.md agent/ide/SYSTEM.md agent/ide/create-ticket.md ... ``` This suggests there are three prompt types: Primary, System and Sub-Agents
Author
Owner

@calvinalkan commented on GitHub (Oct 14, 2025):

The environent information is injected AFTER a custom Agent prompt

Still getting my bearings, but shouldn't any system prompt be added separately:

const result = await generateObject({
  model: openai('gpt-4o'),
  system: `You are a SQL (postgres) ...`, // SYSTEM PROMPT AS ABOVE - OMITTED FOR BREVITY
  prompt: `Generate the query necessary to retrieve the data the user wants: ${input}`,
  schema: z.object({
    query: z.string(),
  }),
});

Also rather than optionally inject a hardcoded system prompt wouldn't it be better to allow users to define a SYSTEM.md per agent, say for the hypothetical IDE agent:

agent/ide.md
agent/ide/SYSTEM.md
agent/ide/create-ticket.md
...
This suggests there are three prompt types: Primary, System and Sub-Agents

AFAIK, the system prompt for an agent can be defined already and is used as it. The issue is how it's merged with environment specific stuff, which you have no control over.

@calvinalkan commented on GitHub (Oct 14, 2025): > > The environent information is injected AFTER a custom Agent prompt > > Still getting my bearings, but shouldn't any system prompt be [added separately](https://ai-sdk.dev/cookbook/guides/natural-language-postgres#create-a-server-action): > > const result = await generateObject({ > model: openai('gpt-4o'), > system: `You are a SQL (postgres) ...`, // SYSTEM PROMPT AS ABOVE - OMITTED FOR BREVITY > prompt: `Generate the query necessary to retrieve the data the user wants: ${input}`, > schema: z.object({ > query: z.string(), > }), > }); > Also rather than _**optionally**_ inject a hardcoded system prompt wouldn't it be better to allow users to define a `SYSTEM.md` per agent, say for the hypothetical IDE agent: > > agent/ide.md > agent/ide/SYSTEM.md > agent/ide/create-ticket.md > ... > This suggests there are three prompt types: Primary, System and Sub-Agents AFAIK, the system prompt for an agent can be defined already and is used as it. The issue is how it's merged with environment specific stuff, which you have no control over.
Author
Owner

@taqtiqa-mark commented on GitHub (Oct 14, 2025):

AFAIK, the system prompt for an agent can be defined already and is used as it.

Thanks. I see that Modes is now deprecated in favor of an agent option mode, and a mode did have a prompt option (which was the system prompt). However, agent docs say that mode has one option:

https://opencode.ai/docs/agents#mode:

The mode option can be set to primary, subagent, or all. If no mode is specified, it defaults to all.

So no more mode#prompt?

@taqtiqa-mark commented on GitHub (Oct 14, 2025): > AFAIK, the system prompt for an agent can be defined already and is used as it. Thanks. I see that Modes is now deprecated in favor of an agent option `mode`, and a mode did have a prompt option (which was the system prompt). However, agent docs say that mode has one option: https://opencode.ai/docs/agents#mode: > The mode option can be set to primary, subagent, or all. If no mode is specified, it defaults to all. So no more `mode#prompt`?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1279