Skip to content

Commit 226a833

Browse files
committed
docs: document Gemini authentication options for container
Add documentation for reusing existing Gemini CLI credentials and manual authentication flow inside the container.
1 parent 929e2a1 commit 226a833

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- [Building the Container Image](#building-the-container-image)
55
- [Build Arguments](#build-arguments)
66
- [Authentication Setup](#authentication-setup)
7+
- [Reusing Existing Gemini CLI Authentication](#reusing-existing-gemini-cli-authentication)
8+
- [Manual Gemini Authentication in the Container](#manual-gemini-authentication-in-the-container)
79
- [Environment File Option](#environment-file-option)
810
- [Important Environment Variables](#important-environment-variables)
911
- [Verifying Authentication](#verifying-authentication)
@@ -96,6 +98,76 @@ This gives the container access to:
9698
- `/home/bun/.local/share/opencode` through the home mount for persisted local OpenCode and memory-related state
9799
- `/work` for the project you want OpenCode to read and modify
98100

101+
### Reusing Existing Gemini CLI Authentication
102+
103+
If you already authenticated with `gemini-cli` on the host, the container can reuse that login
104+
automatically.
105+
106+
At startup, `entrypoint.sh` checks whether `~/.gemini/oauth_creds.json` exists inside the
107+
container. If it does, the Bun script `convert-gemini.auth.ts` converts that Gemini OAuth state
108+
into OpenCode's auth store at `~/.local/share/opencode/auth.json`.
109+
110+
Typical run pattern:
111+
112+
```bash
113+
docker run -it --rm \
114+
-v $HOME:/home/bun \
115+
-v ${PWD}:/work \
116+
opencode-cli:dev
117+
```
118+
119+
With that home-directory mount:
120+
121+
- host `~/.gemini/oauth_creds.json` becomes available in the container at `/home/bun/.gemini/oauth_creds.json`
122+
- the entrypoint converts it into OpenCode auth automatically before launching `opencode`
123+
- existing entries in `~/.local/share/opencode/auth.json` are preserved and only the `google` provider entry is updated
124+
125+
Notes:
126+
127+
- If `~/.gemini/oauth_creds.json` is not present, startup stays silent and OpenCode launches normally
128+
- If the Gemini credentials file exists but is malformed or missing required token fields, container startup fails so the problem is visible
129+
- The converter path inside the image is `/usr/local/bin/convert-gemini.auth.ts`
130+
131+
### Manual Gemini Authentication in the Container
132+
133+
If you do not already have reusable Gemini CLI credentials on the host, you can authenticate
134+
manually from inside the container with the `opencode-gemini-auth` plugin.
135+
136+
Start the container with a bash shell instead of the normal entrypoint:
137+
138+
```bash
139+
docker run -it --rm \
140+
--entrypoint bash \
141+
-v $HOME:/home/bun \
142+
-v ${PWD}:/work \
143+
opencode-cli:dev
144+
```
145+
146+
Then run the login flow manually inside the container:
147+
148+
```bash
149+
opencode auth login
150+
```
151+
152+
In the OpenCode prompt flow:
153+
154+
- select `Google`
155+
- select `OAuth with Google (Gemini CLI)`
156+
- complete the browser-based authorization flow
157+
158+
If you are running the container in an environment where the browser callback cannot be completed
159+
automatically, use the fallback flow described by the plugin and paste the redirected callback URL
160+
or authorization code when prompted.
161+
162+
After successful login, the credential is stored in your mounted home directory under OpenCode's
163+
data path, so future container runs can reuse it:
164+
165+
- `/home/bun/.local/share/opencode/auth.json` for provider auth
166+
- `/home/bun/.config/opencode` for config
167+
168+
Once this has been done once, subsequent normal container starts can use the stored OpenCode auth
169+
directly, without repeating the manual login flow.
170+
99171
### Environment File Option
100172

101173
If your OpenCode setup depends on provider-specific environment variables, keep them in a local

0 commit comments

Comments
 (0)