set -a; source ../.env; set +a; opencode --model opencode-go/kimi-k3
does three things in sequence.
1. set -a
Tells Bash:
Automatically export every variable that is subsequently defined.
Normally:
creates a shell variable, but it is not automatically exported to programs you launch.
With set -a:
is exported so child processes can see it.
2. source ../.env
Reads and executes the .env file located one directory above your current directory.
For example, if you are here:
then:
means:
If .env contains:
OPENCODE_API_KEY=your-key-here
then source loads that variable into the current shell.
Because set -a was enabled, it is also exported:
OPENCODE_API_KEY
│
▼
Bash shell
│
▼
opencode process
3. set +a
Turns automatic exporting back off.
This is important because you generally don't want every variable you subsequently create to automatically become an environment variable.
4. Start OpenCode with Kimi K3
opencode --model opencode-go/kimi-k3
This launches OpenCode and explicitly selects:
provider: opencode-go
model: kimi-k3
So the complete sequence is essentially:
# Temporarily enable automatic exporting
set -a
# Load environment variables from ../.env
source ../.env
# Stop automatic exporting
set +a
# Start OpenCode using Kimi K3 through OpenCode Go
opencode --model opencode-go/kimi-k3
One important detail
The .env file must contain the API key in a form Bash can source, for example:
OPENCODE_API_KEY="your-api-key"
And if your .env is one level above /var/www/html, adjust the path accordingly. ../.env is always relative to the directory where you execute the command.