Skip to content

State root consistency: migrate tmpdir state to CLAUDE_PLUGIN_DATA #30

@JohnnyVicious

Description

@JohnnyVicious

Summary

/opencode:setup --enable-review-gate may write config to a different state directory than the Stop hook reads from, depending on whether CLAUDE_PLUGIN_DATA is present in the execution environment.

This can make setup appear successful while the Stop hook still sees the default disabled state.

Local evidence

plugins/opencode/scripts/lib/state.mjs selects the state root as:

process.env.CLAUDE_PLUGIN_DATA
  ? path.join(process.env.CLAUDE_PLUGIN_DATA, "state")
  : path.join("/tmp", "opencode-companion")

setup is run through a Bash command from plugins/opencode/commands/setup.md. Hooks are run through Claude Code's hook system from plugins/opencode/hooks/hooks.json. Those two paths may not receive the same environment.

Expected behavior

Review gate state should be read and written from the same persistent location across setup commands, lifecycle hooks, and Stop hooks.

Suggested fix

Options:

  1. Make setup resolve the same persistent plugin-data path hooks use, even when CLAUDE_PLUGIN_DATA is absent.
  2. Have the setup command explicitly pass/derive CLAUDE_PLUGIN_DATA before invoking Node.
  3. As a compatibility bridge, write review-gate config to both the persistent state root and the legacy /tmp/opencode-companion fallback.

Add a regression test that simulates setup with no CLAUDE_PLUGIN_DATA and hook execution with CLAUDE_PLUGIN_DATA set.

Upstream reference

Derived from openai/codex-plugin-cc#59.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions