Skip to content

fix(hooks): register the bash hook functions only once - #18

Merged
AnnatarHe merged 1 commit into
mainfrom
claude/affectionate-rubin-q3mstr
Nov 10, 2026
Merged

AnnatarHe merged 1 commit into
mainfrom
claude/affectionate-rubin-q3mstr

Conversation

@AnnatarHe

@AnnatarHe AnnatarHe commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

hooks/bash.bash appended preexec_invoke_cmd and precmd_invoke_cmd to the bash-preexec arrays without checking whether they were already there. bash-preexec returns early when it is sourced again, so source ~/.bashrc in a shell that already loaded the hook (what install.bash's next steps suggest) registered both twice. Every command then sent two shelltime track -p=pre calls 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.bash in shelltime/cli (shelltime/cli#346), which carries the regression test that sources the hook twice in one bash. cmp confirms the two copies are identical, as are zsh.zsh and fish.fish.


Generated by Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T15:25:44.359701Z eb6de16 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@shelltime

shelltime Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

☁️ Claude Code cloud · Prevent duplicate Bash hook registration

Made the Bash hook registration idempotent and added regression coverage for repeatedly sourcing the hook.

💰 Cost 🔢 Tokens ⏱️ Duration 🧠 Model 💬 Prompts ✏️ Lines
$3.06 5.9M 18m (6m active) claude-opus-5-5 2 +111 / −3

5.9M tokens: 82 input · 30.8K output · 5.7M cache read · 162.3K cache write

📝 AI summary

Updated /home/user/cli/model/hooks/bash.bash so preexec_invoke_cmd and precmd_invoke_cmd are not appended to their respective Bash function arrays when already registered. This prevents duplicate shelltime track -p=pre calls and mismatched pre/post tracking after users re-source ~/.bashrc in an existing shell.

Extended /home/user/cli/model/hooks_regression_test.go with regression coverage for loading the hook multiple times, verifying each callback remains registered only once. The related changes were then merged as requested.

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

@AnnatarHe
AnnatarHe merged commit f63fc40 into main Nov 10, 2026
3 of 9 checks passed
@AnnatarHe
AnnatarHe deleted the claude/affectionate-rubin-q3mstr branch November 10, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants