[BUG] settings.json `env` block not injected into hook subprocesses when running with --output-format stream-json (e.g. Cursor extension)
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?
When claude is invoked with --output-format stream-json --input-format stream-json (which is how the Cursor / VS Code extension launches it), environment variables defined under the env block in ~/.claude/settings.json are not injected into hook subprocesses spawned during the session. Same claude binary in interactive CLI mode injects them as expected.
This breaks tools that rely on the env block to configure hooks — e.g. observability tooling that ships pre-baked hooks and expects OTEL_SERVICE_NAME / similar settings to flow through.
What Should Happen?
Both runs should show OTEL_SERVICE_NAME=test-marker-12345 in the hook subprocess env, since the documented behavior of env is "Environment variables to set for Claude Code sessions" (per claude-code-settings.schema.json).
Error Messages/Logs
Steps to Reproduce
- Add to
~/.claude/settings.json:
``json``
{
"env": {
"OTEL_SERVICE_NAME": "test-marker-12345"
},
"hooks": {
"SessionStart": [
{
"hooks": [{
"type": "command",
"command": "{ echo \"=== entrypoint=${CLAUDE_CODE_ENTRYPOINT:-?} ===\"; env | grep -E '^OTEL_SERVICE_NAME=' || echo '(absent)'; } >> /tmp/hook-env-test.log 2>&1"
}]
}
]
}
}
- Run
claudein a terminal, then/exit. - Run
claude --output-format stream-json --input-format stream-json --verbose < /dev/null(this is roughly what the Cursor extension does), or just open the Cursor extension and start a new Claude Code session. - Check
/tmp/hook-env-test.log.
Claude Model
None
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.123
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Cursor
Additional Information
- macOS 15.x (Darwin 25.4.0)
- Claude Code 2.1.123 (CLI:
~/.local/bin/claude) - Claude Code 2.1.138 (Cursor extension:
~/.cursor/extensions/anthropic.claude-code-2.1.138-darwin-arm64/resources/native-binary/claude) - Cursor v1.x with the Anthropic Claude Code extension
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗