Skip to content

Port reflection-3 to Claude Code as Stop-hook plugin #137

Closed

Description

@dzianisv

Context

Parent: #131 (portability verdict — Claude Code adapter declared viable).

In long CC sessions, the agent forgets project-level skill guidance (e.g. /take-ownership) and back-delegates to the user prematurely. reflection-3.ts already solves the equivalent problem in OpenCode via session.idle hook. This issue tracks porting that pattern to Claude Code.

Goal

A CC plugin that, on the Stop event:

  1. Grades whether the assistant actually finished the task (re-uses reflection-3 evaluator).
  2. If incomplete, injects a follow-up prompt via decision: "block" + additionalContext to keep the agent driving.
  3. Honors stop_hook_active to prevent infinite loops.
  4. Detects planning/action loops and back-delegation to the user as failure modes.

Success Metric

Manual smoke: open a fresh CC session in this repo, give a multi-step coding task, observe at least one Stop→inject→continue cycle where the plugin successfully re-prompts the agent. Plugin must NOT loop more than 3 times on same failure mode, and must not fire when stop_hook_active=true.

Scope

  • New: claude/ directory containing the plugin (manifest + hook + bin script)
  • Reuse: import core grading/loop-detection from a shared module extracted from reflection-3.ts (or, speed path, copy + adapt)
  • Out of scope: Codex adapter (Assess portability of OpenCode plugins to Codex and Claude Code #131 says App Server sidecar — separate issue)

Acceptance Criteria

  • .claude-plugin/plugin.json valid, installable via claude --plugin-dir
  • Stop hook injects follow-up prompt for incomplete tasks
  • stop_hook_active loop guard implemented
  • Real-feature smoke test passes (documented in .tasks/.../test-report.md)
  • Atomic commits per phase

Activity

  1. dzianisv commented on May 26, 2026

    @dzianisv
    OwnerAuthor

    Shipped in #139 as 28d1aa0.

    Post-merge prod verify: PASS

    Plugin installed globally on dev machine via ~/.claude/settings.json (settings-based path is authoritative for CC v2.1.150 — --plugin-dir does not enable Stop hooks in -p mode; see follow-up note in #139).

    Real CC session (claude -p headless, fresh /tmp dir) → Stop hook fired → classifier ran (Haiku 4.5 via OAuth) → category=complete confidence=0.99 → no inject (correct, trivial Q&A). Hook latency ~870ms.

    Evidence: .tasks/131-cc-reflection/smoke-evidence/prod-verify/

    Follow-ups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions