Skip to content

Duplicate System Message Sent #1301

Closed
Closed

Description

@bepuca

It seems OpenCode sends two times the system prompt at the beginning of the conversation. The second time includes the <env> information, and the first is just the provider system prompt. I have only been able to test this with Azure OpenAI models, but from the code, I would suspect to happen for everything.

This is how I found out:

  1. Set up mitmproxy with uv tool install mitmproxy.
  2. Start it by running mitmweb.
  3. Trust the certificate
  4. Run opencode like so: HTTP_PROXY=http://127.0.0.1:8080 HTTPS_PROXY=http://127.0.0.1:8080 NODE_EXTRA_CA_CERTS="$HOME/.mitmproxy/mitmproxy-ca-cert.pem" opencode

After the first message, you can see in the browser the requests intercepted by opencode. When I look at them, they look like this (trimming irrelevant stuff):

{
    "model": "gpt-4.1",
    "max_tokens": 32000,
    "temperature": 0,
    "messages": [
        {
            "role": "system",
            "content": "You are opencode..."
        },
        {
            "role": "system",
            "content": "You are opencode..."
        },
        {
            "role": "user",
            "content": "Just tell me hello"
        }
    ],
    "tools": ....
}

Checking the diffs, between these two system messages, the only difference is:

Here is some useful information about the environment you are running in:
<env>
  Working directory: /Users/bernat/.config/opencode
  Is directory a git repo: no
  Platform: darwin
  Today's date: Fri Jul 25 2025
</env>
<project>
</project>

This, as expected, is repeated for every subsequent request of the conversation

$ opencode --version
0.3.67

Suspicion

I do not know enough about the caching mechanisms, so uncertain about opening a PR. But it looks to me like this line is duplicating the functionality immediately above. After removing it, I can see how there is two system messages: the first contains whatever the system prompt is, and the second the env info. I'd assume this to be correct?

https://github.com/sst/opencode/blob/fc13d057f8eb296ec8b08cbe11b37ef65a320a39/packages/opencode/src/session/index.ts#L629

Activity

  1. self-assigned this
    on Jul 25, 2025
  2. thdxr commented on Jul 25, 2025

    @thdxr
    Member

    yep i introduced this error - pushed a fix will release soon

  3. assigned and unassigned on Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions