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
Click a segment to jump to that moment
29msession
2interventions
by library · 4h
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.
- +0Prompt · +0Add a pi hook that reminds the agent to clean up/simplify/refactor code before committing, since first drafts are often functional but not clean.
- +0mAgent did · +0mExplored existing Claude Code hook patterns (global hooks, PreToolUse prompt hooks) and proposed a git-commit hook using Claude Code conventions.
- +6mIntervention · +6mDeveloper 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.
- +6mAgent did · +6mRead 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.
- +7mAgent did · +7mWrote code-cleanup.ts extension that injects a cleanup reminder before git commit runs, skipping amend-only commits.
- +8mIntervention · +8mDeveloper 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.
- +8mFail · +8mThe edit to make the hook opt-in corrupted the file, requiring a full rewrite.
- +8mAgent did · +8mRewrote 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).
- +21mAgent did · +21mAdded AGENTS.md with workflow, TUI consistency/performance, and testing guidelines for the economist-cli project, then committed it (cdc5be8).
- +29mOutcome · +29mCreated 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.