/greycat-c:greycat-cfrom greycat-c
Reference for GreyCat C API, GCL Standard Library modules (core, runtime, io, util), and plugin development patterns including lifecycle hooks, type configuration, and native function linking.
Ships in greycat-c. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Comprehensive reference for GreyCat native development (C API), the GCL Standard Library, and plugin development patterns. Tracks SDK 9.0 (headers re-verified 2026-11-27 against upstream 9bafd68ea).
Breaking — rebuild every plugin, stores of 8.4 are refused:
gc_type_t renumbered (GC_ABI_PROTO 3 → 4): new gc_type_node_time_set (7), gc_type_node_set (8), gc_type_node_index_set (10) and gc_type_node_geo_set (13); every tag from gc_type_node_index on moved up (now 28 tags, GC_TYPE_LAST = gc_type_error = 27; nodeTimeSet / nodeGeoSet landed after 24f7110f4 with GC_ABI_PROTO still 4). New gc_type__is_node(t) (node .. node_geo_set) / gc_type__is_keyed_node(t) / gc_type__is_pair_counted(t) (nodeTimeSet, nodeGeoSet). Opcodes renumbered: one push_node_empty (44) replaced the four push_node_{time,list,index,geo}.gc_tensor_type_t (gc/tensor.h), gc_duration_unit_t (new gc/duration.h, replaces the removed gc_core_DurationUnit_* macros), dtz zone indexes (GC_DTZ_UTC, gc_dtz_zone_names; a tz is no longer the TimeZone ordinal — also in gc_buffer_options_t.tz and gc_program_type_field_format_t). Convert via prog->enums.{tensor_type,duration_unit,time_zone,float_precision} (gc_program_enum_map_t, gc_program_enum_map__to_fixed / __to_entry) and gc_program__resolve_enum_entry. nativegen.h now declares extern u32_t gc_<mod>_<Enum>_<entry> resolved by name at link (variables: no case labels).gc_error_code_t (C-only, gc/machine.h): none 0, interrupted 1, await 2, timeout 3, forbidden 4, runtime_error 5 — GCL ErrorCode removed.gc_program_library__set_install_hook + gc_program_library_t.install (greycat install only downloads); gc_program_map_t / gc_program_bucket_t / gc_program_map__* (name indexes are gc_u32_map_t, symbols a gc_str_map_t); gc_program_function_t.is_raw (@raw gone); gc_license_level_t / gc_license__level; gc_buffer__read_all_from_fd.greycat.h): c64_t / c128_t + gc_c64__* / gc_c128__* → gc/complex.h; gc_common__parse_number / _parse_sign_number → gc/int.h; gc_duration__parse → gc/duration.h.gc_core_tensor__clone_internal returns bool (allocation failure); const on read-only tensor params (diff, check_shape, get_data, all descriptor checks/sizes); gc_program_function_t flags are 1-bit fields (+ takes_http_request, returns_http_response); gc_abi_function_t.is_static. Tensor errors now name shapes/types (GC_ERROR_TENSOR_* are only for your own messages); getters no longer read out-of-bounds.New C API: gc_u32_map_t / gc_u64_map_t (gc/u32_map.h, gc/u64_map.h) and gc_str_map_t (gc/str_map.h) hash maps; gc_char__parse (gc/char.h); gc_slot__to_f64; gc_host__run_function(host); gc_core_tensor__add_type_name / _add_shape; prog->core gained ids for every primitive/node type (int_, nodeSet, nodeIndexSet, nodeTimeSet, nodeGeoSet, DurationUnit, TimeZone, …); gc_program__encode_symbol, __runtime_type, __resolve_ptype, __compute_layout, .gcp gc_program__save / __load / __check / __rebuild_indexes; env options __label, __repair, __task_retention, __tls, __acme, __acme_email, __acme_directory, __paste (appended; HTTPS via OpenSSL 3.5).
Since 642356556 (incremental, rebuild plugins): env option gc_env_options__compiler was inserted after __task_retention (__tls .. __paste moved up by one — index by enumerator name, never raw values) and __native, __native_load, __keep_store, __drop_credentials appended; gc_program_function_t.has_native_body bit; opcodes 83-130 (GC_PROGRAM_OPCODE_LAST = node_fits), .gcp GC_PROGRAM_FORMAT_VERSION 4 (reads ≥ _MIN 2), GC_PROGRAM_PUSH_ARR_GUESSED, gc_program__pair_ops, gc_program_function__trusted_return, new program-check enum values (gc_program_check_operand_empty_node_type 20 → 21); gc_node__type_fits / _strict; new inline-only headers gc/equals_inline.h (gc__equals_is_composite / gc__equals_scalar) and gc/object_inline.h (gc_object__segments_inline / gc_object__get_offset_inline), not in greycat.h; gc_ssl_ca__pem_bundle documented as lazily resolved and thread-safe.
Stdlib (breaking): Task::header/headers/uri/body + @raw removed → an @exposed fn takes runtime::HttpRequest (only param) / returns runtime::HttpResponse; nodeList is positional (set removed, remove shifts); grants are per permission (IdentityGrantType + Identity.grants removed; grant/revoke(name, target, permission): bool, grant_permission, has_grant; new permissions files:read/files:write/tasks:read/tasks:cancel); License / LicenseType / RuntimeInfo.license / ErrorCode removed; Tensor.scale(value, inPlace: bool); System::exec returns stdout+stderr. New: nodeSet<V>, nodeIndexSet<K, V>, nodeTimeSet<T> / nodeGeoSet<T> (a set of values per time / per point), Identity::sign_in(id, ttl), Task::result(id), Task.worker_id / .jobs, Identity::tokens / revoke_token(s) / IdentityToken, Runtime::program(), Tensor.mean/min/max, GeoBox.crosses_antimeridian/lobes; task folders under gcdata/tasks/<id>/ (File::workingDir(), kept --task_retention). Details: standard_library.md.
gc_allocator_t *: per-call scratch from gc_machine__allocator(ctx) (= ((gc_ctx_t *)ctx)->allocator), plugin-global state from gc_host__global_allocator(). gc_alloc__create(bool shared) (true = multi-thread arena); gc_alloc__free(a, ptr, size) requires the original size; gc_alloc__reset(allocator) wipes a whole arena. See api_memory_text.md.gc_type_static_field with the entry position in .tu32.right; compare against nativegen's link-resolved gc_<mod>_<Enum>_<entry>, and convert TensorType / DurationUnit / TimeZone through prog->enums (api_core.md, Enum Entries).gc_machine__program(ctx)->core.Array / .Tensor / .nodeTime … (no gc_core_* globals for out-of-tree plugins).gc/log.h). gc_log_level_t is none / error / warn / info / trace (trace = 4). Use gc_log__machine(f) / gc_log__host(f); gate hot paths with gc_log__enabled(host, level).gc_string_t (heap, immutable, hash-cached; NUL-terminated at buffer[size], but size is authoritative since content may embed NUL). No inline short strings (gc_str_t is not public).gc_machine__call_function takes a const gc_program_function_t *fn. On false the result is a synthesized Error object (gc_type_object); the caller owns one mark. gc_machine__impersonate(ctx, user_id) switches the effective user.gc/host.h). gc_host__cancel_task(self, task_id, requester_id, requester_permissions, out_task) is thread-safe and permission-checked; gc_host__spawn_task takes a u64_t user_permissions mask; gc_host__options(self) exposes resolved CLI/env config (gc/env.h); gc_host__run_function(self) tells a start hook which function greycat run will call. Periodic scheduling via gc_scheduler_t / gc_periodic_task_t / gc_periodicity_t. See api_runtime_storage.md.gc_node__resolve / gc_machine_native__node_get / node_set_at work across node kinds via a u64_t node_ref; nodeList positions are not raw keys since 9.0 (append only via node_set_at(..., add_semantic = true, ...)). Check a node's declared specialization with gc_node__type_fits_strict (generic-built nodes fit only any arguments) before trusting its element type.greycat build --native compiles GCL functions to project.gcn; at load (--native_load, default on) those functions get has_native_body and run native code — don't assume a non-is_native function is interpreted bytecode.gc_tensor_t / gc_tensor_descriptor_t (descriptor.type is a gc_tensor_type_t); data survives a reshape to zero elements — test descriptor.size. A tensor over caller-owned data (gc_machine__init_tensor + proxy) must not be re-shaped. See api_collections.md.gc/stream.h, not in greycat.h). Appends only fill a buffer (flushed by size / step / reader / clean shutdown); call gc_stream__flush before persisting a drain offset.gc_map__set stores object keys uncopied; keys hash with gc_slot__hash and compare with gc__deep_equals (int and float of equal value are one key).gc_machine_t - Execution context passed to all native functions. Use to get parameters, set results, report errors, create objects, and access scratch buffers.
gc_slot_t - Universal value container (tagged union) holding any GreyCat value: integers, floats, bools, objects, enums, tuples, etc.
gc_type_t - Type system enum (8-bit, 28 values, renumbered in 9.0) defining all GreyCat types: null, bool, char, int, float, node variants (node, nodeTime, nodeTimeSet, nodeSet, nodeIndex, nodeIndexSet, nodeList, nodeGeo, nodeGeoSet), geo, time, duration, cubic, static_field, object, block_ref, block_inline, function, undefined, type, field, stringlit, error.
gc_object_t - Generic handle for heap-allocated objects. Packed to 128 bits. Every collection type (Array, Map, Table, Tensor, String, Buffer) starts with this as its first member.
The few patterns below are the trigger-level essentials. Full runnable examples for every operation (objects, tensors, arrays, maps, strings, buffers, allocators, logging, introspection) live in the five C-API reference files listed under Detailed Reference.
Parameters & results:
gc_slot_t p = gc_machine__get_param(ctx, 0); gc_type_t t = gc_machine__get_param_type(ctx, 0);
u32_t n = gc_machine__get_param_nb(ctx); gc_slot_t self = gc_machine__this(ctx); // instance methods
gc_machine__set_result(ctx, (gc_slot_t){.i64 = 42}, gc_type_int);
gc_machine__set_result(ctx, (gc_slot_t){.object = obj}, gc_type_object);
gc_object__un_mark(obj, ctx); // CRITICAL: every object result must be un-marked or it leaks / GC-faults
Enum parameters & results (CRITICAL — #1 native bug). GCL enum values are NOT gc_type_int; they are gc_type_static_field with the entry position in .tu32.right (.tu32.left is the enum type offset), never .i64. Since 9.0 compare/return positions through nativegen's link-resolved gc_<mod>_<Enum>_<entry> variables rather than literals:
// WRONG — always hits the default fallback: (type == gc_type_int) ? slot.i64 : 0
// CORRECT:
i64_t variant = (gc_machine__get_param_type(ctx, 0) == gc_type_static_field) ? (i64_t) slot.tu32.right : 0;
// Returning MyEnum::variant2:
gc_machine__set_result(ctx, (gc_slot_t){.tu32 = {.left = 0, .right = gc_mymod_MyEnum_variant2}}, gc_type_static_field);
Errors: gc_machine__set_runtime_error(ctx, "msg") / gc_machine__set_runtime_error_syserr(ctx) (uses errno); check propagated errors with if (gc_machine__error(ctx)) return;.
The C API reference is split by domain — each file below is linked directly (one level deep) and loads on demand.
references/api_core.md — value model, execution context, type system, logging. Start here.
gc_machine_t (params, result, errors, gc_machine__allocator, gc_machine__impersonate, gc_machine__call_function via gc_program_function_t *, object creation)gc_type_t / gc_slot_t value model, complex c64/c128 arithmetic (gc/complex.h), gc_node__parse, gc_error_code_tgc_program__link_mod_fn / gc_program__link_type_fn), type configuration, introspection, enum entry resolution + fixed-value enum maps, .gcp load/save/check, iterator params, gc_duration_unit_tgc/log.h) and the cross-cutting Conventions & Patterns indexreferences/api_memory_text.md — memory, buffers, strings, objects
gc_alloc__create(bool shared), sizing/statsgc_string_t, allocator-aware constructors)gc/object_inline.h)references/api_collections.md — array, map, table, tensor, C hash maps
gc_tensor_type_t, init_Nd, get/set/add for i32/i64/f32/f64/c64/c128, descriptor utilities, raw data access, matmul/bias/sumgc_u32_map_t / gc_u64_map_t / gc_str_map_t (new in 9.0)references/api_runtime_storage.md — runtime, persistence, graph nodes
gc_scheduler_t, gc_periodic_task_t), plugin-global allocator (gc_host__allocator / gc_host__global_allocator)is_static, truncated-header error, signed @precision), file I/O (open/sync), streams (gc/stream.h: buffered, gc_stream__flush, ndjson/csv), resolved env options (incl. metrics / flush / TLS / task retention)gc_node__resolve, gc_node__parse, gc_node__type_fits / _strict) and direct node-entry read/write (gc_machine_native__node_get / node_set_at via gc_node_single_value_t, released with gc_node_single_value__clear); node_get takes an expected_type_id (prog->core.nodeTime / .nodeGeo / .nodeIndex) and refuses other block typesreferences/api_services.md — crypto, geo, time, math, util
GC_DTZ_UTC, gc_dtz_time__print / parse)gc/equals_inline.h, sorting with allocator)runtime::HttpRequest / HttpResponse), Worlds, OpenAPI, MCPxml / s3 libraries)File: references/standard_library.md
Load when working with:
runtime::HttpRequest / HttpResponse)Contains: Complete documentation for all four standard library modules with code examples, usage patterns, and best practices.
Build native GreyCat plugins in C with proper lifecycle management, type configuration, and thread safety.
Function naming (CRITICAL — must match nativegen): gc_<module>_<Type>__<methodName>(gc_machine_t *ctx)
When GreyCat compiles GCL code with native declarations, it auto-generates nativegen.c / nativegen.h. Those extern declarations define the exact C symbol names the runtime resolves at dlopen — your C definitions MUST match or you get undefined symbol errors. Convention:
gc_<gcl_module>_<GclType>__<methodName> (double underscore before the method)gc_<gcl_module>__<functionName> (double underscore before the function)<gcl_module> is the GCL file's module path; <GclType> matches the GCL type (PascalCase); <methodName> matches the GCL method (camelCase)// GCL (module "text_normalizer", type TextNormalizer):
// native static fn rejoinHyphenatedWords(text: String): String;
// nativegen.h generates:
// extern void gc_text_normalizer_TextNormalizer__rejoinHyphenatedWords(gc_machine_t *ctx);
// Your C implementation MUST be named exactly:
void gc_text_normalizer_TextNormalizer__rejoinHyphenatedWords(gc_machine_t *ctx) { ... }
Plugin lifecycle: link -> lib_start -> [worker_start -> native calls -> worker_stop] -> lib_stop
Type configuration: gc_program_type__configure(prog, type_id, sizeof(my_struct_t), finalizer)
Library hooks:
gc_program_library__set_lib_hooks(lib, lib_start, lib_stop);
gc_program_library__set_worker_hooks(lib, worker_start, worker_stop);
gc_program_library__set_codegen_hook(lib, lib_codegen); // optional: `greycat codegen <lang>`
File: references/plugin_development.md
Load when:
Contains: Complete project structure, CMake configuration, GCL type definitions, nativegen implementation, lifecycle hooks, custom type configuration with finalizers, global state management, memory management patterns, parameter handling (including type checking with gc_object__is_instance_of), result returning, error handling, conditional logging, and a full end-to-end plugin example.
references/api_collections.md (opens in a new tab)references/api_core.md (opens in a new tab)references/api_memory_text.md (opens in a new tab)references/api_runtime_storage.md (opens in a new tab)references/api_services.md (opens in a new tab)references/plugin_development.md (opens in a new tab)references/standard_library.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub datathings/marketplace --plugin greycat-cOther plugins' skills for the same job