# How should my skill detect that it is running in Cowork?

A naive environment-variable check false-negatives in exactly the configuration that matters most, because the part of your skill that runs shell commands runs somewhere with none of those markers set. Use an ordered recipe instead: check the environment marker, then the working-directory signature, then the CLI marker. For behaviour rather than reporting, branch on which tools exist — that is the most durable signal available to a skill.

### For behaviour rather than reporting, branch on which tools exist instead of on the environment.

*Measured*

The tool surface is the most durable runtime signal available to a skill: it is what actually determines what the skill can do, it is visible without a shell, and it stays correct when environment markers are added or removed. Use environment detection to report where you are; use capability detection to decide what to do.

### Do not hard-fail when a runtime marker is missing. Fall through to the next check.

*Measured* · *Depends on server-side configuration — can change without a version bump*

Markers are set by the host at spawn time and have been added and removed across releases. A detection routine that treats one missing variable as proof of a runtime will be wrong the next time the spawn contract changes. Order the checks so each one only adds coverage.

### Do not detect Cowork with a bare environment-variable check.

*Measured*

A skill spans two execution contexts. The part that runs shell commands runs in a sealed context with none of the usual markers set, so a bare environment check returns 'not Cowork' in precisely the production configuration you most needed to detect. The failure is silent and produces confidently wrong behaviour.

### Detect the runtime with an ordered sequence of checks, not a single environment test.

*Measured*

Check the Cowork environment marker first; if it is set you are in Cowork. Otherwise check whether the working directory matches the session-path signature, which catches the case where your skill's shell commands run somewhere the marker is absent. Otherwise check the CLI's own marker. Each step only adds coverage — a later one never contradicts an earlier one.

### Remember your skill spans two execution contexts, and test the one you are actually in.

*Measured*

Part of a skill runs where the agent runs; the shell commands it issues run somewhere else with a different environment and a different filesystem view. A check performed in one tells you little about the other, which is why a single probe gives confident wrong answers.

## What is not established

- Runtime markers are set by the host at spawn time and have been added and removed across releases. The ordering below degrades safely: a later check never contradicts an earlier one, it only adds coverage.

---

Consistent with the capture of 2026-08-05. Exact artifact versions and capture identity are on the current-state page. This documentation does not detect product changes.
