[BUG] Can't get headless claude to run in pipeline when connecting to Azure Foundry models
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
I've tried many variations from the linked issue, and while I can get Foundry to work in local context with environment variables, when running remote in pipeline I can't figure out why it isn't working.
Claude Code CLI v2.0.58/2.0.59 hangs indefinitely (60s timeout) when running in Azure DevOps hosted agents with Microsoft Foundry integration. The CLI produces zero output before hanging - not even debug messages.
What Should Happen?
I've tried running a single command with no extra prompt setup to just confirm it is working, and claude --debug --print --dangerously-skip-permissions --output-format text respond with a haiku from my output doesn't work.
The templated command that is generated from is:
# Connectivity check: validate Claude API access before main execution
echo "##[section]Testing Claude API connectivity"
CONNECTIVITY_CMD=("${CLAUDE_CMD}" --debug --print --dangerously-skip-permissions --output-format text "respond with a haiku")
echo "##[command]${CONNECTIVITY_CMD[*]}"
set +e
timeout 60 "${CONNECTIVITY_CMD[@]}" >/dev/null 2>&1
CONNECTIVITY_EXIT_CODE=$?
set -e
if [ ${CONNECTIVITY_EXIT_CODE} -ne 0 ]; then
if [ ${CONNECTIVITY_EXIT_CODE} -eq 124 ]; then
echo "##vso[task.logissue type=error]Claude API connectivity check timed out after 60 seconds"
else
echo "##vso[task.logissue type=error]Claude API connectivity check failed with exit code ${CONNECTIVITY_EXIT_CODE}. Unable to reach model."
fi
exit 1
fi
echo "##[info]Claude API connectivity verified successfully"
Error Messages/Logs
##[error]Claude API connectivity check timed out after 60 seconds
I can't get it to respond.
Based on the issue feedback earlier, I tried with debug flag, environment variable and more but it won't show me any output at all to know what's wrong.
I've added logging to confirm the variables are set:
Azure AI Foundry Configuration (Required)
##[info]┌──────────────────────────────────────────────────────────────┐
##[info]│ CLAUDE_CODE_USE_FOUNDRY = 1 │
##[info]│ ANTHROPIC_FOUNDRY_RESOURCE = sheld-[REDACTED]-eastus2
##[info]│ ANTHROPIC_FOUNDRY_API_KEY = [REDACTED] │
##[info]└──────────────────────────────────────────────────────────────┘
Model Configuration
##[info]┌──────────────────────────────────────────────────────────────┐
##[info]│ ANTHROPIC_DEFAULT_HAIKU_MODEL = claude-haiku-4-5
##[info]│ ANTHROPIC_DEFAULT_SONNET_MODEL = claude-sonnet-4-5
##[info]│ ANTHROPIC_DEFAULT_OPUS_MODEL = claude-opus-4-5
##[info]└──────────────────────────────────────────────────────────────┘
Debug Configuration
##[info]CLAUDE_LOG_LEVEL=debug
##[info]CLAUDE_DEBUG=true
##[info]CLAUDE_HOME will use default: $HOME/.claude
##[info]Skills directory found with 0 files
##[info]ANTHROPIC_MCP_CONFIG set to: /home/vsts/work/_temp/.cache/mcp-config.json
Steps to Reproduce
I've tried to configure my agent directory so it had skills and other settings.
I have a template repo that gets cloned containing all the special claude prompts and skills.
TARGET_CLAUDE_DIR="${HOME}/.claude"
rsync -av "${SOURCE_CLAUDE_DIR}/" "${TARGET_CLAUDE_DIR}/"
So before claude code is called, I have copied all the config settings over and confirmed with this output it shows:
rsync -av "/home/vsts/work/1/autopilot/.claude/" "/home/vsts/.claude/"
sending incremental file list
./
CLAUDE.md
settings.json
agents/
agents/azure-devops-manager.md
commands/
commands/devex-docs-review.md
commands/devex-pr-review.md
skills/
skills/azure-repos-threads/
skills/azure-repos-threads/SKILL.md
skills/azure-repos-threads/scripts/
skills/azure-repos-threads/scripts/Check-CodexAzdoEnvironment.ps1
skills/azure-repos-threads/scripts/Get-CodexAzdoMainProgressThread.ps1
skills/azure-repos-threads/scripts/New-CodexAzdoThreadComment.ps1
skills/azure-repos-threads/scripts/New-CodexAzdoThreadSuggestion.ps1
skills/azure-repos-threads/scripts/Update-CodexAzdoMainProgressThread.ps1
skills/git-diff-analyzer/
skills/git-diff-analyzer/SKILL.md
sent 94,454 bytes received 287 bytes 189,482.00 bytes/sec
total size is 93,179 speedup is 0.98
##[info]Successfully synced .claude configuration to /home/vsts/.claude
##[info]Contents of /home/vsts/.claude: /home/vsts/.claude
├── CLAUDE.md
├── agents
│ └── azure-devops-manager.md
├── commands
│ ├── devex-docs-review.md
│ └── devex-pr-review.md
├── settings.json
└── skills
├── azure-repos-threads
│ ├── SKILL.md
│ └── scripts
│ ├── Check-CodexAzdoEnvironment.ps1
│ ├── Get-CodexAzdoMainProgressThread.ps1
│ ├── New-CodexAzdoThreadComment.ps1
│ ├── New-CodexAzdoThreadSuggestion.ps1
│ └── Update-CodexAzdoMainProgressThread.ps1
└── git-diff-analyzer
└── SKILL.md
7 directories, 12 files
I've run commands to
# CLI responds immediately
$ claude --version
# Output: 2.0.59 (Claude Code)
# Network connectivity confirmed
$ curl -sS --max-time 10 -o /dev/null -w "HTTP %{http_code}\n" "https://<resource>.services.ai.azure.com"
# Output: HTTP 200
Environment Variables Set
CLAUDE_CODE_USE_FOUNDRY=1
ANTHROPIC_FOUNDRY_BASE_URL=https://<resource>.services.ai.azure.com
ANTHROPIC_FOUNDRY_API_KEY=<redacted>
ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5
ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-5
ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-5
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
DO_NOT_TRACK=1
Iterations Tested
Iteration 1: Basic invocation
- Command:
claude --debug --print --dangerously-skip-permissions --output-format text "respond with a haiku" - Result: Hangs 60s, no output
Iteration 2: Added pre-flight diagnostics
- Added
claude --versioncheck (works) - Added
curlconnectivity test (works - HTTP 200 in ~80ms) - Result: Still hangs on actual command
Iteration 3: Isolated CLAUDE_HOME
- Used
env CLAUDE_HOME=/tmp/.claude-test claude ... - Hypothesis: MCP config with invalid paths causing hang
- Result: Still hangs
Iteration 4: Removed CLAUDE_CODE_SKIP_FOUNDRY_AUTH
- Removed undocumented
CLAUDE_CODE_SKIP_FOUNDRY_AUTH=1variable - Result: Still hangs
Iteration 5: Isolated HOME (pending)
- Using
HOME=/tmp/.claude-test-homeinstead of CLAUDE_HOME - Simplified command without arrays/subshells
- Result: No difference, still hangs.
Key Observations
- Zero output: The CLI produces absolutely no output - no debug logs, no errors, nothing. It just hangs silently.
- Version works:
claude --versionresponds instantly, proving the CLI binary executes.
- Network works: Direct HTTPS to Foundry endpoint returns HTTP 200 in <100ms.
- Local works: The same configuration works locally on macOS.
- Memory stable: Agent memory stays around 1GB during hang - no memory leak.
- CPU idle: CPU usage drops to <1% during hang - CLI is waiting on something, not spinning.
Local Testing
export CLAUDE_CODE_USE_FOUNDRY=1
# NOPE: export ANTHROPIC_FOUNDRY_BASE_URL='https://<resource-name>.services.ai.azure.com' // API Error: 404 {"error":{"code":"404","message":"Resource not found"}}
export ANTHROPIC_FOUNDRY_BASE_URL='https://<resource-name>.services.ai.azure.com/anthropic'
export ANTHROPIC_FOUNDRY_API_KEY="$(az cognitiveservices account keys list --name '<resourcename>' --resource-group '<rg>' --subscription '<subscription>' --query key1 -o tsv)"
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-5
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-5
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
export DO_NOT_TRACK=1
claude --debug --print --dangerously-skip-permissions --output-format text "respond with a haiku"
So one note in running this in my local test is that /anthropic is not documented as required, but with base url it made an immediate difference.
When using ANTHROPIC_FOUNDRY_RESOURCE=<resource> locally in my terminal it also worked, but not with base url missing the /anthropic path.
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.59
Platform
Other
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Non-interactive/CI environment
Additional Information
Environment
- Claude Code Version: 2.0.58, 2.0.59 (latest)
- Platform: Azure DevOps Hosted Agents (Ubuntu,
ubuntu-latest) - Foundry Endpoint:
https://<resource>.services.ai.azure.com, and also have usedANTHROPIC_FOUNDRY_BASE_URLas well as basic resource<resource> - Authentication: API Key (
ANTHROPIC_FOUNDRY_API_KEY) - Node.js: v22.x
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗