Skip to content

OpenCode compatibility: hook layer needs adaptation #39

Description

@jsirish

Context

throughline is tightly coupled to Claude Code's plugin hook system. The data layer (HANDOFF.md, logs, buffer) is already harness-agnostic via THROUGHLINE_DATA_DIR, but the hook layer needs adaptation for OpenCode.

Current State

Hook Architecture (Claude Code-specific)

hooks.json defines 5 Claude Code events:
- SessionStart → session-onboard.sh
- UserPromptSubmit → session-prompt.sh  
- PostToolUse → session-capture.sh
- PreCompact → session-precompact.sh
- SessionEnd → session-flush.sh

Claude Code Dependencies

  • `` variable in all hook scripts
  • Payload parsing assumes Claude Code's JSON structure:
    • .session_id (stable across compaction)
    • .tool_name, .tool_input, .tool_response
    • .source (startup/resume/clear/compact)
  • Scripts use Claude Code's hook event names

What's Needed for OpenCode

1. Event Mapping

OpenCode needs to map its events to throughline's hooks:

OpenCode Event throughline Hook Notes
Session start session-onboard.sh Inject HANDOFF pointer + git state
User input session-prompt.sh Capture redacted prompts
Tool execution session-capture.sh Capture tool actions
Context compaction session-precompact.sh Stamp boundary marker
Session end session-flush.sh Safety-net stamp

2. Script Adaptations

  • Replace `` with OpenCode's equivalent
  • Adjust payload parsing for OpenCode's JSON structure
  • Handle OpenCode's session ID mechanism (may differ from Claude Code's stable UUID)

3. Data Directory

THROUGHLINE_DATA_DIR is already portable - works across harnesses. Default .claude/throughline/ or custom path.

Implementation Options

Option A: Adapter Layer

Create an adapter that translates OpenCode events to Claude Code's format. Minimal changes to throughline scripts, but adds translation overhead.

Option B: Fork and Adapt

Fork throughline and adapt hook scripts for OpenCode's event system. More work upfront, but cleaner integration.

Option C: Abstract Hook Interface

Refactor throughline to define an abstract hook interface, with Claude Code and OpenCode as implementations. Most work, but enables multi-harness support.

Recommendation

Investigate OpenCode's hook/event system first to understand:

  • What events are available?
  • What's the payload structure?
  • Is there a plugin system that can call shell scripts?

Then choose the implementation path based on OpenCode's capabilities.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions