# CLAUDE_CODE_REMOTE env gate

> Claude Code sets CLAUDE_CODE_REMOTE in cloud sessions and leaves it unset locally, so one repo SessionStart hook can run installs only in the cloud VM.

URL: https://bartlomiejkrupa.dev/notes/claude-code-remote-env-gate/
Category: snippet | Updated: 2026-10-26
Summary: Claude Code sets CLAUDE_CODE_REMOTE in cloud sessions and leaves it unset locally, so one repo SessionStart hook can run installs only in the cloud VM.

`CLAUDE_CODE_REMOTE` is set when a Claude Code session runs in the cloud (`claude --cloud`) and unset on your machine. Check it inside a repo hook when a step should run only in the cloud VM.

## Use

Repository hooks live in `.claude/settings.json`, so they run the same way locally and in the cloud. Gate the cloud-only part:

```bash
#!/usr/bin/env bash
# SessionStart hook
if [ -n "$CLAUDE_CODE_REMOTE" ]; then
  npm install   # fresh VM: install deps; locally they already exist
fi
```

Running processes do not survive the cloud environment cache, so start services in this hook rather than in a setup script. More in [claude --cloud: the GitHub token never enters the VM](/articles/claude-code-cloud-sessions).

Sources:
- Claude Code in the cloud: a field guide to cloud sessions: https://claude.dev/blog/claude-code-in-the-cloud/
