Skip to content

fix(agents): keep OpenCode identity through Claude hooks - #13385

Closed
mrcha033 wants to merge 1 commit into
stablyai:mainfrom
mrcha033:fix/opencode-inherited-claude-hook-identity
Closed

mrcha033 wants to merge 1 commit into
stablyai:mainfrom
mrcha033:fix/opencode-inherited-claude-hook-identity

Conversation

@mrcha033

@mrcha033 mrcha033 commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Keep an OpenCode pane identified as OpenCode when its exact live local foreground process and explicit native OC | ... title agree, even if Claude-compatible tooling posts an inherited Claude hook for the same pane.
  • Resolve the identity before main-process retention so renderer replay, sidebar/tab status, worktree.ps, headless, and mobile consumers receive the same corrected agent, while incompatible Claude session/model/tool metadata is removed.
  • Preserve hook precedence for shell foreground, missing or mismatched process evidence, launch-only hints, SSH panes, and remote-runtime PTYs; preserve launch-owner normalization for Pi/oh-my-pi and similar wrappers.
  • Suppress inherited child completion/provider-only events so a nested Claude-compatible hook cannot complete or attach a Claude session to the active OpenCode turn.

Related context: #8940, #12466, and the nested-hook precedence established in #3990. This fixes the residual inherited Claude-compatible hook path rather than the already-fixed generic title path.

Screenshots

No visual layout change. A fresh headed Electron run on the rebased commit verified that the tab and sidebar remain OpenCode after a real Claude-form hook reaches a renderer-created OpenCode PTY.

Testing

  • pnpm lint
  • pnpm typecheck (node, CLI, and web typechecks run through pnpm run build:desktop)
  • pnpm test (the pre-rebase identical patch ran 48,668 passing and 155 skipped tests with 6 unrelated baseline/environment failures; focused affected tests were rerun after rebase and GitHub CI owns the new full-suite run)
  • pnpm build (pnpm run build:desktop)
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Exact-SHA validation on rebased commit f54840c939998f38437e4d7aaa0e3980352ee43c:

  • independent QA matrix: 1,452 passed, 1 skipped across 17 files
  • core identity/runtime selection: 1,100 passed, 1 skipped across 4 files under Node 24
  • rebase-adjacent Prime Agent/process-recognition and canonical PTY hydration suites: 35/35 passed
  • lint, reliability, type-aware, max-lines, skill, and localization gates: passed
  • desktop build and node/CLI/web typechecks: passed
  • git diff --check: clean
  • fresh headed Electron QA: renderer store, main worktree.ps, tab, and sidebar all stayed OpenCode; Claude model/provider metadata was absent

The regression matrix covers local positive identity correction, exact launch-token/live-PTY binding, stale launch hints, shell return, process/title mismatch, first inherited Stop, inactive split-pane titles, SSH, remote-runtime PTYs, replay/remote ingestion, metadata filtering, Pi/oh-my-pi owner normalization, Prime Agent coexistence, and canonical PTY hydration.

AI Review Report

Five independent review lanes plus a debugging runtime audit reviewed exact rebased SHA f54840c939998f38437e4d7aaa0e3980352ee43c: goal verification, code quality, security, history/context, and QA all passed with no blockers. An earlier review found that connection IDs alone did not identify remote-runtime PTYs; the final patch adds an addressed-PTY remote-runtime guard and negative regression. Every lane was rerun after the main rebase.

The review explicitly checked macOS, Linux, and Windows compatibility. This PR changes no shortcuts, labels, filesystem paths, shell commands, or platform-specific process APIs; it uses the existing cross-platform PTY controller and shared agent/title normalization. It also checked local, SSH, and remote-runtime routing; supported-agent wrapper ownership; Prime Agent coexistence; canonical PTY hydration; split-pane behavior; main/renderer/headless/mobile consistency; performance; and UI quality. The only new process query is bounded and occurs only for a conflicting non-replay local hook without an already-protected parent identity.

Security Audit

The correction is classification, not authorization. Main-process corroboration requires the runtime-owned local hook endpoint, exact nonempty launch token, exact pane/leaf/tab/worktree binding, a connected local PTY, the current controller, and a bounded foreground-process result; those bindings are rechecked after the async probe. Replay and remote ingestion bypass the resolver, and renderer fallback excludes SSH and remote-runtime PTYs.

No dependency, wire contract, IPC surface, command execution, filesystem path, credential, or secret-handling change was introduced. Conflicting Claude provider-session/transcript/model/tool/subagent metadata is stripped before persistence and publication. Residual low risk: a process and title are controlled by the same local user and can spoof presentation classification, but no reviewed authorization consumer trusts this identity.

Notes

  • Rebasing onto upstream bf406720a059029cadaaeb56c79e6b8cc49d5dec preserved the stable patch ID exactly. Six later upstream commits contain four IME/key-remap changes, a release marker, and manual artifact sharing. The artifact commit adds unrelated imports and service methods in orca-runtime.ts, far from the PTY identity resolver; git merge-tree confirms the current PR and live main integrate without conflict.
  • Linux hosted manual QA was completed; platform-neutral controller behavior and macOS/Linux/Windows non-regression were reviewed statically and through mocked controller tests.
  • Open PRs fix(agents): preserve OpenCode identity for bare status titles #9135 and fix(sidebar): keep agent rows aligned with pane processes #10066 overlap conceptually but do not implement this inherited-hook/full-chain correction.
  • X/Twitter handle: not provided (none is configured on the contributor's GitHub profile).

@mrcha033
mrcha033 force-pushed the fix/opencode-inherited-claude-hook-identity branch from c197997 to f54840c Compare August 9, 2026 23:16
@hackerh3

Copy link
Copy Markdown

Repro data from 1.4.182 (stable), in case it helps validate this: the mismatch also occurs on panes that were started with OpenCode from the beginning, not only after switching a workspace's agent.

On one machine, same moment in time:

Source Reports
orca worktree ps --json → agents[].agentType claude=17, opencode=1
orca-data.json → worktreeMeta[].createdWithAgent opencode=9, claude=1
actual running processes opencode=9, claude=2
session-parse-cache.json → session.agent opencode for those same panes

So worktree ps reported claude for 7 of 9 live panes whose transcript, recorded resumeCommand (cd '<path>' && opencode --session 'ses_...'), and OS process were all OpenCode.

User-visible consequence is resume: the pane is labelled claude, so an OpenCode session id gets resumed with the Claude CLI and is not found. Matches #8940, and #12466 did not cover this path (no stray literal "claude" in the title — these are native OC | ... titles with an inherited Claude hook, exactly as this PR describes).

Happy to supply the raw JSON triples if useful.

@nwparker

Copy link
Copy Markdown
Contributor

Thanks for the investigation! Nested-agent identity is now handled on main by the nested-hook guards in #29264 and #29386 plus #33572 (the pane's owner reclaims the pane by session). Closing as superseded.

@nwparker nwparker closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants