
gc-safe-coding
Rules for writing and reviewing GC-safe C++ code in the Hermes VM runtime. Use when writing, modifying, or reviewing C++ runtime VM code that uses internal Hermes VM APIs (as opposed to code using JSI). This includes working with GC-managed types (HermesValue, Handle, PinnedValue, JSObject, StringPrimitive, etc.), Locals, GCScope, PseudoHandle, CallResult, or any function with RJS suffix. Typically in lib/VM/, include/hermes/VM/, API/hermes/, or API/napi/.
- Installs
- 47
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/facebook/hermes --skill gc-safe-coding- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads gc-safe-coding automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
For the full explanation and rationale, see doc/GCSafeCoding.md.
GC safepoints
A GC safepoint is either a GC heap allocation or a function call that might
transitively reach one (regular C heap allocations like malloc are not
safepoints). Any function that takes Runtime & or PointerBase &
may trigger GC, unless documented otherwise or named with _noalloc/_nogc.
Functions with _RJS suffix invoke JavaScript recursively and always trigger
GC.
All raw pointers and PseudoHandles to GC objects must be rooted before any
GC safepoint. PseudoHandle<T> is not a root — it is just as dangerous as
a raw pointer across a safepoint. The same applies to bare SymbolID values
extracted from a non-uniqued source (e.g., the SymbolID pulled out of the
Handle<SymbolID> returned by getSymbolHandleFromPrimitive for a
freshly-allocated StringPrimitive): once nothing roots it, the lookup-table
slot is reclaimed by freeUnmarkedSymbols during sweep. Pin via
PinnedValue<SymbolID>.
Rooting local values: use Locals + PinnedValue (required for new code)
All new code must use Locals + PinnedValue<T>. Do not introduce new
GCScope instances or makeHandle() calls.
struct : public Locals {
PinnedValue<JSObject> obj;
PinnedValue<StringPrimitive> str;
PinnedValue<SymbolID> sym;
PinnedValue<> genericValue;
} lv;
LocalsRAII lraii(runtime, &lv);
Assignment patterns
- From PseudoHandle:
lv.obj = std::move(*callResult); - From HermesValue with known type:
lv.obj.castAndSetHermesValue<JSObject>(hv); - From raw pointer:
lv.obj = somePtr; - Clear:
lv.obj = nullptr; - In template context:
lv.obj.template castAndSetHermesValue<T>(hv);
Passing to functions
PinnedValue<T> implicitly converts to Handle<T>. Pass directly to functions
that accept Handle<T>.
Error handling with CallResult
Always check for exceptions before using the value:
auto result = someOperation_RJS(runtime, args);
if (LLVM_UNLIKELY(result == ExecutionStatus::EXCEPTION))
return ExecutionStatus::EXCEPTION;
lv.obj = std::move(*result);
When Handle usage is fine (do not flag)
Not every use of Handle<> needs to be converted to PinnedValue. The rule
"use Locals, not GCScope" applies to creating new rooted values — allocating
new PinnedHermesValue slots via makeHandle() or Handle<> constructors.
The following are not allocating new handles and do not need conversion:
vmcast<>(handle)— casts an existing handle to a different type. It does not takeRuntime &and does not allocate a GCScope slot. The result points to the samePinnedHermesValueas the input.args.getArgHandle(n)— returns a handle pointing into the register stack, which is already a root. No new allocation.- Passing or receiving a
Handle<>parameter — the handle was allocated by the caller; the callee is just using it.
Only flag handle usage when a new PinnedHermesValue slot is being
allocated (via makeHandle(), makeMutableHandle(), or Handle<>/
MutableHandle<> constructors that take Runtime &).
Checklist for writing / reviewing GC-safe code
- No raw pointers or PseudoHandles across GC safepoints. Every pointer to
a GC object — including values held in
PseudoHandle<T>— must be stored in aPinnedValuebefore any call that takesRuntime &or is_RJS. Watch for multi-step creation patterns: ifFoo::create()returns aPseudoHandleand the next line callsBar::create(runtime), the firstPseudoHandleis stale after the second allocation. Equally watch for capture-via-deref:auto *x = vmcast<T>(*pinned)extracts a raw pointer from a pinned location (e.g., aPinnedHermesValue *such as anapi_value). The pinned slot stays GC-safe, but the local raw pointer does not. Re-deref*pinnedat each use site, or pin viaPinnedValue<T>. - Use Locals, not GCScope. New code must not introduce
GCScopeormakeHandle(). Declare astruct : public LocalswithPinnedValuefields and aLocalsRAII. - Check every CallResult. Never dereference a
CallResultwithout first checking== ExecutionStatus::EXCEPTION. - Never return Handle from local roots. Do not return
Handle<T>pointing into aPinnedValueorGCScopethat is about to be destroyed. ReturnCallResult<PseudoHandle<T>>orCallResult<HermesValue>instead. - Null prototype checks. When traversing prototype chains, check for null
before calling
castAndSetHermesValue. - Loops are safe with Locals.
PinnedValuefields are reused each iteration — no unbounded growth. If aGCScopeis still needed for legacy APIs that returnHandle, useGCScopeMarkerRAIIorflushToMarker. - Handles allocate in the topmost GCScope.
makeHandle(),makeMutableHandle(),Handle<>andMutableHandle<>constructors, and calls to functions that takeRuntime &/PointerBase &and returnHandle<>, all allocate a slot in the topmostGCScope. Functions that create or receive handles without returning them need their ownGCScopeorGCScopeMarkerRAII(preferred for one or two handles). Functions likevmcast<>that do not takeRuntime &just cast existing handles without allocating. flushToMarkerinvalidates handles allocated after the marker. Any value extracted from such a Handle (raw pointer, bareSymbolID) is unrooted after the flush. Pin into aPinnedValuebefore the flush if the value is needed later.
Debugging tips
- If
IdentifierTable::materializeLazyIdentifierasserts(entry.isLazyASCII() || entry.isLazyUTF16()) && "identifier is not lazy", the entry is most often a free-list slot — look up the call stack for an unrootedSymbolIDheld across an allocation.
FAQ
What does the gc-safe-coding skill do?
Rules for writing and reviewing GC-safe C++ code in the Hermes VM runtime. Use when writing, modifying, or reviewing C++ runtime VM code that uses internal Hermes VM APIs (as opposed to code using JSI). This includes working with GC-managed types (HermesValue, Handle, PinnedValue, JSObject, StringPrimitive, etc.), Locals, GCScope, PseudoHandle, CallResult, or any function with RJS suffix. Typically in lib/VM/, include/hermes/VM/, API/hermes/, or API/napi/.
How do I install gc-safe-coding?
Run npx skills add https://github.com/facebook/hermes --skill gc-safe-coding in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/gc-safe-coding/ (personal) or .claude/skills/gc-safe-coding/ (project).
Which AI agents can use gc-safe-coding?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is gc-safe-coding safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains gc-safe-coding?
It is published by facebook in facebook/hermes, and it is an official skill from the maker of the technology it covers. It has 47 recorded installs.
More from facebook/hermes
non-interactive-git-rebase
facebook/hermes
Open the skill to read its SKILL.md instructions.
add-ir-instruction
facebook/hermes
Open the skill to read its SKILL.md instructions.
Popular backend & apis skills
find-skills
vercel-labs/skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
google-agents-cli-adk-code
google/agents-cli
This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).
embedded-captions
heygen-com/hyperframes
Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.
entra-agent-id
microsoft/azure-skills
Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).
neon
neondatabase/agent-skills
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.