I created this script to help others get benefit from the free tier offered by Github
I appreciate all the support I got for making this, but would now suggest people look at TheLolos' excellent fork at https://github.com/TheLoloS/Copilot-CLI-Unlocker which significantly expands the capabilities
A tool to add custom models to GitHub Copilot CLI's allowed models list.
- Bash shell (macOS, Linux, WSL)
- Perl (pre-installed on macOS/Linux)
- GitHub Copilot CLI installed
Platform Support:
- ✅ macOS
- ✅ Linux
- ✅ Windows (via WSL/Git Bash)
cd ~/copilot-patch
chmod +x patch-models.sh
./patch-models.sh --dry-run # Preview changes
./patch-models.sh # Apply patchAfter patching, update your config at ~/.copilot/config.json:
{
"model": "gpt-5-mini"
}The GitHub Copilot CLI has a hardcoded array of allowed models in its minified index.js file. If you configure a model in ~/.copilot/config.json that isn't in this list, the CLI silently falls back to another model.
Example: Setting "model": "gpt-5-mini" in your config won't work if "gpt-5-mini" isn't in the allowed list.
This patcher:
- Locates the models array variable in the minified code
- Adds your desired models to the array
- Creates timestamped backups before making changes
- Validates the patch was successful
./patch-models.sh # Add gpt-5-mini (default)
./patch-models.sh --dry-run # Preview without making changesThe script will automatically:
- Detect your Copilot installation location
- Add the specified models to the allowed list
- Create a timestamped backup
- Remind you to update
~/.copilot/config.json
./patch-models.sh --models gpt-5-mini,o1
./patch-models.sh --models claude-opus-4./patch-models.sh --file /path/to/custom/index.jsThe script automatically searches these locations (in order):
$HOME/node_modules/@github/copilot/index.js- Global npm modules (from
npm root -g) /usr/local/lib/node_modules/@github/copilot/index.js/opt/homebrew/lib/node_modules/@github/copilot/index.js(Homebrew on Apple Silicon)
You can override with --file if your installation is elsewhere.
You need to re-run this patcher:
- After updating the
@github/copilotnpm package - When the CLI is reinstalled
- If you encounter "model not available" errors
The Copilot CLI's index.js is a ~13.5 MB minified file. Inside, there's a variable (currently Yv) that contains the allowed models:
Yv=["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","gpt-5"]Note: The variable name changes between versions (Ef, Yv, etc.) but the patcher auto-detects it.
The patcher finds this array by searching for a recognizable pattern:
- Looks for variable assignments containing known model names (like "claude-sonnet")
- Extracts the variable name dynamically (works even if
Yvchanges toZv,Aa, etc.) - Parses the current models from the array
# Original
Yv=["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","gpt-5"]
# Patched
Yv=["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","gpt-5","gpt-5-mini"]The patcher:
- Creates a backup:
index.js.bak.YYYYMMDD-HHMMSS - Uses Perl with environment variables to safely handle special characters
- Performs the replacement in-place
- Verifies the new array exists in the file
- Restores backup if verification fails
- Reminds you to update
~/.copilot/config.json
If GitHub updates the Copilot CLI and this patcher stops working, here's how to adapt it:
# Search for known model patterns
grep -o 'gpt-5.*gpt-4.*claude' ~/node_modules/@github/copilot/index.js
# Or search for array-like structures
grep -o '\["gpt-[^]]*\]' ~/node_modules/@github/copilot/index.js
grep -o '\["claude-[^]]*\]' ~/node_modules/@github/copilot/index.jsOnce you find the array, look for what variable it's assigned to:
# Extract variable name and full assignment
grep -o '[A-Za-z_$][A-Za-z0-9_$]*=\["claude-sonnet-[^]]*\]' ~/node_modules/@github/copilot/index.jsExample output:
Yv=["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","gpt-5"]
The variable name is Yv (the part before =).
If the patcher can't auto-detect the array, you can update the script's search pattern:
Edit patch-models.sh around line 85:
# Old pattern (searches for claude-sonnet models)
ARRAY_PATTERN=$(grep -o '[A-Za-z_$][A-Za-z0-9_$]*=\["claude-sonnet-[^]]*\]' "$TARGET_FILE" | head -n 1 || true)
# If models change, update the search term:
# For GPT-focused arrays:
ARRAY_PATTERN=$(grep -o '[A-Za-z_$][A-Za-z0-9_$]*=\["gpt-[^]]*\]' "$TARGET_FILE" | head -n 1 || true)
# For any model array with known model name:
ARRAY_PATTERN=$(grep -o '[A-Za-z_$][A-Za-z0-9_$]*=\["known-model-name[^]]*\]' "$TARGET_FILE" | head -n 1 || true)Always test with --dry-run first:
./patch-models.sh --dry-runLook for:
- ✓ Variable name detected correctly
- ✓ Current models list makes sense
- ✓ New array includes your additions
$HOME/node_modules/@github/copilot/index.js # Local install
$(npm root -g)/@github/copilot/index.js # Global npm
/usr/local/lib/node_modules/@github/copilot/index.js # Standard global
/opt/homebrew/lib/node_modules/@github/copilot/index.js # Homebrew (Apple Silicon)
$HOME/.copilot/config.json
index.js.bak.YYYYMMDD-HHMMSS
Example: index.js.bak.20251109-101507
- Models Array Variable:
Yv(auto-detected, wasEfin earlier versions) - Default Models: claude-sonnet-4.5, claude-sonnet-4, claude-haiku-4.5, gpt-5
- File Size: ~13.5 MB (minified)
# sed has issues with special characters in minified code
sed 's/old/new/' file.js # ❌ Can break on [], (), etc.
# perl with environment variables and \Q...\E is safe
export SEARCH="old" REPLACE="new"
perl -pe 's/\Q$ENV{SEARCH}\E/$ENV{REPLACE}/' file.js # ✅ Safe for minified codeThe file structure changed. Follow "Adapting for Future Updates" above.
-
Check if the file is already patched:
grep "gpt-5-mini" ~/node_modules/@github/copilot/index.js
-
Try restoring from a backup:
ls -lt ~/node_modules/@github/copilot/index.js.bak.* cp ~/node_modules/@github/copilot/index.js.bak.YYYYMMDD-HHMMSS \ ~/node_modules/@github/copilot/index.js
-
Verify the patch was applied:
grep -o '[A-Za-z_$][A-Za-z0-9_$]*=\[.*gpt-5-mini.*\]' ~/node_modules/@github/copilot/index.js
-
Check your config file:
cat ~/.copilot/config.json | grep model
Should show:
"model": "gpt-5-mini"
-
Ensure exact spelling:
- ✅
gpt-5-mini - ❌
gpt5-mini(missing hyphen) - ❌
GPT-5-mini(wrong case)
- ✅
copilot-patch/
├── patch-models.sh # Main patcher script
├── README.md # This file
└── CHANGELOG.md # Version history (if tracking updates)
When updating this patcher for future Copilot versions:
- Document the changes in
CHANGELOG.md - Note the Copilot version number
- Update the "Key Variables" section above
- Test thoroughly with
--dry-run
$ cd ~/copilot-patch
$ ./patch-models.sh --dry-run
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Copilot Model Patcher
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Requirements:
• Bash shell (macOS, Linux, WSL)
• Perl (pre-installed on macOS/Linux)
• GitHub Copilot CLI installed
Platform Support:
✅ macOS ✅ Linux ✅ Windows (WSL/Git Bash)
✓ Target file: /Users/username/node_modules/@github/copilot/index.js
Step 1: Locating models array...
✓ Found variable: Yv
✓ Current array: ["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","gpt-5"]
Step 2: Parsing current models...
✓ Current models:
- claude-sonnet-4.5
- claude-sonnet-4
- claude-haiku-4.5
- gpt-5
Step 3: Building new models array...
+ Adding model: gpt-5-mini
✓ New array: ["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","gpt-5","gpt-5-mini"]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
DRY RUN MODE - No changes will be made
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Would replace:
FROM: Yv=["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","gpt-5"]
TO: Yv=["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","gpt-5","gpt-5-mini"]
To apply changes, run without --dry-run flag
$ ./patch-models.sh
[... applies patch ...]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Successfully patched!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📋 Backup saved to: index.js.bak.20251109-143022
Models now available:
- claude-sonnet-4.5
- claude-sonnet-4
- claude-haiku-4.5
- gpt-5
- gpt-5-mini (newly added)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ Next Step: Update Your Config
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Edit your Copilot config: ~/.copilot/config.json
Change the "model" field to use a free model, for example:
"model": "gpt-5-mini"
Available free models you just added:
- gpt-5-miniThis is a utility script for personal use. The GitHub Copilot CLI itself is proprietary software from GitHub.
For issues with:
- This patcher: Check the troubleshooting section above
- Copilot CLI itself: Contact GitHub Support
- Model availability: Check with your GitHub organization's settings