@ymchun/opencode-ollama-usageAn opencode TUI plugin for Ollama usage information.
0
351
近 7 天 196
32.5
生态多维模型
2 个月前
2026-06-18
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@ymchun/opencode-ollama-usage@1.1.2"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@ymchun/opencode-ollama-usage@1.1.2"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @ymchun/opencode-ollama-usageopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
An opencode TUI plugin for Ollama usage information.


Why This Plugin
A quick shortcut to check my quota usage would be fantastic, rather than navigating to the settings page every time.
Quick Start
Add the plugin to your ~/.config/opencode/tui.json & start opencode:
{
"$schema": "https://opencode.ai/tui.json",
"plugin": ["@ymchun/opencode-ollama-usage@latest"]
}
Environment Variables
OLLAMA_SESSION_COOKIE (required)
Your Ollama session cookie, used to authenticate requests to the Ollama settings page. Without it the plugin shows No Cookie in the sidebar.
How to get it:
- Sign in at ollama.com in your browser
- Open DevTools → Application → Cookies →
https://ollama.com - Copy the value of the cookie named
__Secure-session - Set it as the environment variable:
# In your shell profile (~/.zshrc, ~/.bashrc, etc.)
export OLLAMA_SESSION_COOKIE="<your-session-cookie-value>"
Or set it in your opencode.json:
{
"env": {
"OLLAMA_SESSION_COOKIE": "<your-session-cookie-value>"
}
}
Note: The session cookie expires periodically. When it does, the plugin will show Signed Out — repeat the steps above to update the value.
OLLAMA_QUOTA_REFRESH_INTERVAL (optional)
How often (in milliseconds) the plugin refreshes quota data. Defaults to 300000 (5 minutes).
export OLLAMA_QUOTA_REFRESH_INTERVAL=60000 # refresh every minute
Troubleshooting
Error Codes
The plugin shows different status messages in the sidebar depending on the state of your connection and quota data. Here's what each message means:
| Message | Meaning |
|---|---|
| Connect Ollama | No quota data has been fetched yet (initial state). |
| No Cookie | OLLAMA_SESSION_COOKIE is not set. |
| Signed Out | The session cookie has expired or is invalid. |
| Missing Data | The Ollama settings page loaded, but no quota fields (session, weekly, plan) could be extracted. |
| Network Error | The fetch to ollama.com/settings failed (timeout, DNS failure, or non-OK HTTP response). |
| Unknown Error | An unrecognized error occurred. |
Tip: You can force an immediate refresh by restarting
opencodeor by settingOLLAMA_QUOTA_REFRESH_INTERVALto a shorter interval (e.g.60000for 1 minute) to see if the issue resolves on the next cycle.
Using with agent-safehouse
Prepare an env file, place it somewhere (/path/to/agent-safehouse.env)
OLLAMA_QUOTA_REFRESH_INTERVAL=6000
OLLAMA_SESSION_COOKIE='__Secure-session=...'
Start the agent-safehouse as follows
$ safehouse --env=/path/to/agent-safehouse.env -- opencode --opencode-options
Development
bun install
bun run build
bun test
License
MIT