/blender:codingfrom blender
Use when writing or reviewing Python that runs inside Blender, covering bpy code from data references to host boundaries
Ships in blender. 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.
Code runs on Blender's bundled Python 3.13 and takes no 3.14 or 3.15 form: imports stay eager, frozen mappings are types.MappingProxyType, TypeForm imports from typing_extensions, annotations read through inspect.get_annotations(owner, eval_str=True), and text another program parses escapes each value at its format site (shlex.join) in place of a t-string. A package entry that also runs on 3.15 names its private modules in __lazy_modules__, which 3.13 ignores.
rna_enums literals, <Class>.bl_idname)[REFERENCES]:
execute through its propertiesmathutils semantics against RNA and numpy, host members over hand-written geometryHost references go stale after their event, and code holds the form that survives:
| [INDEX] | [REFERENCE] | [STALE_AFTER] | [HOLD] |
|---|---|---|---|
| [01] | ID | remove(), undo step touching it, file load | session_uid, name and library after a load |
| [02] | Vertex, bone, point, UV, attribute | mode_set, container growth, ID removal | Index or name, re-read after the change |
| [03] | CollectionProperty item | add() on its collection | Index, re-read after each add() |
| [04] | Grease Pencil stroke or point | remove_strokes, resize_strokes | frame.drawing read again |
| [05] | Keyframe | Next insert on its F-curve | keyframe_points re-read per insert |
| [06] | mathutils value read from RNA | Owner write (read live), owner removal | .copy() |
| [07] | PropertyGroup on an ID | Undo | Re-resolved through its ID |
| [08] | Evaluated ID | Depsgraph.update(), rewriting it in place | Values copied out per evaluation |
| [09] | object_instances item | Next iteration step | Values copied per step |
| [10] | to_mesh() result | Re-evaluation, to_mesh(), to_mesh_clear() | Scope calling to_mesh_clear() |
| [11] | GeometrySet component | Release of its GeometrySet | GeometrySet bound for the read |
| [12] | Struct with a class a write refines | Light.type, interface socket_type | Re-read from its owner after the write |
| [13] | Generated properties.inputs struct | Group assignment, any interface write | properties.inputs re-read after each write |
| [14] | Pointer an operator re-targets | object.convert, importer obj.data swaps | Read through its owner after the call |
| [15] | Dynamic enum EnumPropertyItem | End of enum_items iteration listing it | Item identifier |
Stale references fail by kind:
object_instances item, to_mesh() mesh, and GeometrySet component references raise ReferenceError on every readKeyframe, PropertyGroup, and mathutils references read freed or reused memory, returning wrong values or crashing Blenderdefault_value write includedWrites to some members reset other members:
system writes reset length_unit and mass_unit, an equal value included, and leave temperature_unit and time_unitrotation_mode names the rotation member evaluation reads, and writes to the other rotation members store and change nothingparent writes keep matrix_basis and move the object, and a matrix_world copied before the write and assigned after it keeps the placementCreation, removal, selection, and scope follow host rules:
.new() returns the ID or node to keep, a name taken in its collection or tree suffixed .001, an ID name cut at 255 bytesbpy.data.<collection>.new and new_from_object meshes start with zero users until code links them, and saves drop zero-user IDsmaterials, append adding a slot on each sharing object and pop(index=) shifting higher face material_index downslot.link = 'OBJECT' overrides one object's slot starting at None, the data's entry and every other object's slot keptbpy.data.batch_remove(ids=...) removes the IDs named alone, scanning users once where each remove() scans every userbatch_remove crashes Blender on a removed ID, and held IDs resolve by session_uid before the callscene.objects, view_layer.objects, a collection), bpy.data.objects holding orphans, other scenes, and linked datascene.world, context.scene), bpy.data.<collection>[0] naming the alphabetically first blockselect_set(True) raises RuntimeError for an object outside the view layer and changes nothing on a hide_select objecthide_set is per view layer, hide_viewport global, LayerCollection exclude and hide_viewport per layer, visible_get() combining themRemoving an object leaves its data at zero users, and removals name objects with the data no other user holds in one batch_remove:
def removed(objects: tuple[bpy.types.Object, ...], /) -> None:
held = frozenset(objects)
users = bpy.data.user_map(subset=tuple(item.data for item in objects if item.data is not None))
bpy.data.batch_remove(ids=(*objects, *(block for block, holders in users.items() if holders <= held)))
Identity and lookup follow host keys:
bpy.data.<collection>[(name, None)] reads local data alone, (name, <library path>) linked datain, and get lookups on bpy.data collections scan linearly, and operations resolving many build one {session_uid: id} mapbpy.data.all_ids iterates every ID except embedded data (material, world, light, and scene node trees, each Scene.collection)bpy.data.<collection> iterates in name order, and loops that rename iterate bpy.data.<collection>[:]Collection.all_objects[:]"Material Output") translate with the interface language, and code holds the returned reference or matches typebpy.data.node_groups with id_data naming each tree, and keys over them take the holding ID==session_uid, stable across renames, undo, and an undone removal while as_pointer() addresses repeattype(<struct>).__name__ names a refined subtype (SunLight), and dispatch matches base classes through isinstance or a class patternObjectModifiers) never match a bpy_prop_collection value, and code binds the collection's own membername in T.bl_rna.properties or T.bl_rna.functionsbpy.ops.<module>.<name>.get_rna_type() raises KeyError for an operator the build lacks, its struct listing parameters in propertiesenum_items invokes context-free providers and exposes declared items for context-dependent enumsenum_items_static lists declared items without calling a dynamic providerTypeError listing live itemsUILayout.enum_item_name(data, prop, identifier) reads a dynamic enum's live label and "" for an identifier outside the live itemsNone items (texture_slots), and iteration enumerates before skipping None to keep host indicesPer-object operator loops compound edits and costs, each call acting on the whole selection. Calls pay a context resolve, a view-layer update before the call and after FINISHED, and undo bookkeeping. Work takes a data API member where one does it, else a built-in operator, bpy_extras, _bpy_internal, or bundled add-on member Blender includes:
| [INDEX] | [WORK] | [FORM] |
|---|---|---|
| [01] | New ID | bpy.data.<collection>.new, then an explicit link |
| [02] | Topology edit | bmesh scope |
| [03] | Per-element values | foreach_set over attributes |
| [04] | Keys and drivers | keyframe_points.add with foreach_set, driver_add |
| [05] | Active and selected objects | view_layer.objects.active, select_set, set independently |
| [06] | Operator override | Every member the operator reads, derived members included |
| [07] | Procedure Blender includes | Included member, operators under a temp_override |
| [08] | Constraint applied | Updated matrix_world copied, constraint removed, copy set |
| [09] | Modifier stack applied | new_from_object mesh as data, then modifiers.clear() |
| [10] | Rigid body | rigidbody.world_add, then a link into its collection |
Overrides reach the members an operator reads alone:
selected_objects overrides leave selected_editable_objects reading the window's own selectionobject.mode_set acts on view_layer.objects.active and exporter selected-only options on selection, returning FINISHEDwindow= alone sets workspace and screen and clears area and regionscreen= of another workspace switches the window's workspace and the active object's mode for the blockTypeError at __enter__, and members passed as None enter with no raisetemp_override accepts unknown keywords with no raisewindow and screen but no area, editor operators overriding with a screen.areas VIEW_3D area and its WINDOW regionOperator calls fail by raising (RuntimeError, TypeError) or by a return set holding no success, and called turns both into a fault keeping the exception or set as cause. Stubs type each operator as a class with __new__ stating its properties, and called takes them through a ParamSpec ty checks per call. object.join reads active_object and selected_editable_objects and leaves joined meshes at zero users, one batch_remove after the call clearing them on a join and nothing on a failure:
def called[**P](operator: Callable[Concatenate["OperatorContextItems", P], Returns], subject: str, /, *args: P.args, **keywords: P.kwargs) -> Outcome[Returns]:
try:
answer = operator("EXEC_DEFAULT", *args, **keywords)
except (RuntimeError, TypeError) as error:
return Error(Fault.of(Reason.FAILED, subject, error))
return Ok(answer).filter_with(lambda held: not held.isdisjoint({"FINISHED", "RUNNING_MODAL", "INTERFACE"}), partial(Fault.of, Reason.FAILED, subject))
def merged(context: bpy.types.Context, target: bpy.types.Object, items: Sequence[bpy.types.Object], /) -> Outcome[bpy.types.Object]:
joined = tuple(item.data for item in items if item.data is not None)
with context.temp_override(active_object=target, selected_editable_objects=[target, *items]):
answer = called(bpy.ops.object.join, target.name)
bpy.data.batch_remove(ids=tuple(block for block in joined if block.users == 0))
return answer.map(lambda _: target)
Calls and their return sets:
scene.render.bake for object.bake) and preferences (align, Edit Mode entry)'INVOKE_DEFAULT' runs invoke in a GUI session, and wm.call_menu crashes a background run under either call formpoll makes the call raise RuntimeError("Operator bpy.ops.<op>.poll() failed, context is incorrect")ERROR, ERROR_INVALID_INPUT, ERROR_INVALID_CONTEXT, and ERROR_OUT_OF_MEMORY reports raise as one RuntimeError in either return setFINISHED means a built-in operator ran (mesh.fill_grid on an odd loop adds no face), and dependent work reads the data it wrote{'FINISHED'}, {'RUNNING_MODAL'}, {'INTERFACE'}, {'CANCELLED'}, or {'PASS_THROUGH'}CANCELLED and PASS_THROUGH mean failure, built-in operators returning CANCELLED with nothing to act onRUNNING_MODAL or INTERFACE finishes after the call in a GUI session, dependent reads running from a later timer stepwindow.workspace and file-browser params writes apply one event-loop pass later, dependent work running from a timer or modal steparea.type and show_region_* writes apply inside the writeCreated IDs are the bpy.data.all_ids difference across a call in place of a requested name or selected_objects. Raising calls keep their writes, and one function serving every importer removes the created set on a failure. Importers share no stub base, and Importer states the execution context and filepath keyword each takes:
class Importer(Protocol):
def __call__(self, execution_context: "OperatorContextItems", /, *, filepath: str) -> Returns: ...
def imported(importer: Importer, source: Path, /) -> Outcome[frozenset[bpy.types.ID]]:
before = frozenset(bpy.data.all_ids)
answer = called(importer, str(source), filepath=str(source))
created = frozenset(bpy.data.all_ids) - before
bpy.data.batch_remove(ids=tuple(created if answer.is_error() else ()))
return answer.map(lambda _: created)
imported(bpy.ops.wm.obj_import, source) returns the created mesh and object, and an unreadable file returns one fault holding the importer's report.
Settings, operator properties, and preferences are bpy.props annotations on PropertyGroup, Operator, and AddonPreferences classes. Properties take Blender's keywords (min, max, soft_min, soft_max, step, precision, subtype), a use_<name> BoolProperty beside each value it switches. Copies of an RNA member take every keyword its RNA states, enum items as 5-tuples keeping each item's RNA value and floats their unit in place of subtype. Update callbacks act on the owning ID through id_data in place of the active item:
def copied(owner: type[Struct], member: str, /, *, update: Callable[[bpy.types.PropertyGroup, bpy.types.Context], None] | None = None) -> bpy.props._PropertyDeferred:
described = owner.bl_rna.properties[member]
match described:
case bpy.types.EnumProperty(enum_items=items, default=default):
definition = partial(bpy.props.EnumProperty, items=tuple((item.identifier, item.name, item.description, item.icon, item.value) for item in items), default=default)
case bpy.types.BoolProperty(array_length=0, default=default):
definition = partial(bpy.props.BoolProperty, default=default)
case bpy.types.FloatProperty(array_length=0) as real:
definition = partial(
bpy.props.FloatProperty,
unit=real.unit,
min=real.hard_min,
max=real.hard_max,
soft_min=real.soft_min,
soft_max=real.soft_max,
step=real.step,
precision=real.precision,
default=real.default,
)
case _:
raise TypeError(f"{owner.__name__}.{member} is a {described.type} property")
return definition(name=described.name, description=described.description, update=update)
def retagged(self: bpy.types.PropertyGroup, _context: bpy.types.Context, /) -> None:
for owner in option.of_optional(self.id_data).to_list():
owner.update_tag()
light = partial(copied, bpy.types.Light, update=retagged)
class Lamp(bpy.types.PropertyGroup):
kind: Annotated[str, light("type")]
use_reach: Annotated[bool, light("use_custom_distance")]
reach: Annotated[float, light("cutoff_distance")]
kind starts at POINT and stores AREA as its Light.type value 4, where 3-tuples store position 3. copied(<class>, <member>) copies static or context-free RNA enum items, booleans, and scalar floats; light binds owner and callback once:
partial binds each kind's keywords and one call adds name, description, and callback, ty refusing a ** dict of mixed values at each typed bpy.props parameterXYZ, COLOR), which register_class refuses on FloatProperty with ValueError and drops the propertybpy.props definitions take the form Blender registers:
poll and update take function objects with exact positional arity, defaulted parameters counted, and a factory returns the closureTypeError at register_class and drop the property from the registered class, int32 overflows printing OverflowErrorfloat32 store as infinity, and min > max and out-of-range defaults register with no errorsession_uid, ID PointerProperty printing ValueError at register_class and dropping from operatorPointerProperty takes ID and PropertyGroup types, CurveMapping, ColorRamp, Scopes, and Histogram coming from an owning IDPointerProperty poll filters UI assignment alone, and assigning an embedded ID (Scene.collection, Material.node_tree) raises RuntimeErrorsubtype (DISTANCE and XYZ_LENGTH read unit LENGTH), a mismatched unit logging at each subtype readget and set hold values stored outside Blender, set needing get and get alone making the property read-onlyset_transform(self, new_value, stored_raw_value, is_set) results clamp to hard boundsget and get_transform(self, stored_value, is_set) results stay unclampedupdate, get, set, and transform callbacks can run in a threaded context per data-block, call no operator, and touch their own ID aloneitems callbacks accept a None context and number items stably per identifier, with an integer defaultFILE_PATH and DIR_PATH properties accepting // declare PATH_SUPPORTS_BLEND_RELATIVEself, with the window manager as id_dataRegistered values read and write through Blender:
ID.keys(); nested PropertyGroup members share the group's storageob["prop"] = value on a registered name creates a separate custom propertyproperty_unset resets a value, and is_property_set(name) counts a value reused from the last run as unset, ghost=False counting it as setcursor_location, is_dirty) and PASSWORD tokens (auth_token, access_token)bl_rna.properties[name].is_readonly is static, and struct.is_property_readonly(name) reports the member's read-only state in its current contextUndo restores bpy.data outside window manager and screen data, and each change pushes its step by form:
| [INDEX] | [CHANGE] | [STEP] | [FORM] |
|---|---|---|---|
| [01] | Operator body that edits data | One per FINISHED from UI, keymap, undo call | bl_options with UNDO |
| [02] | Script bpy.ops call | None, writes joining the next step | bpy.ops.<op>('EXEC_DEFAULT', True) |
| [03] | Operator called inside an UNDO body | None, outer step holding every write | Nested bpy.ops call |
| [04] | Window manager, screen, preference write | None | bl_options without UNDO |
| [05] | Steps the operator names itself | One per ed.undo_push(message=...) | REGISTER without UNDO |
| [06] | Repeated calls collapsing into one step | One across consecutive calls of a group | UNDO_GROUPED, no UNDO, bl_undo_group |
| [07] | Deferred callback write | One per write that changed data | Write, then ed.undo_push(message=<step>) |
| [08] | Background run | None until a script's ed.undo_push() | ExitStack of restores and inverse writes |
Undo steps act on held state:
ReferenceError while untouched IDs keep workingupdate callbackwindow_manager.undo_stack lists steps, active_index, and active, reading None before the first pushHandler, timer, msgbus, and modal bodies run in a context Blender chose:
Noneload_* and save_* handlers receive "" as the startup file's path*_post handlers read the scene and depsgraph they receiveframe_set fires frame_change_pre and frame_change_post aloneframe_change_pre writes data for the frame, and frame_change_post handlers read evaluated resultsSystemErrorGPUOffScreen, batch_for_shader, draw_view3d) after gpu.init(), and gpu.texture.from_image before it crashes BlenderRegion.data None, and RegionView3D.update() crashes thembpy.msgbus keys name a class and member ((bpy.types.Object, "location")) or one instance's member through data.path_resolve("<member>", False)PERSISTENT subscriptions survive ID remappingbpy.props publish no msgbus notification, update or not, and bpy.msgbus.publish_rna(key=<key>) publishes thembpy.ops calls release the GIL to live Python threads mid-operator, and threads (multiprocessing.Queue feeders included) join before a bpy callEach entry point translates the result once into Blenders form:
| [INDEX] | [ENTRY] | [RESULT] |
|---|---|---|
| [01] | execute with changes made | Reports at their levels, a WARNING per skipped item, with {'FINISHED'} |
| [02] | execute with nothing changed | Reason as INFO with {'CANCELLED'} |
| [03] | execute with faults | ERROR report per fault with {'CANCELLED'}, file as the body found it |
| [04] | poll | False with poll_message_set of unmet requirements |
| [05] | Update callback, handler, timer | Faults logged through a structlog logger, a raise printing its traceback |
| [06] | RenderEngine.render | report({'ERROR'}, ...) cancelling render |
| [07] | --python script | sys.exit of None, or of faults joined by newlines for exit 1 |
Helpers below an operator body return faults as the error and skipped-item faults as the success value, and the body reports each once:
def answered(operator: bpy.types.Operator, outcome: Outcome[tuple[Fault, ...]], /) -> Returns:
match outcome:
case Ok(skipped):
for fault in skipped:
operator.report({"WARNING"}, fault.message)
return {"FINISHED"}
case Error(faults):
for fault in faults:
operator.report({"ERROR"}, fault.message)
return {"CANCELLED"}
--python scripts read their arguments after -- in sys.argv, Blender's own flags filling the entries before it.
Blender calls that raise nothing decide the result through their return:
None returns and invalid results (false NodeLink.is_valid, targetless Constraint.is_valid) are faults at the callCANCELLED keeps the writes a body made before its fault outside undo, and dependent steps roll back through the body's ExitStack scopeRenderEngine.render complete the render as FINISHED, and error_set cancels nothinguse_pin_to_last modifiers after unpinned onesValues cross the boundary in Blenders units and axes:
unit_settings.scale_length and angles radians, and decoded values hold SI quantitiesbpy.utils.units.to_string(system, category, value, split_unit=True) and parse through bpy.utils.units.to_valueto_value reads - and + as arithmetic and unitless numbers as the base unitbpy.utils.time_to_frame and time_from_frame convert seconds through the context scene's frame ratebpy_extras.io_utils.axis_conversion(from_forward=, from_up=, to_forward=, to_up=).to_4x4()forward_axis and up_axis (OBJ, STL, PLY), axis_forward and axis_up (FBX), or export_yup (glTF)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
7 skills in this plugin
/debuggingUse when Python or native code inside Blender gives a wrong value, raises, hangs, crashes, or never stops at a breakpoint, covering debug endpoints, stops by code kind, extension reloads, stack dumps, crash reports, native frames, and GPU captures/extensionsUse when writing or reviewing a Blender extension's registration, preferences, or manifest, covering lifecycle and packaging/hostUse when driving Blender or reading bpy members from the installed build, covering host control and installed-extension workflowsnpx claudepluginhub bsamiee/rasm --plugin blender