Skip to content

Commit 0a62fb0

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 7b61441 commit 0a62fb0

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

src/commands/integrate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ function updateStateAfterConfiguration(hooksInstalled: boolean): void {
387387
// Track installed hooks
388388
if (hooksInstalled) {
389389
addInstalledHook(state, 'claude-code', 'sonar-secrets', 'PreToolUse');
390+
addInstalledHook(state, 'claude-code', 'sonar-secrets', 'UserPromptSubmit');
390391
}
391392

392393
saveState(state);

src/lib/state-manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
type AuthConnection,
3232
type CloudRegion,
3333
type AgentConfig,
34+
type HookType,
3435
} from './state.js';
3536
import { CLI_DIR, STATE_FILE } from './config-constants.js';
3637
import { version as VERSION } from '../../package.json';
@@ -176,7 +177,7 @@ export function addInstalledHook(
176177
state: CliState,
177178
agentName: string,
178179
hookName: string,
179-
hookType: 'PreToolUse' | 'PostToolUse' | 'SessionStart',
180+
hookType: HookType,
180181
): void {
181182
if (!Object.hasOwn(state.agents, agentName)) {
182183
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
@@ -285,6 +285,7 @@ describe('integrateCommand: full flow', () => {
285285
it('tracks hooks in state when skipHooks is false', async () => {
286286
const discoverSpy = spyOn(discovery, 'discoverProject').mockResolvedValue(FAKE_PROJECT_INFO);
287287
const healthSpy = spyOn(health, 'runHealthChecks').mockResolvedValue(CLEAN_HEALTH);
288+
const addInstalledHookSpy = spyOn(stateManager, 'addInstalledHook');
288289

289290
try {
290291
await integrateCommand('claude', {
@@ -295,9 +296,12 @@ describe('integrateCommand: full flow', () => {
295296
skipHooks: false,
296297
});
297298
expect(mockExit).toHaveBeenCalledWith(0);
299+
expect(addInstalledHookSpy).toHaveBeenCalledWith(expect.anything(), 'claude-code', 'sonar-secrets', 'PreToolUse');
300+
expect(addInstalledHookSpy).toHaveBeenCalledWith(expect.anything(), 'claude-code', 'sonar-secrets', 'UserPromptSubmit');
298301
} finally {
299302
discoverSpy.mockRestore();
300303
healthSpy.mockRestore();
304+
addInstalledHookSpy.mockRestore();
301305
}
302306
});
303307
});

0 commit comments

Comments
 (0)