Use pre-commit git hooks that enforce your coding standards.
So, even if the first stab at getting a solution produces a less than desirable result, the hook will act as a gate-keeper and will get the agent to do a second pass over your code to enforce it. Works much better than repeatedly reminding via prompts.
When it attempts to commit, it will get this failure -
This will force it to re-think -
Here is the hook that triggered this -
echo ""
echo "đź§ Checking for Cyclomatic Complexity (Excessive Nesting)..."
if [ -n "$staged_cljs" ]; then
complexity_errors=0
for file in $staged_cljs; do
# Use awk to find lines with 6+ closing brackets AND report the current function
awk_output=$(awk '
# Track current function
/^\(defn? / { current_func = $2 }
# Check for excessive nesting (6+ closing brackets)
/[])}]{6,}/ {
print " File: " FILENAME
print " Line: " FNR
if (current_func != "") {
print " Func: " current_func
} else {
print " Func: (unknown/top-level)"
}
print " Code: " $0
print "---"
found_error = 1
}
END { if (found_error) exit 1 }
' "$file")
if [ $? -ne 0 ]; then
echo "❌ Excessive nesting detected in $file (> 5 closing brackets)"
echo "$awk_output"
complexity_errors=1
fi
done
if [ $complexity_errors -eq 1 ]; then
echo "â›” Commit aborted: recursive complexity too high. Please refactor function."
exit 1
fi
echo "âś… Complexity within limits."
fiThe best part is that the LLMs themselves will write the correct hooks for you.
Happy prompting!