@@ -149,44 +149,13 @@ function handlePreToolUse(sessionOrigin: string, event: HookInput): void {
149149 const rules = loadRulesForBash ( ) ;
150150 verdict = checkBash ( rules , command ) ;
151151 if ( ! verdict . allowed ) break ;
152- // Track effective cwd through cd/pushd segments, then check each git
153- // segment with the correct cwd. If cwd cannot be determined (variables,
154- // subshells), block with instruction to use git -C.
155- // If chain contains git checkout (branch switch), skip merged-PR check
156- // because the hook runs BEFORE execution - current branch will change.
152+ // Split chained commands and check each git segment independently.
153+ // No cwd tracking needed - #!axme gate carries repo/PR explicitly.
157154 const segments = splitCommandSegments ( command ) ;
158- const hasCheckout = segments . some ( s => / ^ \s * g i t \s + ( c h e c k o u t | s w i t c h ) \b / . test ( s . trim ( ) ) ) ;
159- let effectiveCwd = process . cwd ( ) ;
160- let cwdResolved = true ;
161155 for ( const seg of segments ) {
162156 const trimmed = seg . trim ( ) ;
163- // Track cd/pushd
164- const cdMatch = trimmed . match ( / ^ (?: c d | p u s h d ) \s + [ " ' ] ? ( [ ^ \s " ' ] + ) [ " ' ] ? $ / ) ;
165- if ( cdMatch ) {
166- const target = cdMatch [ 1 ] ;
167- if ( target . includes ( "$" ) || target . includes ( "`" ) ) {
168- cwdResolved = false ;
169- } else {
170- const { resolve : pathResolve } = require ( "node:path" ) ;
171- const expanded = target . startsWith ( "~" ) ? target . replace ( "~" , process . env . HOME || "" ) : target ;
172- effectiveCwd = pathResolve ( effectiveCwd , expanded ) ;
173- }
174- continue ;
175- }
176- // Check git segments
177157 if ( / ^ \s * g i t \b / . test ( trimmed ) ) {
178- // Parse git -C override
179- const cFlagMatch = trimmed . match ( / g i t \s + - C \s + [ " ' ] ? ( [ ^ \s " ' ] + ) [ " ' ] ? / ) ;
180- let gitCwd = effectiveCwd ;
181- if ( cFlagMatch ) {
182- const { resolve : pathResolve } = require ( "node:path" ) ;
183- gitCwd = pathResolve ( effectiveCwd , cFlagMatch [ 1 ] ) ;
184- } else if ( ! cwdResolved ) {
185- verdict = { allowed : false , reason : `Cannot determine target directory for git command. Use explicit path: git -C /absolute/path ${ trimmed . replace ( / ^ g i t \s + / , '' ) } ` } ;
186- break ;
187- }
188- // Skip merged-PR check if chain includes checkout (branch will change)
189- verdict = checkGit ( rules , trimmed , gitCwd , hasCheckout ) ;
158+ verdict = checkGit ( rules , trimmed ) ;
190159 if ( ! verdict . allowed ) break ;
191160 }
192161 }
0 commit comments