Skip to content

Repository files navigation

claude-mem OpenCode OAuth Bridge

CI

简体中文 | Architecture | Troubleshooting

An unofficial, local-only bridge that lets claude-mem 13.12.4 use an OpenCode-managed ChatGPT OAuth session for memory compression. It implements only the non-streaming OpenAI Chat Completions surface required by claude-mem; it is not a general OpenAI API proxy.

This project is not affiliated with or endorsed by claude-mem, OpenCode, OpenAI, or Anthropic.

Architecture

The bridge no longer runs as a plugin inside an interactive OpenCode process. The installer creates three systemd user services:

Service Address Purpose
claude-mem-worker.service 127.0.0.1:37700 Receives and stores claude-mem events
claude-mem-opencode.service 127.0.0.1:37711 Dedicated opencode serve --pure inference process
claude-mem-opencode-bridge.service 127.0.0.1:37710 OpenAI-compatible adapter for the Worker

The dedicated OpenCode service clears Herdr environment variables, runs with --pure, and requires HTTP Basic Auth on port 37711. The bridge creates temporary OpenCode sessions, invokes the hidden claude-mem-compressor agent with openai/gpt-5.6-luna-fast, converts the response, and deletes each session. It never reads or copies OpenCode OAuth credential files.

A normally completed empty model response is returned as HTTP 200 with empty Assistant content. This is the claude-mem protocol signal for intentionally skipping an observation; only an empty response without a normal finish: stop state is treated as an error.

Requirements

  • Linux with a working systemd user session.
  • Node.js >=20.12.0.
  • OpenCode installed and authenticated with an OpenAI/ChatGPT OAuth account.
  • Access to openai/gpt-5.6-luna-fast in opencode models.
  • claude-mem 13.12.4 installed for OpenCode.
  • Bun, normally installed by the official claude-mem installer.
  • Runtime paths without whitespace, as required by the generated systemd units.

Windows, macOS, and custom CLAUDE_MEM_DATA_DIR locations are not supported by this installer.

Quick Start

  1. Install the pinned upstream version:

    npx claude-mem@13.12.4 install --ide opencode
  2. Confirm OpenCode authentication and model availability:

    opencode models
  3. Inspect the installation without changing files:

    git clone https://github.com/Empty-Jing/claude-mem-opencode-bridge.git
    cd claude-mem-opencode-bridge
    ./install.sh --dry-run
  4. Install and start the services:

    ./install.sh
  5. Verify all three endpoints:

    curl --fail http://127.0.0.1:37700/health
    set -a; source ~/.claude-mem/opencode-server.env; set +a
    curl --fail --user "$OPENCODE_SERVER_USERNAME:$OPENCODE_SERVER_PASSWORD" \
      http://127.0.0.1:37711/global/health
    curl --fail http://127.0.0.1:37710/health

No interactive OpenCode restart is required. The installer generates a separate random Bridge Token and stores it in ~/.claude-mem/settings.json with mode 600; it does not accept or copy an OAuth token.

Installed Files

Source Destination
src/bridge.mjs ~/.local/lib/claude-mem-opencode-bridge/bridge.mjs
config/opencode.json ~/.local/lib/claude-mem-opencode-bridge/opencode.json
src/claude-mem-compressor.md ~/.config/opencode/agent/claude-mem-compressor.md
generated OpenCode credentials ~/.claude-mem/opencode-server.env
generated Worker unit ~/.config/systemd/user/claude-mem-worker.service
generated OpenCode unit ~/.config/systemd/user/claude-mem-opencode.service
generated Bridge unit ~/.config/systemd/user/claude-mem-opencode-bridge.service

The installer does not replace ~/.config/opencode/plugins/claude-mem.js. When upgrading from the former plugin-based bridge, it restores the saved official bundle before removing the legacy bridge plugin. Original managed files, service states, and settings fields are recorded under ~/.claude-mem/opencode-bridge-state/.

Supported options:

./install.sh --dry-run
./install.sh --no-start

Uninstall

./uninstall.sh

Uninstall restores original managed files, service states, and only the settings fields changed by this project. It does not delete claude-mem.db, Chroma data, logs, the official claude-mem plugin, or other stored memories.

Security Model

  • All HTTP listeners bind to 127.0.0.1 only.
  • Compression requests require a random Bearer token separate from OAuth credentials.
  • The dedicated OpenCode API requires a separate random Basic Auth password.
  • Bearer tokens use a timing-safe comparison.
  • The compression agent denies all tools; the request also disables known tools.
  • Request bodies are limited to 2 MiB and responses use Cache-Control: no-store.
  • The Bridge is single-concurrency with at most eight waiting requests.
  • Temporary OpenCode sessions use an excluded work directory and are deleted on a best-effort basis.
  • Herdr process variables are removed from both dedicated services.

Conversation content is still processed by the model provider configured in OpenCode. Review OpenCode and provider privacy policies before using sensitive material. See SECURITY.md.

Documentation

License

Licensed under the Apache License 2.0. Upstream projects retain their own copyrights and licenses. See NOTICE.

About

Local-only OAuth bridge that lets claude-mem use OpenCode-managed ChatGPT authentication for memory compression.

Resources

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages