Skip to content
PitestsCLI & tooling3 files · +214 −29

Add pi extension hook to remind agent to clean up code before commits

Session from economist-tui-sessions on Hugging Face by thomasmustier · MIT · condensed by Coders Talk

29msession
2interventions
GOAL

Build a hook for the pi coding agent that reminds it to review and simplify code quality before git commits, following the existing long-task-harness hook pattern.

  1. Prompt · +0
    Add a pi hook that reminds the agent to clean up/simplify/refactor code before committing, since first drafts are often functional but not clean.
  2. Agent did · +0m
    Explored existing Claude Code hook patterns (global hooks, PreToolUse prompt hooks) and proposed a git-commit hook using Claude Code conventions.
  3. Intervention · +6m
    Developer clarified they wanted a *pi* extension, not a Claude Code hook, and pointed the agent at pi-mono docs.
    Why: No, no a *pi* hook. Read ~/pi-mono/ to find out about extensions.
  4. Agent did · +6m
    Read pi-mono docs and the existing long-task-harness.ts extension, then proposed a tool_call hook on git commit as a new pi extension option.
  5. Agent did · +7m
    Wrote code-cleanup.ts extension that injects a cleanup reminder before git commit runs, skipping amend-only commits.
  6. Intervention · +8m
    Developer asked to change the hook from a global always-on hook to a per-project opt-in.
    Why: Oh wait can we do project level opt-in rather than have this be a general hook.
  7. Fail · +8m
    The edit to make the hook opt-in corrupted the file, requiring a full rewrite.
  8. Agent did · +8m
    Rewrote code-cleanup.ts as opt-in via a .pi/code-cleanup.md marker file, enabled it for the economist-cli project, and committed the addition (feac37d).
  9. Agent did · +21m
    Added AGENTS.md with workflow, TUI consistency/performance, and testing guidelines for the economist-cli project, then committed it (cdc5be8).
  10. Outcome · +29m
    Created an opt-in pi extension for pre-commit code cleanup reminders and an AGENTS.md guidelines file, across two commits (feac37d, cdc5be8).
VERDICT

Next time I'd specify upfront that I mean a pi extension, not a Claude Code hook, to skip the initial detour through the wrong tooling. The intervention to make the hook opt-in per project rather than global was the right call - the corrupted edit that followed cost a bit of time but the rewrite fixed it cleanly. Overall a quick, low-risk session that produced a working, scoped extension plus some useful project docs.

I tried this · 0

Discussion · 0

How Builds work