Repository navigation
Closed
Labels
area:parserParsertheme:analysisAnalysis and context-pack utilitytool:claudeClaudetool:codexCodextype:featNew feature
Description
Problem
Post-hoc session JSONL misses high-value lifecycle and tool metadata: paste ground truth before expansion, tool annotations, structured MCP output, error subtypes, permission decisions, file diffs, cwd changes, and precise timing.
Claude Code and Codex both expose hook systems that can capture this data at creation time.
Target architecture
Hook capture should write structured hook artifacts through Polylogue's artifact/blob pipeline, linked to the session by link_group_key or equivalent provenance.
The integration should use the shared config system from #829 for install paths, enabled events, auth/token concerns, and provider-specific hook config generation.
Scope
- Ship a
polylogue-hookhandler or equivalent installed script. - Handle Claude Code hook events and Codex hook events through one normalized hook artifact schema where practical.
- Add
polylogue hooks installor another explicit install surface that writes the right provider config. - Ingest hook artifacts into blob/raw/artifact taxonomy and link them to sessions.
- Capture paste ground truth, tool annotations, structured outputs, errors/interrupts, permissions, cwd/file changes, and session lifecycle data where available.
- Leave room for future context injection at SessionStart, but do not make injection part of the first capture slice unless it is small and tested.
Non-goals
- Do not write untracked sidecar formats as the primary archive contract when blob/artifact storage can own the data.
- Do not require hooks for normal post-hoc JSONL ingestion.
- Do not implement temporal/cost/context features here; feat(insights): temporal session analysis — per-tool timing, thinking vs output split, latency breakdown #804/feat(insights): subscription-aware cost tracking with client-side tokenizer and per-model breakdown #803/feat(context): build project/date/query context packs for agent analysis #838 consume the captured data.
Acceptance criteria
- Hook handler handles the supported Claude Code and Codex events or records explicit unsupported-event behavior.
- Hook artifacts are stored through the archive/blob/artifact pipeline and linked to the parent session.
- Install/config flow is driven by feat(config): unified config system — polylogue.toml, four-layer precedence, shared daemon/CLI config #829 config conventions.
- Artifact taxonomy discovers hook artifacts alongside session JSONL.
- Paste ground truth and tool/error/permission metadata are captured in tests.
- Security/privacy boundaries are tested for local hook ingestion.
Metadata
Metadata
Assignees
Labels
area:parserParsertheme:analysisAnalysis and context-pack utilitytool:claudeClaudetool:codexCodextype:featNew feature
Activity
Sinity commentedon May 4, 2026
Sinity commentedon May 4, 2026
Claude Code Hook System → Polylogue Synergy
Hook system overview (from /realm/project/_inactive/claude-code-src)
Claude Code hooks are user-provided shell scripts executed at 16 lifecycle events. Each hook receives JSON on stdin with event-specific context and can return JSON on stdout to influence behavior or inject context.
16 hook events:
SessionStartSetupUserPromptSubmitPreToolUsePostToolUsePostToolUseFailurePermissionRequestPermissionDeniedNotificationElicitationElicitationResultCwdChangedFileChangedWorktreeCreateSubagentStartStopHook output capabilities:
additionalContext— inject text into Claude's system prompt (all events)permissionDecision— approve/block tool calls (PreToolUse)updatedInput— modify tool arguments before execution (PreToolUse)updatedMCPToolOutput— modify MCP tool results (PostToolUse)decision— answer permission requests (PermissionRequest)watchPaths— register paths for FileChanged hooks (SessionStart, CwdChanged)stopReason— custom stop message (Stop)Codex hook system (6 events)
Codex has an equivalent hook system at
/realm/project/_inactive/codex/codex-rs/hooks/:PreToolUsePostToolUsePermissionRequestSessionStartUserPromptSubmitStopCodex has 6 events vs Claude Code's 16. The same integration strategy works for both — a single handler script that writes structured JSONL. Codex discovers hooks differently (TOML config + JSON files, not just settings.json), but the output format can be identical. One
polylogue-hookscript handles both providers.Polylogue workflows BEYOND data capture
Hooks don't just let polylogue READ data — they let polylogue INJECT back into sessions:
Hooks provide data that is NOT in the session JSONL:
1. Paste ground truth (UserPromptSubmit)
The hook receives the prompt BEFORE paste expansion — with
[Pasted text #N]markers intact. This is exactly whathistory.jsonlprovides but for 100% of sessions, not 29.9%. One hook handler could write prompt text + paste markers to a polylogue sidecar file.2. Tool execution metadata (PreToolUse + PostToolUse)
Tool annotations (read_only/destructive), structured input/output, updated MCP tool results. This fills all 10 tool call schema gaps found by the upstream analysis. Data that exists at hook time but is never written to JSONL.
3. Error/interrupt data (PostToolUseFailure)
Error subtypes, interrupt flags, whether the failure is transient or permanent. Currently only described in SDK schemas, never exposed in transcripts.
4. Permission audit trail (PermissionRequest + PermissionDenied)
What was proposed, what was decided, who decided. Currently invisible in session JSONL.
5. Session lifecycle (SessionStart + Stop)
Model configuration at session start, working directory, permission mode. Final state at session end. Session start could trigger polylogue ingestion; session end could trigger finalization.
6. File change tracking (FileChanged)
Lines added/removed per file per tool call. Currently calculated by CC's diff engine but only surfaced in aggregated form.
7. Working directory tracking (CwdChanged)
All directory changes during the session, not just the initial cwd recorded in session JSONL.
Integration approach
Full: Ship a
polylogue hooks installCLI command that generates the hook configuration and installs the handler script. Each hook event writes to a dedicated sidecar file under.claude/polylogue-hooks/. Schema inference handles the auto-discovery of new event types.Why this is better than JSONL extraction
The hook system gives polylogue access to data at the moment of creation, before any downstream transformation or loss. This is a strictly richer data source than the session JSONL for several metadata dimensions.
Sinity commentedon May 4, 2026
Acceptance Criteria
polylogue-hookshell script handles all 16 CC events + 6 Codex eventspolylogue hook-ingest, linked to session vialink_group_keyWhen closing: comment on this issue or the PR explicitly stating how each criterion was satisfied, deferred, or found misframed.
Sinity commentedon May 6, 2026
Execution supplement
Mass-execution wave: #852 Wave 5 after #829 config is available where hook install/config paths need it.
Focused verification:
devtools verify --quick, then fulldevtools verifybefore PR.Do not make hook sidecars the canonical archive model; hook data should flow through artifact/blob/source ingestion semantics.
Sinity commentedon May 7, 2026
Reconnaissance Report: #802 feat(acquisition): Claude Code + Codex hook integration
Date: 2026-05-07 | Prep agent: file-search (read-only)
Codebase State
Hook code does not exist yet.
rg hook polylogue/returns only MCP server hook/plugin-registration paths — zero CC/Codex hook integration code exists. This is a green-field builder issue.Existing acquisition pipeline (the surface hooks must feed into):
polylogue/sources/dispatch.pypolylogue/sources/parsers/claude/code_parser.pyparse_code(),parse_stream())polylogue/sources/parsers/codex.pyparse(),parse_stream())polylogue/sources/assembly_claude_code.pypolylogue/sources/assembly_codex.pypolylogue/sources/source_acquisition.pypolylogue/pipeline/semantic_capture.pypolylogue/storage/artifacts/Config surface (where hook keys will live per #829):
polylogue/config.py—Configdataclass,Source,DriveConfig,IndexConfigpolylogue/paths/__init__.py—claude_code_path(),codex_path(),config_root(),data_root()polylogue/paths/_roots.py— XDG path resolutionBuild This
Hook handler script (
polylogue-hook): a single shell script handling all 16 CC events + 6 Codex events. Writes structured JSONL to a sidecar directory (e.g.,.claude/polylogue-hooks/). Each event type gets its own output stream.Hook event taxonomy (
polylogue/sources/hook_events.pyor similar): typed event payloads for each hook event, with shared provenance fields (session_id, cwd, timestamp, event_type). Schema inference for auto-discovery.Hook artifact ingestion (
polylogue/sources/hook_ingest.py): a source acquisition component that discovers hook sidecar files alongside session JSONL, reads them, validates event shapes, and routes them to the blob store withlink_group_keyconnecting them to the parent session.Hook install CLI (
polylogue cli hooks install): generates hook config in settings.json (or equivalent for Codex TOML), installs the handler script, and validates the hook pipeline end-to-end.Config keys in feat(config): unified config system — polylogue.toml, four-layer precedence, shared daemon/CLI config #829 (
polylogue.toml [hooks]section):enabled, path to handler script, sidecar output dir, event filter allowlist.Artifact taxonomy integration: hook artifacts appear alongside session JSONL in the artifact taxonomy with auto-discovered event types.
Do NOT Build
artifact/blob/sourceingestion semantics — the sidecar directory is ephemeral capture, the blob store is durable storage.polylogue-hookscript handles both.code_parser.py/codex.pyparse logic (except to link artifacts).Files to Touch
polylogue/sources/hook_events.pypolylogue/sources/hook_ingest.pypolylogue/cli/hook_commands.pypolylogue hooks installCLIpolylogue/sources/source_acquisition.pypolylogue/sources/dispatch.pypolylogue/config.pyHookConfigdataclasspolylogue/paths/_roots.pycontrib/polylogue-hookpolylogue/storage/artifacts/persistence.pyCoordination
[hooks]section in polylogue.toml, precedence, daemon/CLI parity).Focused Tests
Acceptance Criteria
polylogue-hookshell script handles all 16 CC events + 6 Codex eventspolylogue hook-ingest, linked to session vialink_group_keyAmbiguities / Stale Notes
polylogue/schemas/) rather than inventing a separate inference mechanism..claude/polylogue-hooks/as the sidecar dir — confirm this path against the existingpolylogue/paths/_roots.pyconvention (should use XDG data/cache dirs like other Polylogue paths)./realm/project/_inactive/codex/codex-rs/hooks/before implementing. The issue claims one handler script handles both, but the install path differs.Sinity commentedon May 7, 2026
Implementation Scope
What's being built
contrib/polylogue-hook) — handles all 16 CC events + 6 Codex events, writes structured JSONL to sidecar directoryArtifactKind.HOOK_EVENT, classification detection inclassify_artifact()PolylogueConfigwithhooks_sidecar_dir, add path resolution in_roots.pydefault_sources()so daemon picks up hook files automaticallydocs/hooks.md) — hook protocol, supported events, sidecar layout, example configsNon-goals (per issue instructions)
Files to touch
polylogue/archive/artifact_taxonomy/models.py— addHOOK_EVENTtoArtifactKindpolylogue/archive/artifact_taxonomy/support.py— addlooks_like_hook_event()detectionpolylogue/archive/artifact_taxonomy/runtime.py— classify hook eventspolylogue/paths/_roots.py— addhooks_sidecar_dir()polylogue/paths/__init__.py— exporthooks_sidecar_dirpolylogue/config.py— addhooks_sidecar_dirproperty, extend TOML mergepolylogue/sources/live/watcher.py— add hook sidecar todefault_sources()contrib/polylogue-hook— NEW shell scriptdocs/hooks.md— NEW documentationtests/unit/sources/test_hook_events.py— NEW testsAcceptance Criteria
polylogue-hookshell script handles all 16 CC events + 6 Codex eventslink_group_keyhooks_enabled, addinghooks_sidecar_dir)ArtifactKind.HOOK_EVENT)feat(acquisition): add hook integration for Claude Code + Codex (#802)
feat(acquisition): Claude Code and Codex hook integration (#937)
feat(acquisition): Claude Code and Codex hook integration (#937)
Sinity commentedon May 7, 2026
Closed-scope audit found the hook taxonomy captures
UserPromptSubmitpayload shape, but the paste-detection promise is not wired through to stored message/query semantics; leaving this issue closed and tracking reconciliation in #944.Evidence:
~/.claude/projects, Codex sessions, inbox, and hook sidecars, but not top-level~/.claude/history.jsonl.UserPromptSubmitrecords classify asArtifactKind.HOOK_EVENT, with tests preserving[Pasted text #N]markers, but I did not find code that converts those events into messagehas_pastefacts.polylogue/pipeline/materialization_runtime.pycurrently initializeshas_paste = 0for every materialized message, anddetect_paste()appears unit-tested but unused in production paths.#944 now tracks wiring paste evidence into materialization/derived updates or explicitly narrowing the claim.
feat(insights): session timeline renderer with fidelity tags (#1135) (#…
feat(pipeline): wire hook events to has_paste detection (#1313) (#1331)
audit(governance): closed-issue workload audit (#1310) (#1401)