Skip to content

fix: Provide OPENCODE & AGENT env vars#3843

Merged
rekram1-node merged 6 commits intoanomalyco:devfrom
stevoland:fix/agent-env-vars
Nov 4, 2025
Merged

fix: Provide OPENCODE & AGENT env vars#3843
rekram1-node merged 6 commits intoanomalyco:devfrom
stevoland:fix/agent-env-vars

Conversation

@stevoland
Copy link
Copy Markdown
Contributor

Plus generic AGENT var used by eg bun test: https://bun.com/docs/test#environment-variables

(I don't think you can mutate the environment as currently attempted)

@stevoland stevoland marked this pull request as ready for review November 3, 2025 20:44
})(),
})

process.env["OPENCODE"] = "1"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why remove this?

should we just also set AGENT=1 here too instead?

Note there is also the user invoked commands in prompt.ts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll take a look at prompt. I just don't think a process can mutate its environment like this? Might be wrong of course but it certainly doesn't work for the bash spawn

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the env vars to the shell prompts 40b3730

Happy to revert the - process.env["OPENCODE"] = "1" change but atm I don't see how it has ever served its intended purpose.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

according to bun docs u can: https://bun.com/docs/runtime/environment-variables

sorry, just seen this. Interesting:

  • My unit tests fail on dev

  • Interactive session fails on dev:

print the value of OPENCODE env var
stevoland (10:44:17 PM)
I'll check the value of the OPENCODE environment variable for you.
# Print OPENCODE environment variable value
$ echo $OPENCODE
The OPENCODE environment variable is not set or is empty in your current environment.
  • but opencode run works on dev:
$ opencode run "print the OPENCODE env var"


I'll check the OPENCODE environment variable for you.

|  Bash     echo $OPENCODE

1


The OPENCODE environment variable is set to `1`.

I've re-added the mutation (and AGENT) out of caution b939a9d

Thanks

@rekram1-node
Copy link
Copy Markdown
Collaborator

thanks for PR, couple questions for u

This works as-is `opencode run` for not for interactive sessions
@stevoland stevoland changed the title fix: Provide OPENCODE env var to bash tool fix: Provide OPENCODE & AGENT env vars Nov 3, 2025
@rekram1-node
Copy link
Copy Markdown
Collaborator

found the issue, when we spawn a worker we weren't passing process.env to it

@rekram1-node rekram1-node merged commit 0538f43 into anomalyco:dev Nov 4, 2025
3 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 4, 2025
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
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.

2 participants