Last active
April 17, 2026 18:56
-
-
Save GoXLd/cdbaa5598df152d1ef63feec4c50a717 to your computer and use it in GitHub Desktop.
Patch Script: OpenAI ChatGPT VS Code extension (macOS Apple Silicon)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # ----------------------------------------------------------------------------- | |
| # Patch Script: OpenAI ChatGPT VS Code extension (macOS Apple Silicon) | |
| # Author: GoXLd (https://github.com/GoXLd) | |
| # Please retain attribution when reusing this code. | |
| # License/Disclaimer: Provided "as is", without any warranties or guarantees | |
| # of any kind (express or implied). Use at your own risk. | |
| # ----------------------------------------------------------------------------- | |
| if [[ "$(uname -s)" != "Darwin" ]]; then | |
| echo "This patch script is for macOS only." | |
| exit 1 | |
| fi | |
| if [[ "$(uname -m)" != "arm64" ]]; then | |
| echo "This patch script is for Apple Silicon (arm64) only." | |
| exit 1 | |
| fi | |
| if pgrep -f '/Applications/Visual Studio Code.*Electron|/Applications/Visual Studio Code - Insiders.*Electron|[[:space:]]code([[:space:]]|$)|[[:space:]]code-insiders([[:space:]]|$)' >/dev/null 2>&1; then | |
| echo "VS Code appears to be running." | |
| echo "Please close VS Code and VS Code Insiders before patching." | |
| exit 1 | |
| fi | |
| roots=( | |
| "$HOME/.vscode/extensions" | |
| "$HOME/.vscode-insiders/extensions" | |
| ) | |
| targets=() | |
| for root in "${roots[@]}"; do | |
| [[ -d "$root" ]] || continue | |
| while IFS= read -r -d '' file; do | |
| targets+=("$file") | |
| done < <(find "$root" -type f -path '*/openai.chatgpt-*-darwin-arm64/out/extension.js' -print0 2>/dev/null) | |
| done | |
| if [[ ${#targets[@]} -eq 0 ]]; then | |
| echo "No extension.js found for openai.chatgpt-*-darwin-arm64." | |
| echo "Checked:" | |
| printf ' - %s\n' "${roots[@]}" | |
| exit 1 | |
| fi | |
| timestamp="$(date +%Y%m%d-%H%M%S)" | |
| patched_count=0 | |
| already_patched_count=0 | |
| failed_count=0 | |
| for file in "${targets[@]}"; do | |
| backup="${file}.bak.${timestamp}" | |
| cp "$file" "$backup" | |
| if ! perl -0777 -i -pe ' | |
| s/"local-environment"\s*:\s*async\([^)]*\)\s*=>\s*.*?(?=,\s*"local-environments"\s*:)/"local-environment":async()=>({environment:{type:"error",error:{message:"Local environments are not available in the extension."}}})/sg; | |
| s/"local-environments"\s*:\s*async\([^)]*\)\s*=>\s*.*?(?=,\s*"local-environment-config"\s*:)/"local-environments":async()=>({environments:[]})/sg; | |
| s/"local-environment-config"\s*:\s*async\([^)]*\)\s*=>\s*.*?(?=,\s*"local-environment-config-save"\s*:)/"local-environment-config":async({configPath:e})=>({configPath:e,exists:!1,raw:null})/sg; | |
| s/"local-environment-config-save"\s*:\s*async\([^)]*\)\s*=>\s*.*?(?=,\s*"ide-context"\s*:)/"local-environment-config-save":async({configPath:e})=>({configPath:e,success:!1})/sg; | |
| s/"open-in-targets"\s*:\s*async\([^)]*\)\s*=>\s*.*?(?=,\s*"set-preferred-app"\s*:)/"open-in-targets":async()=>({preferredTarget:null,availableTargets:[],targets:[]})/sg; | |
| s/"set-preferred-app"\s*:\s*async\([^)]*\)\s*=>\s*.*?(?=,\s*"terminal-shell-options"\s*:)/"set-preferred-app":async()=>({success:!1})/sg; | |
| ' "$file"; then | |
| cp "$backup" "$file" | |
| echo "FAILED: $file (patching error, restored from backup)" | |
| failed_count=$((failed_count + 1)) | |
| continue | |
| fi | |
| expected=( | |
| '"local-environment":async()=>({environment:{type:"error",error:{message:"Local environments are not available in the extension."}}})' | |
| '"local-environments":async()=>({environments:[]})' | |
| '"local-environment-config":async({configPath:e})=>({configPath:e,exists:!1,raw:null})' | |
| '"local-environment-config-save":async({configPath:e})=>({configPath:e,success:!1})' | |
| '"open-in-targets":async()=>({preferredTarget:null,availableTargets:[],targets:[]})' | |
| '"set-preferred-app":async()=>({success:!1})' | |
| ) | |
| verify_ok=1 | |
| for pattern in "${expected[@]}"; do | |
| if ! grep -Fq "$pattern" "$file"; then | |
| verify_ok=0 | |
| break | |
| fi | |
| done | |
| if [[ $verify_ok -ne 1 ]]; then | |
| cp "$backup" "$file" | |
| echo "FAILED: $file (restored from backup)" | |
| failed_count=$((failed_count + 1)) | |
| continue | |
| fi | |
| if cmp -s "$backup" "$file"; then | |
| rm -f "$backup" | |
| echo "UNCHANGED (already patched): $file" | |
| already_patched_count=$((already_patched_count + 1)) | |
| else | |
| echo "PATCHED: $file" | |
| echo "BACKUP: $backup" | |
| patched_count=$((patched_count + 1)) | |
| fi | |
| done | |
| echo | |
| echo "Done." | |
| echo "Patched: $patched_count" | |
| echo "Already patched: $already_patched_count" | |
| echo "Failed: $failed_count" | |
| echo | |
| echo "Note: VS Code extension updates may overwrite this patch." | |
| echo "Disclaimer: This script is provided as-is, with no warranties or guarantees." |
Author
I am executing this on my M2 Air since codex has been causing overheating.
Will let you know how it goes
Thanks for trying it on your M2 Air. Yeah, it’s a bit odd that the issue hasn’t been fixed, but people have reported that this patch helps in practice. Looking forward to hearing how it works for you.
this isn't only affecting macbooks, I get massive CPU usage on every platform, even linux, it's just most visible with macbooks air because they overheat because of this, other platforms usually have weaker CPUs with better cooling so it's not so visible, still annoying though
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am executing this on my M2 Air since codex has been causing overheating.
Will let you know how it goes