opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Add option to modify system prompt

Open ChaseRensberger opened this issue 1 year ago • 7 comments

I'd love the ability to edit the system prompt/toggle between system prompts. My main interest in this would be to be able to use the opencode interface for tasks other than coding. Like similar to toggling between PLAN and BUILD it'd be cool to toggle between CODE and CHAT or something like that.

ChaseRensberger avatar Jul 23 '25 05:07 ChaseRensberger

you can create custom modes with custom system prompts: https://opencode.ai/docs/modes/

adamdotdevin avatar Jul 23 '25 11:07 adamdotdevin

My fault for not checking the docs. Thanks for taking time out of your day to send that link.

ChaseRensberger avatar Jul 24 '25 05:07 ChaseRensberger

The link was broken, the correct one is: https://open-code.ai/en/docs/modes which says it is deprecated now. "Caution: Modes are now configured through the agent option in the opencode config. The mode option is now deprecated. Learn more.". As I understand we can now change our defined agent's system prompt:

{
  "$schema": "https://opencode.ai/config.json",
  "agent": {
    "build": {
      "mode": "primary",
      "model": "anthropic/claude-sonnet-4-20250514",
      "prompt": "{file:./prompts/build.txt}",
      "tools": {
        "write": true,
        "edit": true,
        "bash": true
      }
    },
    "plan": {
      "mode": "primary",
      "model": "anthropic/claude-haiku-4-20250514",
      "tools": {
        "write": false,
        "edit": false,
        "bash": false
      }
    },
    "code-reviewer": {
      "description": "Reviews code for best practices and potential issues",
      "mode": "subagent",
      "model": "anthropic/claude-sonnet-4-20250514",
      "prompt": "**You are a code reviewer. Focus on security, performance, and maintainability.**",
      "tools": {
        "write": false,
        "edit": false
      }
    }
  }
}

Even though this example does not showcase, we should change the plan and the build agent's system prompts.

cbarkinozer avatar May 15 '26 05:05 cbarkinozer

@cbarkinozer those are docs: https://opencode.ai/docs

hpietukhin avatar May 22 '26 10:05 hpietukhin

@cbarkinozer doesn't seem work in 2.2.4, unless I misconfigured something.

Have this opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "enabled_providers": ["llamacpp"],
  "provider": {
    "llamacpp": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "llama-server (local)",
      "options": { "baseURL": "http://127.0.0.1:9931/v1" },
      "models": {
        "local": {
          "name": "local llm"
        }
      }
    }
  },
  "model": "llamacpp/local",
  "small_model": "llamacpp/local",
  "agent": {
    "build": {
      "mode": "primary",
      "model": "llamacpp/local",
      "prompt": "hello world",
    }
  }
}

I launch opencode in Build plan, send a hi, then I look at the text being sent, and I see a bunch of unrelated junk like:

hello world\\n# Your Model\\n- Name: local llm\\n- Provider ID: llamacpp\\n- Model ID: local\\n# Code Mode\\n\\nThe tools listed below cannot be called directly. I did write the "hello world" but why would I ever want to spend tokens on useless information like "Model ID: local".

There's a lot of content, none of which I want to see for my local coding agent and the solution suggested doesn't work.

Hi-Angel avatar Nov 02 '26 15:11 Hi-Angel

I'm assuming this functional has regressed, so I created an issue describing how to reproduce it

Hi-Angel avatar Nov 02 '26 15:11 Hi-Angel

Update from the linked issue — turns out, the text I see in the prompt isn't considered part of the prompt by OpenCode, but instead kinda an additional info. I guess that turns that into an RFE… Edited the issue accordingly.

Hi-Angel avatar Nov 02 '26 16:11 Hi-Angel