Repository navigation
fix(hooks): register the bash hook functions only once - #18
Conversation
The bash hook appended preexec_invoke_cmd and precmd_invoke_cmd to the bash-preexec arrays without checking whether they were already there. Sourcing it again in the same shell (source ~/.bashrc, which the installer suggests to reload) registered both twice: every command then sent two pre events, the first precmd consumed LAST_COMMAND, and the second sent no post, so pre and post no longer paired up. Append each function only when its array doesn't already contain it. The zsh and fish hooks define their hooks as functions, so sourcing them again only redefines them; they are unchanged. Same file as model/hooks/bash.bash in shelltime/cli, which carries the regression test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014EpZRfDAbFPp8o8CM7ED6j
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
☁️ Claude Code cloud · Prevent duplicate Bash hook registrationMade the Bash hook registration idempotent and added regression coverage for repeatedly sourcing the hook.
5.9M tokens: 82 input · 30.8K output · 5.7M cache read · 162.3K cache write 📝 AI summaryUpdated Extended View this session on ShellTime → Updated 2026-11-11 15:25 UTC by ShellTime · totals for the whole session so far · the session page is visible to its owner |
Problem
hooks/bash.bashappendedpreexec_invoke_cmdandprecmd_invoke_cmdto the bash-preexec arrays without checking whether they were already there. bash-preexec returns early when it is sourced again, sosource ~/.bashrcin a shell that already loaded the hook (whatinstall.bash's next steps suggest) registered both twice. Every command then sent twoshelltime track -p=precalls and one post, so pre and post no longer paired up.Fix
Each function is appended only when its array doesn't already contain it. The rest of the hook is unchanged. The zsh and fish hooks define their hooks as functions, so re-sourcing them only redefines them. I checked both in interactive zsh and fish, and they are untouched.
This is the same file as
model/hooks/bash.bashin shelltime/cli (shelltime/cli#346), which carries the regression test that sources the hook twice in one bash.cmpconfirms the two copies are identical, as arezsh.zshandfish.fish.Generated by Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.