cc-plugin-codex icon indicating copy to clipboard operation
cc-plugin-codex copied to clipboard

setup falsely reports missing hooks when an alternate CODEX_HOME symlinks the plugin cache

Open behruznassre opened this issue 2 weeks ago • 0 comments

Summary

$cc:setup reports found: 0 / ready: false for native plugin hooks, and tells the user to trust them manually, when Codex reports the hooks through a symlinked path to the plugin cache. The hooks are already trusted. Trusting them again in /hooks does not change the result.

Versions: cc@sendbird 1.5.0 (current main, 19e5651, has the same code), Node v26.13.1, macOS.

Setup that triggers it

An alternate Codex profile (CODEX_HOME=~/.codex-alt) shares the default profile's plugin cache through a symlink:

~/.codex-alt/plugins -> ~/.codex/plugins
companion ROOT_DIR:  ~/.codex/plugins/cache/sendbird/cc/1.5.0
hooks/list sourcePath: ~/.codex-alt/plugins/cache/sendbird/cc/1.5.0/hooks/hooks.json

hooks/list returns all four cc hooks with source: "plugin", pluginId: "cc@sendbird", trustStatus: "trusted". Setup still reports:

{ "attempted": true, "ready": false, "found": 0, "trusted": 0,
  "detail": "no native plugin hooks were reported for this plugin" }

and suggests "Open /hooks and trust this plugin's hooks manually, then rerun $cc:setup."

Cause

pathIsInsideRoot in scripts/claude-companion.mjs compares ROOT_DIR with path.resolve(filePath). path.resolve does not follow symlinks, so the alias path fails the containment check even though both paths name the same file. The source and plugin-ID checks pass, isCurrentPluginHook drops every hook, and found is 0.

scripts/lib/codex-paths.mjs already canonicalizes paths with fs.realpathSync.native (and a path.resolve fallback) in samePath. The containment check doesn't do the same.

Reproduction (isolated, uses the existing fake app-server harness)

I added this test next to setup trusts current native plugin hooks through Codex hooks/list in tests/integration/claude-companion.test.mjs. It symlinks a directory to PROJECT_ROOT and has the fake hooks/list report three trusted cc hooks through that alias. It also reports one untrusted cc@sendbird hook from a real file outside the plugin root, which must stay rejected.

Test
  it("setup recognizes trusted plugin hooks reported through a symlinked plugin root", () => {
    const testEnv = createTestEnvironment();
    const aliasRoot = path.join(testEnv.rootDir, "alias-plugin-root");
    fs.symlinkSync(PROJECT_ROOT, aliasRoot, "dir");
    const aliasSourcePath = path.join(aliasRoot, "hooks", "hooks.json");
    const outsideDir = path.join(testEnv.rootDir, "outside-plugin", "hooks");
    fs.mkdirSync(outsideDir, { recursive: true });
    fs.copyFileSync(path.join(PROJECT_ROOT, "hooks", "hooks.json"), path.join(outsideDir, "hooks.json"));
    const hook = (event, order, extra = {}) => ({
      key: `cc@sendbird:hooks/hooks.json:${event}:0:0`,
      eventName: event, handlerType: "command", matcher: null, command: "node hook.mjs",
      timeoutSec: 600, statusMessage: null, sourcePath: aliasSourcePath, source: "plugin",
      pluginId: "cc@sendbird", displayOrder: order, enabled: true, isManaged: false,
      currentHash: `sha256:${event}`, trustStatus: "trusted", ...extra,
    });
    const hooks = [
      hook("session_start", 0),
      hook("stop", 1),
      hook("user_prompt_submit", 2),
      hook("pre_tool_use", 3, {
        key: "cc@sendbird:outside:pre_tool_use:0:0",
        sourcePath: path.join(outsideDir, "hooks.json"),
        trustStatus: "untrusted",
      }),
    ];
    const fakeCodex = createFakeCodexAppServer(testEnv, hooks);
    try {
      const report = runCompanionJson(["setup", "--cwd", testEnv.workspaceDir, "--json"], {
        env: {
          ...testEnv.env,
          CC_PLUGIN_CODEX_EXECUTABLE: process.execPath,
          CC_PLUGIN_CODEX_APP_SERVER_ARGS_JSON: JSON.stringify([fakeCodex.serverPath]),
          CC_PLUGIN_CODEX_FORCE_HOOK_TRUST: "1",
        },
      });
      assert.equal(report.hookTrust.ready, true);
      assert.equal(report.hookTrust.found, 3);
      assert.equal(report.hookTrust.trusted, 0);
      assert.doesNotMatch(report.nextSteps.join("\n"), /trust this plugin's hooks manually/);
      const wroteTrust = readJsonLines(fakeCodex.logPath).some(
        (r) => r.method === "config/batchWrite" && r.params.edits.some((e) => e.keyPath === "hooks.state")
      );
      assert.equal(wroteTrust, false, "outside-root hook must not be trusted");
    } finally {
      cleanupTestEnvironment(testEnv);
    }
  });
  • On current main: fails with hookTrust = {"ready":false,"found":0,"trusted":0,"detail":"no native plugin hooks were reported for this plugin"}, the same result I see on the real installation.
  • After changing pathIsInsideRoot to canonicalize both ROOT_DIR and filePath (fs.realpathSync.native, falling back to path.resolve): passes with {"ready":true,"found":3,"trusted":0,"detail":"native plugin hooks already trusted (3)"}. The outside-root hook is still rejected, and no hooks.state write happens.

I ran only this test, not the full suite, against that change. I'll leave the implementation to you. Reusing the canonicalPath helper from codex-paths.mjs looks like the natural choice.

Expected vs. actual

  • Expected: setup counts the existing trusted hooks and reports them as ready.
  • Actual: setup drops every hook, reports them missing, and sends the user back to /hooks, where they already show as trusted.

Impact

Low. The setup status and the remediation advice are wrong for shared-cache alternate profiles. ensureClaudeReady doesn't gate on hook trust, so delegation commands still run.

behruznassre avatar Nov 12 '26 18:11 behruznassre