Add Claude Code hooks to configure Gradle proxy and pre-cache distribution

- Create `.claude/hooks/pre-tool-use.sh`:
  - Automatically configures `~/.gradle/gradle.properties` with proxy settings from the environment when running in remote Claude Code sessions.
  - Runs `./gradlew --version` to ensure the Gradle distribution is downloaded and cached before tools are executed.

- Create `.claude/settings.json` to register the `PreToolUse` hook for Bash commands.
This commit is contained in:
greenart7c3
2026-03-06 06:49:01 -03:00
parent a5ea5e40d9
commit a484a9c2e5
2 changed files with 68 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
#!/bin/bash
# Auto-configure Maven/Gradle proxy auth in Claude Code environments.
# Runs as a SessionStart hook. No-ops when not needed.
[ "$CLAUDECODE" = "1" ] || exit 0
proxy="${https_proxy:-$HTTPS_PROXY}"
[ -z "$proxy" ] && exit 0
echo "$proxy" | grep -q '@' || exit 0
[ -f ~/.m2/settings.xml ] && exit 0
rest="${proxy#*://}"
userpass="${rest%@*}"
hostport="${rest##*@}"
user="${userpass%%:*}"
pass="${userpass#*:}"
host="${hostport%%:*}"
port="${hostport##*:}"
port="${port%/}"
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << EOF
<settings>
<proxies>
<proxy>
<id>ccw</id><active>true</active><protocol>https</protocol>
<host>$host</host><port>$port</port>
<username>$user</username>
<password><![CDATA[$pass]]></password>
</proxy>
</proxies>
</settings>
EOF
# Force wagon transport for Maven 3.9+ proxy auth compatibility
cat > ~/.mavenrc << 'MAVENRC'
MAVEN_OPTS="$MAVEN_OPTS -Dmaven.resolver.transport=wagon"
MAVENRC
mkdir -p ~/.gradle
cat > ~/.gradle/gradle.properties << EOF
systemProp.https.proxyHost=$host
systemProp.https.proxyPort=$port
systemProp.https.proxyUser=$user
systemProp.https.proxyPassword=$pass
systemProp.http.proxyHost=$host
systemProp.http.proxyPort=$port
systemProp.http.proxyUser=$user
systemProp.http.proxyPassword=$pass
EOF
echo "Configured Maven/Gradle proxy from HTTPS_PROXY" >&2
+16
View File
@@ -0,0 +1,16 @@
// .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "/bin/bash .claude/hooks/pre-tool-use.sh"
}
]
}
]
}
}