If you're seeing this error even after setting your token, follow this guide step by step.
Error: GitHub token not found. Set GITHUB_TOKEN environment variable or use --token flag.
Run this command to check if your token is set:
echo $GITHUB_TOKENIf you see output (your token): The token is set, but ActionsGuard isn't reading it → Go to Solution 1
If you see nothing: The token isn't set → Go to Solution 2
If you just set the token in the current session, it should work. But if you're in a virtual environment, you might need to:
# Deactivate virtual environment
deactivate
# Reactivate it
source venv/bin/activate
# Set token again
export GITHUB_TOKEN="your_token_here"
# Verify
echo $GITHUB_TOKEN
# Try running ActionsGuard
actionsguard scan --repo owner/repoOption A: Current terminal session only
export GITHUB_TOKEN="your_token_here"Option B: Make it permanent (Recommended)
# For Zsh (default on macOS)
echo 'export GITHUB_TOKEN="your_token_here"' >> ~/.zshrc
source ~/.zshrc
# For Bash (Linux/older macOS)
echo 'export GITHUB_TOKEN="your_token_here"' >> ~/.bashrc
source ~/.bashrcVerify it worked:
echo $GITHUB_TOKEN
# Should show your tokenPowerShell:
# Current session
$env:GITHUB_TOKEN = "your_token_here"
# Permanent (requires admin)
[System.Environment]::SetEnvironmentVariable('GITHUB_TOKEN', 'your_token_here', 'User')Command Prompt:
set GITHUB_TOKEN=your_token_hereIf environment variables aren't working, use the --token flag directly:
actionsguard scan --repo owner/repo --token "your_token_here"❌ Wrong:
export GITHUB_TOKEN=ghp_xxxxxxxxxxxx # No quotes
export GITHUB_TOKEN='ghp_xxxxxxxxxxxx # Missing closing quote✅ Correct:
export GITHUB_TOKEN="ghp_xxxxxxxxxxxx" # Double quotes
export GITHUB_TOKEN='ghp_xxxxxxxxxxxx' # Single quotesIf you're using Zsh (default on modern macOS), but edited ~/.bashrc, it won't work!
Check your shell:
echo $SHELLUse the correct file:
- If output is
/bin/zsh→ Edit~/.zshrc - If output is
/bin/bash→ Edit~/.bashrc
Make sure there are no spaces around the = sign:
❌ Wrong:
export GITHUB_TOKEN = "ghp_xxxx" # Spaces around =✅ Correct:
export GITHUB_TOKEN="ghp_xxxx" # No spacesDon't use sudo with actionsguard - it runs in a different environment:
❌ Wrong:
sudo actionsguard scan --repo owner/repo # Won't see your GITHUB_TOKEN✅ Correct:
actionsguard scan --repo owner/repo # No sudo neededIf you set the token BEFORE activating your virtual environment, it won't be available:
Correct Order:
# 1. Activate venv first
source venv/bin/activate
# 2. THEN set token
export GITHUB_TOKEN="ghp_xxxx"
# 3. Run actionsguard
actionsguard scan --repo owner/repoRun these commands to diagnose the issue:
# 1. Check if token is set
echo $GITHUB_TOKEN
# 2. Check if it's a valid format
echo $GITHUB_TOKEN | wc -c # Should be 40+ characters
# 3. Check your current shell
echo $SHELL
# 4. Check if you're in a virtual environment
which python3
# 5. Test token with GitHub API
curl -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/user
# Should return your GitHub user info in JSON formatYour token might be set but lack the necessary permissions:
# Check token scopes (Classic token)
curl -I -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/user \
| grep -i x-oauth-scopes
# Test repository access
curl -H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/owner/repo
# Test organization access
curl -H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/orgs/your-org# In your project directory
echo 'GITHUB_TOKEN=your_token_here' > .env
# Load it before running
export $(cat .env | xargs)
actionsguard scan --repo owner/repoGITHUB_TOKEN="your_token_here" actionsguard scan --repo owner/repoYou might have an older version. Try:
cd actions-guard
git pull origin main
pip install -e . --force-reinstallOnce you think you've fixed it, run this test:
# Test 1: Token is set
echo "Token set: $([ -z "$GITHUB_TOKEN" ] && echo NO || echo YES)"
# Test 2: Token length (should be 40+)
echo "Token length: $(echo -n "$GITHUB_TOKEN" | wc -c)"
# Test 3: ActionsGuard can see it
actionsguard scan --repo kubernetes/kubernetes --format json
# If this works, you're all set! 🎉If none of these solutions work:
- Run the debug commands above
- Copy the output
- Create an issue: https://github.com/cybrking/actions-guard/issues
- Include:
- Your OS (macOS/Linux/Windows)
- Your shell (
echo $SHELL) - Output of
echo $GITHUB_TOKEN | wc -c - Any error messages
To avoid this issue in the future, add token to your shell config:
# For macOS (Zsh)
echo 'export GITHUB_TOKEN="your_token_here"' >> ~/.zshrc
# For Linux (Bash)
echo 'export GITHUB_TOKEN="your_token_here"' >> ~/.bashrc
# Reload
source ~/.zshrc # or source ~/.bashrc
# Test
echo $GITHUB_TOKEN~/.zshrc or ~/.bashrc has proper permissions:
chmod 600 ~/.zshrc # Only you can read/writeQuick Reference:
# Set token (current session)
export GITHUB_TOKEN="your_token_here"
# Verify
echo $GITHUB_TOKEN
# Use it
actionsguard scan --repo owner/repo
# Or use flag instead
actionsguard scan --repo owner/repo --token "your_token_here"