feat: Multi-agent support with adapter pattern + Claude Code integration#2
Merged
feat: Multi-agent support with adapter pattern + Claude Code integration#2
Conversation
Refactors the monolithic flush.py into a core engine + adapter pattern to support multiple coding agents with consistent trace output. ## Architecture - **hooks/core.py** — Agent-agnostic engine: NormalizedEvent dataclass, turn assignment, span building, monotonic timestamps, Phoenix posting - **hooks/adapters/cursor.py** — Cursor adapter: buffer I/O, atomic drain, hook event normalisation (all 13 hook types) - **hooks/adapters/claude_code.py** — Claude Code adapter: JSONL transcript parser with tool_use/tool_result pairing, thinking blocks, sub-agent support - **hooks/flush.py** — New entrypoint: CLI with --agent flag, dispatches to the appropriate adapter then through the core pipeline ## New files - hooks/claude-code-trace-hook.sh — Claude Code Stop hook script - .github/workflows/ci.yml — CI with Python 3.10-3.13, lint, shellcheck ## Changes - install.sh: Auto-detects Cursor (~/.cursor/) and Claude Code (~/.claude/), installs hooks for each, registers Stop hook in Claude settings.json - docker-compose.yml: Exposes gRPC port 4317 for OTel collector - tests/test_flush.py: 35 tests (was 21) covering core engine, both adapters, and cross-adapter span parity - README.md: Multi-agent docs, architecture diagram, comparison table, badges ## Key design decisions - Both adapters produce identical span structures via NormalizedEvent - Claude Code uses Stop hook + transcript parsing (not OTel native) for trace-level parity with Cursor - Backward compatible: CURSOR_TRACES_* env vars still work - Adding a new agent = one adapter file + registry entry
- Add 'shellcheck source=/dev/null' directives for non-constant source in trace-hook.sh and claude-code-trace-hook.sh - Replace sed with bash parameter expansion for timestamp injection in trace-hook.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors the monolithic
flush.pyinto a core engine + adapter pattern to support multiple coding agents with consistent trace output in Phoenix.What changed
hooks/core.pyNormalizedEventdataclass, turn assignment, span building, Phoenix postinghooks/adapters/cursor.pyhooks/adapters/claude_code.pyhooks/flush.py--agentflag dispatching to adaptershooks/claude-code-trace-hook.shinstall.shdocker-compose.yml.github/workflows/ci.ymltests/test_flush.pyREADME.mdArchitecture
Key design decisions
NormalizedEvent→ consistent Phoenix traces regardless of agentCURSOR_TRACES_*env vars still workTests
All 35 tests pass: