Skip to content

feat(ops): session-start hook — install deps and enforce branch naming#984

Merged
ashleyshaw merged 6 commits into
developfrom
chore/session-nqdk8j
Jun 18, 2026
Merged

feat(ops): session-start hook — install deps and enforce branch naming#984
ashleyshaw merged 6 commits into
developfrom
chore/session-nqdk8j

Conversation

@ashleyshaw

@ashleyshaw ashleyshaw commented Jun 18, 2026

Copy link
Copy Markdown
Member

Chore Pull Request

This repository enforces changelog, release, and label automation for all PRs and issues.
See the organisation-wide Automation Governance & Release Strategy for required rules.

Linked issues

Relates to #984 — no separate issue; this is a self-contained ops improvement tracked in this PR.

Summary

Adds a Claude Code remote session-start hook that automatically installs npm dependencies and renames auto-generated claude/ prefixed branches (explicitly forbidden by CLAUDE.md) to valid chore/session-{hash} names before any work begins.

Changes

  • Added .claude/hooks/session-start.sh — detects claude/ branch prefix, renames locally and on origin to chore/session-{hash}, prints action-required banner to rename further before committing. Handles branch names without hyphens; push failures are non-fatal so they don't block session startup.
  • Added .claude/settings.json — registers the hook under SessionStart
  • Updated CHANGELOG.md with entry under [Unreleased] > Added

Impact / Compatibility

  • Runtime/behaviour changes: Remote Claude Code sessions on this repo will auto-rename claude/ branches at startup
  • Build/dev-experience impact: Reduces manual branch cleanup and wasted token overhead from forbidden-branch PRs

Verification

  • CI passes locally (npm install + 43 tests green)
  • Hook executed and renamed claude/admiring-mendel-nqdk8jchore/session-nqdk8j successfully
  • chore/session-nqdk8j passes npm run validate:branch-name

Risk & Rollback

  • Risk level: Low
  • Rollback plan: Delete .claude/hooks/session-start.sh and .claude/settings.json

Changelog

Added

  • Claude Code session-start hook — Added .claude/hooks/session-start.sh and .claude/settings.json to install npm dependencies and auto-rename auto-generated claude/ prefixed branches (forbidden by CLAUDE.md) to valid chore/session-{hash} names at the start of every remote session. Prevents forbidden branch names from ever reaching a commit and reduces manual cleanup overhead. (#984)

Checklist (Global DoD / PR)

  • All AC met and demonstrated
  • Tests added/updated — existing branch-name validation suite covers renamed branch format
  • Accessibility checklist: N/A — tooling-only change, no UI
  • Docs/readme/changelog updated (CHANGELOG.md updated)
  • Security checklist: hook reads only local git branch name; no untrusted input; no secrets introduced
  • CI green; release notes prepared in CHANGELOG.md

🤖 Generated with Claude Code

https://claude.ai/code/session_01RjsaYw9xviBvDkgSAEsQsc

…naming

Adds a Claude Code remote session-start hook that:
- Installs npm dependencies at session start so linters and tests are ready
- Detects auto-generated claude/ prefixed branches (forbidden by CLAUDE.md)
  and renames them to chore/session-{hash} with a prominent action-required
  notice to rename to a meaningful {type}/{scope}-{title} branch before work

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RjsaYw9xviBvDkgSAEsQsc
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@ashleyshaw, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 22 minutes and 31 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 5ab74da9-e65a-472e-9b44-7e60cb7cd5f4

📥 Commits

Reviewing files that changed from the base of the PR and between e24b51c and 0a144f7.

📒 Files selected for processing (3)
  • .claude/hooks/session-start.sh
  • .claude/settings.json
  • CHANGELOG.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/session-nqdk8j

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

✅ Template check passed after update. Thanks for fixing the PR description.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

🔍 Reviewer Summary for PR #984

CI Status:success
Files changed: 3
Risk Distribution: 0 critical, 0 high, 0 medium, 3 low

Recommendations

  • Ready to proceed pending human review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a session-start hook for Claude Code remote sessions, which installs npm dependencies and automatically renames forbidden claude/ branches to chore/session-{hash}. The feedback suggests correcting a redundant nested array structure in the settings schema, using npm ci instead of npm install for reproducible builds, handling branch names without hyphens to ensure the forbidden prefix is correctly stripped, and gracefully handling remote push failures to prevent blocking the session startup.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread .claude/settings.json
Comment on lines +3 to +12
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh"
}
]
}
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The nested hooks array inside SessionStart is redundant and does not match the standard Claude Code settings schema. It should directly contain the hook command object.

    "SessionStart": [
      {
        "type": "command",
        "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh"
      }
    ]

Comment thread .claude/hooks/session-start.sh Outdated
# ── 1. Install npm dependencies ──────────────────────────────────────────────
echo "==> Installing npm dependencies..."
cd "${CLAUDE_PROJECT_DIR:-.}"
npm install --prefer-offline --no-fund --no-audit 2>&1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using npm install in automated hooks can modify the package-lock.json file and lead to dependency drift. It is highly recommended to use npm ci instead, which is faster, cleaner, and guarantees reproducible installations from the lockfile.

Suggested change
npm install --prefer-offline --no-fund --no-audit 2>&1
npm ci --prefer-offline --no-fund --no-audit 2>&1

Comment thread .claude/hooks/session-start.sh Outdated
Comment on lines +26 to +27
HASH_SUFFIX="${CURRENT_BRANCH##*-}"
NEW_BRANCH="chore/session-${HASH_SUFFIX}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the auto-generated branch name does not contain a hyphen (e.g., claude/test), ${CURRENT_BRANCH##*-} will evaluate to the entire branch name. This results in NEW_BRANCH being chore/session-claude/test, which still contains the forbidden claude/ prefix. Handling the absence of a hyphen ensures the prefix is always correctly stripped.

Suggested change
HASH_SUFFIX="${CURRENT_BRANCH##*-}"
NEW_BRANCH="chore/session-${HASH_SUFFIX}"
if [[ "$CURRENT_BRANCH" == *-* ]]; then
HASH_SUFFIX="${CURRENT_BRANCH##*-}"
else
HASH_SUFFIX="${CURRENT_BRANCH#claude/}"
fi
NEW_BRANCH="chore/session-${HASH_SUFFIX}"

Comment thread .claude/hooks/session-start.sh Outdated

# Push the new branch name to origin and delete the old remote branch.
# Use || true on the delete so a pre-deleted remote branch doesn't fail the hook.
git push -u origin "${NEW_BRANCH}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the remote push fails (e.g., due to network issues, lack of write permissions, or missing remote configuration), the script will exit with an error due to set -e, which might block the Claude session from starting. It is safer to handle push failures gracefully.

Suggested change
git push -u origin "${NEW_BRANCH}"
git push -u origin "${NEW_BRANCH}" || echo "==> Warning: Could not push the new branch to origin."

claude added 2 commits June 18, 2026 12:48
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RjsaYw9xviBvDkgSAEsQsc
…in session hook

- Add fallback for branch names without hyphens (e.g. claude/test) to strip
  the prefix correctly rather than producing chore/session-claude/test
- Make the origin push non-fatal so network failures don't block session startup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RjsaYw9xviBvDkgSAEsQsc
@ashleyshaw ashleyshaw marked this pull request as ready for review June 18, 2026 12:56
@ashleyshaw ashleyshaw enabled auto-merge (squash) June 18, 2026 12:56
Signed-off-by: Ash Shaw <ashley@lightspeedwp.agency>
@github-actions github-actions Bot added status:needs-review Awaiting code review type:chore Chore / small hygiene change priority:normal Default priority area:documentation Docs & guides lang:md Markdown content/docs type:feature Feature or enhancement meta:needs-changelog Requires a changelog entry before merge labels Jun 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 62448ff2d9

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .claude/settings.json
{
"hooks": {
"SessionStart": [
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Constrain the hook to real session starts

The hook group has no matcher, and the Claude Code hook reference says an omitted matcher fires for every SessionStart source, including clear and compact (https://code.claude.com/docs/en/hooks#sessionstart). In a remote session, /clear or automatic compaction will therefore rerun npm install instead of only initial setup, which can stall the agent and potentially dirty the worktree mid-task; scope this group to startup or startup|resume if that is the intended lifecycle.

Useful? React with 👍 / 👎.

Comment thread .claude/hooks/session-start.sh Outdated
# ── 1. Install npm dependencies ──────────────────────────────────────────────
echo "==> Installing npm dependencies..."
cd "${CLAUDE_PROJECT_DIR:-.}"
npm install --prefer-offline --no-fund --no-audit 2>&1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rename forbidden branches before installing dependencies

Because set -e is active, any npm install failure here, such as a registry, cache, or lockfile issue, exits before the branch-rename block runs. The Claude Code hook reference describes SessionStart as context-only with no blocking decision control (https://code.claude.com/docs/en/hooks#sessionstart-decision-control), so the session continues on the forbidden claude/* branch instead of being stopped; move the rename before dependency installation or make install failures non-fatal.

Useful? React with 👍 / 👎.

claude added 2 commits June 18, 2026 13:26
…urces

Two fixes from Codex review:
- Move branch rename before npm install so a failing install never leaves
  the session on a forbidden claude/ branch (set -e would exit early)
- Read source from stdin and exit early on clear/compact events so npm
  install does not re-run unnecessarily mid-session

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RjsaYw9xviBvDkgSAEsQsc
@github-actions github-actions Bot added type:chore Chore / small hygiene change and removed type:chore Chore / small hygiene change labels Jun 18, 2026
@ashleyshaw

Copy link
Copy Markdown
Member Author

@Mergifyio queue

@mergify

mergify Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • 🟠 Waiting for queue conditions
  • ⏳ Enter queue
  • ⏳ Run checks
  • ⏳ Merge
Waiting for
  • -closed [📌 queue requirement]
  • any of: [🔀 queue conditions]
    • all of: [📌 queue conditions of queue rule Merge queue]
      • any of: [🛡 GitHub branch protection]
        • check-neutral = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
        • check-skipped = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
        • check-success = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
      • any of: [🛡 GitHub branch protection]
        • check-neutral = Validate PR Template / validate-pr-template
        • check-skipped = Validate PR Template / validate-pr-template
        • check-success = Validate PR Template / validate-pr-template
    • all of: [📌 queue conditions of queue rule dependabot]
      • label=area:dependencies
      • any of: [🛡 GitHub branch protection]
        • check-neutral = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
        • check-skipped = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
        • check-success = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
      • any of: [🛡 GitHub branch protection]
        • check-neutral = Validate PR Template / validate-pr-template
        • check-skipped = Validate PR Template / validate-pr-template
        • check-success = Validate PR Template / validate-pr-template
All conditions
  • -closed [📌 queue requirement]
  • any of [🔀 queue conditions]:
    • all of [📌 queue conditions of queue rule Merge queue]:
      • any of [🛡 GitHub branch protection]:
        • check-neutral = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
        • check-skipped = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
        • check-success = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
      • any of [🛡 GitHub branch protection]:
        • check-neutral = Validate PR Template / validate-pr-template
        • check-skipped = Validate PR Template / validate-pr-template
        • check-success = Validate PR Template / validate-pr-template
    • all of [📌 queue conditions of queue rule dependabot]:
      • author~=^(dependabot\[bot\]|app/dependabot)$
      • label=area:dependencies
      • any of [🛡 GitHub branch protection]:
        • check-neutral = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
        • check-skipped = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
        • check-success = CI • Unified Checks (Lint, Test, Validate) / All Checks Passed
      • any of [🛡 GitHub branch protection]:
        • check-neutral = Validate PR Template / validate-pr-template
        • check-skipped = Validate PR Template / validate-pr-template
        • check-success = Validate PR Template / validate-pr-template
      • -conflict
      • -draft
      • base=develop
  • -conflict [📌 queue requirement]
  • -draft [📌 queue requirement]
  • any of [📌 queue -> configuration change requirements]:
    • -mergify-configuration-changed
    • check-success = Configuration changed
  • any of [📌 queue requirement]:
    • check-neutral = Mergify Merge Protections
    • check-skipped = Mergify Merge Protections
    • check-success = Mergify Merge Protections

@ashleyshaw ashleyshaw self-assigned this Jun 18, 2026
@ashleyshaw ashleyshaw requested a review from krugazul June 18, 2026 13:47
@ashleyshaw ashleyshaw merged commit 1d343d8 into develop Jun 18, 2026
23 checks passed
@ashleyshaw ashleyshaw deleted the chore/session-nqdk8j branch June 18, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:documentation Docs & guides lang:md Markdown content/docs meta:needs-changelog Requires a changelog entry before merge priority:normal Default priority status:needs-review Awaiting code review type:chore Chore / small hygiene change type:feature Feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants