Duplicate System Message Sent #910

Closed
opened 2026-02-16 17:28:45 -05:00 by yindo · 1 comment
Owner

Originally created by @bepuca on GitHub (Jul 25, 2025).

Originally assigned to: @thdxr on GitHub.

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

Originally created by @bepuca on GitHub (Jul 25, 2025). Originally assigned to: @thdxr on GitHub. 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](https://docs.mitmproxy.org/stable/concepts/certificates/) 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): ```json { "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: ```text 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 ```shell $ 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
yindo closed this issue 2026-02-16 17:28:45 -05:00
Author
Owner

@thdxr commented on GitHub (Jul 25, 2025):

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

@thdxr commented on GitHub (Jul 25, 2025): yep i introduced this error - pushed a fix will release soon
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#910