Skip to content

Commit 3235092

Browse files
committed
CM-65507 fire AI Guardrails SessionStart hook on all sources (resume/fork)
A forked Claude Code session reports its SessionStart source as 'resume', so the 'startup|clear' matcher skipped guardrails session-start for forked and resumed sessions. Omit the SessionStart matcher entirely (match-all) for both Claude Code and Codex so it fires on every source.
1 parent e465045 commit 3235092

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

cycode/cli/apps/ai_guardrails/ides/claude_code.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def render_hooks_config(self, async_mode: bool = False) -> dict:
239239
'hooks': {
240240
'SessionStart': [
241241
{
242-
'matcher': 'startup|clear',
243242
'hooks': [{'type': 'command', 'command': _SESSION_START_COMMAND}],
244243
}
245244
],

cycode/cli/apps/ai_guardrails/ides/codex.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ def render_hooks_config(self, async_mode: bool = False) -> dict:
201201
'hooks': {
202202
'SessionStart': [
203203
{
204-
'matcher': 'startup|clear',
205204
'hooks': [{'type': 'command', 'command': _SESSION_START_COMMAND}],
206205
}
207206
],

tests/cli/commands/ai_guardrails/ides/test_codex.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ def test_settings_path_honors_codex_home_env(fs: FakeFilesystem, monkeypatch: py
146146
# --- hooks config rendering --------------------------------------------------
147147

148148

149-
def test_render_hooks_session_start_matcher_includes_clear() -> None:
150-
"""SessionStart must fire on /clear too (conversation_id rotates)."""
149+
def test_render_hooks_session_start_matches_all_sources() -> None:
150+
"""SessionStart must fire on every source (a forked session reports 'resume',
151+
so no matcher is set -> match-all)."""
151152
rendered = Codex().render_hooks_config()
152-
assert rendered['hooks']['SessionStart'][0]['matcher'] == 'startup|clear'
153+
assert 'matcher' not in rendered['hooks']['SessionStart'][0]
153154
assert '--ide codex' in rendered['hooks']['SessionStart'][0]['hooks'][0]['command']
154155

155156

tests/cli/commands/ai_guardrails/test_hooks_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ def test_claude_code_render_hooks_async() -> None:
111111

112112

113113
def test_claude_code_render_hooks_session_start() -> None:
114-
"""Claude Code SessionStart fires on startup and /clear."""
114+
"""Claude Code SessionStart fires on every source (a forked session reports
115+
'resume', so the matcher is empty -> match-all)."""
115116
config = ClaudeCode().render_hooks_config()
116117
entries = config['hooks']['SessionStart']
117118
assert len(entries) == 1
118-
assert entries[0]['matcher'] == 'startup|clear'
119+
assert 'matcher' not in entries[0]
119120
assert CYCODE_SESSION_START_COMMAND in entries[0]['hooks'][0]['command']
120121
assert '--ide claude-code' in entries[0]['hooks'][0]['command']
121122

0 commit comments

Comments
 (0)