This is another detail the helpfile is not stating clearly.
Ah, if this should become a feature suggestion: a new switch for /window -c or /close should be added (it would break lots of scripts becoming default behaviour)...
Meanwhile/alternatively add all your on close routines to an alias:
alias -l close.routine {
unset %variable
close -@ $1
;(or window -c $1)
}
on *:CLOSE:@window: {
; alias triggered by close event
close.routine $target
}
alias testclose {
window @window
set %variable $active
; alias triggered by remote script
close.routine @window
}