/Knowledge/sources/honojs__hono/llms-full/context-contextvariablemap--part-02--c8509029feca.md
Context: ContextVariableMap (part 02) - hono-docs
Context: ContextVariableMap (part 02) Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://hono.dev/llms full.txt contextvariablem...
Context: ContextVariableMap (part 02)
Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://hono.dev/llms-full.txt#contextvariablemap
Summary
You can augment the ContextVariableMap interface to define types for context variables globally across your entire application. This is appropriate when a variable is set by middleware that is applied app-wide and is guaranteed to exis...
Content
You can augment the ContextVariableMap interface to define types for context variables globally across your entire application. This is appropriate when a variable is set by middleware that is applied app-wide and is guaranteed to exist in the context.
For example:
declare module 'hono' {
interface ContextVariableMap {
result: string
}
}
You can then utilize this in your middleware:
import { createMiddleware } from 'hono/factory'
// ---cut---
const mw = createMiddleware(async (c, next) => {
c.set('result', 'some values') // result is a string
await next()
})
In a handler, the variable is inferred as the proper type:
Metadata
{
"chunk_index": 1,
"citation": "https://hono.dev/llms-full.txt#contextvariablemap",
"coverage_role": "overview",
"qualified_title": "Hono / llms-full / Context > ContextVariableMap (2)",
"retrieved_at": "2026-07-02T05:51:01Z",
"section_index": 568,
"source_id": "/honojs/hono",
"source_type": "llms_full",
"target_label": "llms-full",
"title": "Context: ContextVariableMap (part 02)",
"upstream_url": "https://hono.dev/llms-full.txt",
"version": "2026"
}