Skip to content

Fix: Disable agent hooks when Entire is not active#656

Open
pfleidi wants to merge 3 commits intomainfrom
fix/entire-disabled-hooks
Open

Fix: Disable agent hooks when Entire is not active#656
pfleidi wants to merge 3 commits intomainfrom
fix/entire-disabled-hooks

Conversation

@pfleidi
Copy link
Contributor

@pfleidi pfleidi commented Mar 7, 2026

Fix: Disable agent hooks when Entire is not active

Problem

When Entire was disabled via .entire/settings.json ("enabled": false) or never set up in a repository, agent hooks (Claude Code, Gemini CLI, etc.) still initialized logging on every invocation. Git hooks already had an early-exit guard via settings.IsSetUpAndEnabled() + a gitHooksDisabled flag, but agent hooks were missing an equivalent check in their PersistentPreRunE.

Additionally, IsEnabled() (used by executeAgentHook) returns true by default when no settings file exists — meaning agent hooks could proceed past the enabled check in repos where Entire was never set up.

Changes

cmd/entire/cli/hook_registry.go

Added a settings.IsSetUpAndEnabled(ctx) guard in the PersistentPreRunE of newAgentHooksCmd. When Entire is not set up or is disabled, the function returns nil early — skipping initHookLogging() and avoiding unnecessary file I/O and log initialization. The child command's RunE (executeAgentHook) still runs but bails out via its own IsEnabled() check.

Copilot AI review requested due to automatic review settings March 7, 2026 01:35
@pfleidi pfleidi requested a review from a team as a code owner March 7, 2026 01:35
@cursor
Copy link

cursor bot commented Mar 7, 2026

PR Summary

Low Risk
Small, localized change that only gates hook logging initialization based on existing settings state; low chance of impacting core hook behavior.

Overview
Agent hook subcommands now early-exit their PersistentPreRunE when settings.IsSetUpAndEnabled(ctx) is false, preventing initHookLogging() from running in repos where Entire is disabled or not configured.

This reduces unnecessary file I/O/log setup on agent hook invocations while leaving the underlying hook execution path unchanged.

Written by Cursor Bugbot for commit 089f952. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
if !settings.IsSetUpAndEnabled(cmd.Context()) {
return nil
}
Copy link

Choose a reason for hiding this comment

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

Agent hooks still execute when Entire never set up

Medium Severity

The new IsSetUpAndEnabled guard in PersistentPreRunE only skips logging initialization but doesn't prevent the child command's RunE from running. Unlike the git hooks pattern which uses a gitHooksDisabled flag checked in each child command, agent hooks have no equivalent. When Entire was never set up, executeAgentHook's IsEnabled() returns (true, err) with non-nil err, so the condition err == nil && !enabled is false and the hook proceeds to execute (parsing events, dispatching lifecycle, etc.). The fix doesn't achieve its stated goal for the "never set up" case.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to prevent agent hook commands (Claude Code, Gemini CLI, etc.) from doing work—especially initializing hook logging—when Entire is not active (not set up or disabled via .entire/settings.json).

Changes:

  • Added a settings.IsSetUpAndEnabled(ctx) guard to the agent hooks parent command’s PersistentPreRunE to skip hook logging initialization when Entire is inactive.

Comment on lines 56 to +59
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
if !settings.IsSetUpAndEnabled(cmd.Context()) {
return nil
}
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

With the new early-return, agentHookLogCleanup is no longer overwritten when Entire isn’t set up/enabled. Because it’s a package-level var and PersistentPostRunE will still run, this can call a stale cleanup function from a previous command execution (notably in tests that execute multiple commands in-process). Consider explicitly resetting agentHookLogCleanup (e.g., set to nil or a no-op) before returning early, and/or nil it out after calling it in PersistentPostRunE.

Copilot uses AI. Check for mistakes.
Comment on lines 56 to 60
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
if !settings.IsSetUpAndEnabled(cmd.Context()) {
return nil
}
agentHookLogCleanup = initHookLogging(cmd.Context())
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

Returning nil from PersistentPreRunE only skips logging init; the hook subcommand RunE will still execute. In repos where .entire/settings.json is missing, IsEnabled() defaults to true (via settings.Load), so executeAgentHook will still run lifecycle logic and can print the “Powered by Entire” banner / touch state. If the goal is to disable agent hooks when Entire isn’t active, add an early settings.IsSetUpAndEnabled(ctx) return in executeAgentHook (covers both built-in subcommands and the external-agent RunE fallback).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants