Skip to content

Commit c8697c8

Browse files
CLI-54: Register UserPromptSubmit hook in state.json
Both PreToolUse and UserPromptSubmit hooks were installed to .claude/settings.json, but only PreToolUse was tracked in state.json. Added UserPromptSubmit to HookType and registered both hooks after successful installation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b490468 commit c8697c8

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

src/commands/integrate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ async function updateStateAfterConfiguration(
364364
// Track installed hooks
365365
if (hooksInstalled) {
366366
addInstalledHook(state, 'claude-code', 'sonar-secrets', 'PreToolUse');
367+
addInstalledHook(state, 'claude-code', 'sonar-secrets', 'UserPromptSubmit');
367368
}
368369

369370
saveState(state);

src/lib/state-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import fs from 'node:fs';
2626
import crypto from 'node:crypto';
2727
import logger from './logger.js';
28-
import { CliState, getDefaultState, AuthConnection, CloudRegion } from './state.js';
28+
import { CliState, getDefaultState, AuthConnection, CloudRegion, HookType } from './state.js';
2929
import { CLI_DIR, STATE_FILE } from './config-constants.js';
3030
import { version as VERSION } from '../../package.json';
3131

@@ -174,7 +174,7 @@ export function addInstalledHook(
174174
state: CliState,
175175
agentName: string,
176176
hookName: string,
177-
hookType: 'PreToolUse' | 'PostToolUse' | 'SessionStart'
177+
hookType: HookType
178178
): void {
179179
if (!state.agents[agentName]) {
180180
state.agents[agentName] = {

src/lib/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type ServerType = 'cloud' | 'on-premise';
3636
/**
3737
* Hook type for agent integration
3838
*/
39-
export type HookType = 'PreToolUse' | 'PostToolUse' | 'SessionStart';
39+
export type HookType = 'PreToolUse' | 'PostToolUse' | 'SessionStart' | 'UserPromptSubmit';
4040

4141
/**
4242
* Single authentication connection

tests/unit/integrate.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ describe('integrateCommand: full flow', () => {
273273
it('tracks hooks in state when skipHooks is false', async () => {
274274
const discoverSpy = spyOn(discovery, 'discoverProject').mockResolvedValue(FAKE_PROJECT_INFO);
275275
const healthSpy = spyOn(health, 'runHealthChecks').mockResolvedValue(CLEAN_HEALTH);
276+
const addInstalledHookSpy = spyOn(stateManager, 'addInstalledHook');
276277

277278
try {
278279
await integrateCommand('claude', {
@@ -283,9 +284,12 @@ describe('integrateCommand: full flow', () => {
283284
skipHooks: false,
284285
});
285286
expect(mockExit).toHaveBeenCalledWith(0);
287+
expect(addInstalledHookSpy).toHaveBeenCalledWith(expect.anything(), 'claude-code', 'sonar-secrets', 'PreToolUse');
288+
expect(addInstalledHookSpy).toHaveBeenCalledWith(expect.anything(), 'claude-code', 'sonar-secrets', 'UserPromptSubmit');
286289
} finally {
287290
discoverSpy.mockRestore();
288291
healthSpy.mockRestore();
292+
addInstalledHookSpy.mockRestore();
289293
}
290294
});
291295
});

0 commit comments

Comments
 (0)