Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Access Durable Object name via `ctx.id.name`
description: Retrieve the name of a named Durable Object from within the object itself.
products:
- durable-objects
- workers
date: 2026-03-26

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @vy-ton did you add the correct link here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struggling to find what I was looking at, should just confirm @maxmcd when ctx.id.name was first available

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

---

`ctx.id.name` inside a Durable Object now matches what you see client-side. If a Worker accesses a Durable Object via `idFromName()` or `getByName()`, the same name is now available on `ctx.id.name` inside the object — no need to pass it through method arguments or persist it in storage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lead with your second sentence. The first sentence is confusing to a user - what is "what you see client-side".

When your Worker accesses a Durable Object via getByName()oridFromName(), ...

  • good to frame direct to user


Previously, the TypeScript type for `ctx.id` declared `name` as `string | undefined`, which led developers and LLM-based coding assistants to assume the name would be available inside the Durable Object. In reality, it was always `undefined` from inside, forcing manual workarounds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • let's remove focus on what wasn't supported, distracts here. Instead can emphasize this now correctly matches the Workers runtime types


```js
export class ChatRoom extends DurableObject {
async fetch(request) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feature a RPC method over fetch()

// ctx.id.name now matches the name passed to getByName() or idFromName() on the client side
const roomName = this.ctx.id.name;
return new Response(`Welcome to ${roomName}!`);
}
}

// Worker
export default {
async fetch(request, env) {
const stub = env.CHAT_ROOM.getByName("general");
return stub.fetch(request);
},
};
```

A few things to note about when `ctx.id.name` is set:

- **Populated** when the Durable Object is accessed via `idFromName()` or `getByName()`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already said so can remove to avoid repeat

I would mention something about alarms - we want users to understand that ctx.id.name is something that is available no matter how the DO is invoked. For example, the passing in name as arguement doesnt work for alarms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does ctx.id.name work locally?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- **`undefined`** for Durable Objects created with `newUniqueId()`.
- **`undefined`** when accessed via `idFromString()`, even if the ID was originally created from a name.
- **`undefined`** for names longer than 1,024 bytes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raises user question of what the limit for DO names are. Let's make sure thats documented


For more information, refer to the [Durable Object ID documentation](/durable-objects/api/id/#name).