Quick answer: Hoppscotch gives you five variable scopes, and when two variables share a name, the narrowest scope wins. Resolution runs Request, then Collection, then Predefined, then Environment, then Global, so a request-level value overrides a global one and a red name means no scope produced a value.
The five scopes and the job each one does
Hoppscotch treats anything wrapped in double angle brackets, such as <<baseURL>>, as a variable, and where that name lives decides who reads it and who wins on a collision.
Global variables have the widest reach and are readable from every workspace, so they fit a value you want everywhere, such as a common header. Environment variables belong to one selected environment; keep production and staging environments with their own baseURL, and switching the active one swaps the whole set without touching your requests. Collection variables sit on a collection and its child folders, carrying base URLs, tokens, and defaults across related requests without leaking elsewhere. Request variables are the narrowest, scoped to one request and useful for a URL path value. Predefined variables are generated at runtime and reached with the $ symbol, as in $guid, $timestamp, or $randomUUID.
How precedence resolves a colliding name
The editor colors each variable name to show its scope, and the same name in two places is resolved by a fixed order.
| Scope | Color | Priority |
|---|---|---|
| Request | Orange | 1 |
| Collection | Purple | 2 |
| Predefined | Yellow | 3 |
| Environment | Green | 4 |
| Global | Blue | 5 |
| Not resolvable | Red | No value |
A lower number means higher precedence. If baseURL exists both globally and on the collection, the purple collection value reaches the request, while the blue global stays a fallback outside that collection. The pattern is narrow-beats-wide: set a broad default once, then override it close to the point of use instead of copying values around.
A red name is not another scope. It means no scope produced a value, usually from a misspelling, a removed variable, or an environment that is not active. Treat red as a stop signal rather than a silent empty string, because that is how a request goes out with a broken URL.
Regular versus secret: a boundary that survives export
Every variable is either regular or secret. A regular variable is visible to anyone who can read the workspace and, in a shared workspace, syncs to the server so members get it. A secret variable never syncs and is never shared; its value is masked with asterisks and you fill it at runtime.
Two limits matter. Secrets cannot be scoped to a request, only to an environment or global scope, so a private token does not belong in a request variable. When you export an environment, secret values are left out, so a teammate importing it still supplies the secret locally; that is the safety mechanism, not an omission.
Where a script actually writes
The scripting surface keeps the legacy pw object and the experimental hopp object rather than forcing a migration. The confusing detail is the target of a write: pw.env.set("accessToken", value) writes the currently selected environment, not global, and switching environments changes where later reads land.
const jsonData = pw.response.body;
pw.env.set("accessToken", jsonData.access_token);
To target global, use the experimental hopp.env.global.set("baseURL", "https://api.example.com"), while hopp.env.active.set writes the active environment. On the read side, get returns the resolved value and follows nested references, whereas getRaw returns the stored string without resolving, so pick getRaw to inspect what is actually stored when a variable holds another <<name>>.
For the wider category, the Hoppscotch comparison hub covers the rest of the tool's request model.
Frequently asked questions
Which scope should I pick by default? Start with the environment for values that change between production and staging, and the collection for defaults shared by one related set of requests. Reach for global only when a value truly applies everywhere, since a global name is easy to override by accident.
Why does my variable show up red? No scope resolved the name. Check the spelling against where it is defined, confirm the right environment is active, and remember a secret still has to be populated at runtime even though the variable exists.
Can a secret live on a single request? No. Secrets are limited to environment and global scope, and their values are excluded from exports, so keep request scope for non-sensitive, request-specific values.
The bottom line
Scope is a load-bearing choice, not a filing preference. Put a value at the widest level that is true everywhere and override it narrowly, read the color before you trust a token, and keep secrets in environment or global scope knowing they will not ride out in an export. A desktop tool such as Powerduck follows the same model with globals, collection, environment, and local variables kept on the device, so the habit of choosing the narrowest scope that works transfers across tools. When a name collides, assume the closest definition wins and verify it.
Top comments (0)