Hamur for coding agents
This page is the long instructions for an agent that writes a Hamur app. It ships inside the hamur package as node_modules/hamur/docs/agents/hamur.md, with one Markdown file for every other docs page, so an agent reads the docs of the installed version and not the web.
Read the installed docs first
node_modules/hamur/docs/ holds one file per docs page: docs/<path>.md is the page /<path> (docs/getting-started.md, docs/routing.md, docs/api-reference/adapters.md; docs/index.md is the home page). The files are the same Markdown as the .md copy of each page on the web, with the code samples in place. Search the folder for a name before you use it, and read the page of the topic before you write.
The same pages are online as /llms.txt and /llms-full.txt. They follow the latest release, so for an app on an older version the installed files are the ones that apply.
The package also holds a skill, node_modules/hamur/skills/hamur/SKILL.md, which points here. Hamur writes nothing into .claude/ or any other agent folder; link the folder node_modules/hamur/skills/hamur into the place your agent loads skills from, once.
While hamur dev runs, .hamur/dev.lock names the URL of the dev MCP endpoint. Call get_errors after an edit, and get_routes or get_page before you guess a route.
File layout
| Path | What it is |
|---|---|
app/pages/ | Pages. A file is a route. |
app/layouts/ | Layouts. default wraps every page. |
app/components/, app/composables/, app/utils/ | Your code, imported by path. |
server/index.ts | The door of the server: the handlers pages call are its named exports. |
server/ | Handler definitions and helpers. |
shared/ | Code for both sides, imported as #shared/… (package.json imports). |
public/ | Static files, served as they are. |
hamur.config.ts | The config. |
.hamur/ and .output/ are generated. Never edit them. See Directory structure.
The loader rule
A page that needs data before it renders has a file beside it with the same name and a .load.ts ending: app/pages/blog/[slug].load.ts loads the data for app/pages/blog/[slug].tsx. A load file calls handlers and holds no server code. app/ holds no server code at all; anything that reads a database, a secret or a file is a handler in server/.
import type { Load } from "hamur/app"
export const load = (({ params }) => ({ title: `Post ${params.slug}` })) satisfies Load
One form for each job
| The job | Use |
|---|---|
| Code that runs on the server | defineHandler from hamur/server, exported from server/index.ts |
| Data a page shows | useAsyncData(handler, input), or the page's x.load.ts |
| The answer of another service | useFetch(url) |
| A form | Form action={handler} |
A handler is a typed function. A page imports it from #server and calls it; on the server this is a function call, in the browser a request.
import { defineHandler } from "hamur/server"
export const hello = defineHandler({
route: "/api/hello",
method: "GET",
handler() {
return { message: "Hello" }
},
})
import { Form, useForm, useRoute } from "@hamur/adapter-react"
import { sendContact } from "#server"
export default function Contact() {
const { fields, pending } = useForm(sendContact)
const route = useRoute()
if ("sent" in route.query) return <p>Thanks, we will write back.</p>
return (
<Form action={sendContact}>
<label>
Email <input {...fields.email.as("email")} />
</label>
{fields.email.issues().map((issue) => (
<p role="alert" key={issue.message}>
{issue.message}
</p>
))}
<label>
Message <textarea {...fields.message.as("textarea")} />
</label>
{fields.message.issues().map((issue) => (
<p role="alert" key={issue.message}>
{issue.message}
</p>
))}
<button disabled={pending}>Send</button>
</Form>
)
}
See Data, Handlers and Forms and login.
Import every name
There are no auto-imports. A file imports each name it uses, from hamur/app, hamur/server, @hamur/adapter-<library>, a module's package or a relative path. defineConfig comes from hamur. An agent that writes a name it did not import writes a bug.
The adapter API
The adapter of the app's library (@hamur/adapter-react, -preact, -vue, -solid, -svelte, -html or -angular) exports the same names in every library, listed here and described on @hamur/adapter-<library>.
- Components:
Link,LinkProps,LinkSlot,MarkdownRenderer,MarkdownRendererProps,Form,FormProps,Outlet,ClientOnly,ClientFallback,ClientFallbackProps,DevOnly,useHydrated,onPrehydrate,useId,defineLazyHydrationComponent,Island,IslandProps,defineIsland,island,HtmlIsland,IslandOptions,ServerIsland,ServerIslandProps,serverIsland,ServerIslandOptions,Await,AwaitProps,AwaitOptions,useDeferred,Deferred,Time,TimeProps,transitionName,LoadingIndicator,LoadingIndicatorProps,useLoadingIndicator,useAppUpdate,RouteAnnouncer,useRouteAnnouncer,Announcer,useAnnouncer,RouteAnnouncerProps,ErrorBoundary,ErrorBoundaryProps,DefaultErrorPage,rerunOnHydrate,HtmlProps,HtmlChildren. - Route and navigation:
useRoute,useResolvedPath,useRouter,useNavigation,useLinkStatus,defineLink,useLink,LinkDefaults,UseLinkOptions,Navigate,NavigateProps,onBeforeNavigate,onNavigate,onAfterNavigate,onPageActivated,onPageDeactivated,disableScrollHandling,onBeforeRouteLeave,onBeforeRouteUpdate,useBlocker,usePreventNavigate,Blocker,BlockerArgs,UseBlockerOptions,useSnapshot,SnapshotOptions,usePoll,useOnline,useSyncedState,useSearch,useOptimistic,useAction,UseActionResult,useFormStatus,useForm,useData,useRouteData,useMatches,MatchedRoute,RouteDataName,RouteDataOf,useOutletContext,useLayoutSegment,useLayoutSegments,useLayout,setPageLayout,addRouteMiddleware. - Errors:
useError,clearError,notFound,forbidden,unauthorized,permanentRedirect,showError,navigateTo,NavigateToOptions. - App:
useApp,useRuntimeHook,useReportWebVitals,onAppReady,useRuntimeConfig,useSiteConfig,AngularSetup(Angular'sapp.adapter). - Head:
useHead,useSeoMeta,useHeadSafe,HeadTitle,HeadMeta,HeadLink,HeadScript,HeadStyle,HtmlAttrs,BodyAttrs,useServerHead,useServerSeoMeta. - State and cookies:
useState,useCookie,refreshCookie,UseCookieWatchOptions. - Request:
useRequestEvent,useRequestHeaders,useRequestHeader,useRequestURL,useRequestFetch,usePreviewMode,setResponseStatus,useResponseHeader,HttpStatusCode,HttpHeader,clearState,callOnce. - Data in components:
useAsyncDataEntry,useNuxtData,useAsyncData,useFetch,UseAsyncDataOptions,UseAsyncDataResult,UseFetchOptions,PickFrom,createUseFetch,createUseAsyncData,useLazyFetch,useLazyAsyncData. - Shared types:
Navigation,NavigationType,BeforeNavigateHook,NavigateHook,AfterNavigateHook,RouteValue,RouterApi,NavigateOptions,NavigationState,GetCachedData,GetCachedDataCause,AsyncDataHandler,FetchRequest,ErrorBoundaryFallbackProps.
In Angular the use… names are inject… functions that return signals, called in an injection context: injectRoute, injectRouter, injectNavigation, injectLink, injectLinkStatus, injectResolvedPath, injectOutletContext, injectLayout, injectLayoutSegment, injectLayoutSegments, injectSearch, injectBlocker, injectPreventNavigate, injectMatches, injectRouteData, injectData, injectAsyncData, injectFetch, injectLazyAsyncData, injectLazyFetch, injectNuxtData, injectState, injectCookie, injectHead, injectSeoMeta, injectHeadSafe, injectServerHead, injectServerSeoMeta, injectApp, injectRuntimeConfig, injectSiteConfig, injectRuntimeHook, injectReportWebVitals, injectPreviewMode, injectOnline, injectAppUpdate, injectRequestEvent, injectRequestHeaders, injectRequestHeader, injectRequestURL, injectRequestFetch, injectResponseHeader, injectError, injectForm, injectAction, injectOptimistic, injectFormStatus, injectPoll, injectSyncedState and injectSnapshot; async data is an AsyncDataResource, Angular's Resource with refresh() and clear(), and its options are InjectAsyncDataOptions and InjectFetchOptions; injectAction returns an InjectActionResult and injectForm an InjectFormResult (its for(key) an InjectFormInstance). Form is the directive form[hamurForm], and with FormsModule imported a Hamur form carries ngNoForm. Link is the directive a[hamurLink], Outlet the component hamur-outlet and Navigate the component hamur-navigate; Island the component hamur-island (inputs component, props, on, fallback, persist, persistProps; each island is an application of its own) and ServerIsland the component hamur-server-island (name, props, fallback, a TemplateRef); DevOnly is the structural directive [hamurDevOnly], Time the directive time[hamurTime], LoadingIndicator, RouteAnnouncer, Announcer and MarkdownRenderer the components hamur-loading-indicator, hamur-route-announcer, hamur-announcer and hamur-markdown, with injectLoadingIndicator (its option type LoadingIndicatorOptions), injectRouteAnnouncer (its politeness is a RouteAnnouncerPoliteness), injectAnnouncer (its option AnnouncerPoliteness), injectDeferred, injectHydrated and injectId; there is no ClientOnly, Await or defineLazyHydrationComponent: @defer (on immediate), injectDeferred with @if and @defer (hydrate on …) do their work; onPageActivated, onPageDeactivated and onPrehydrate keep their names, and transitionName(name) is the [style] object; onBeforeNavigate, onNavigate, onAfterNavigate, onBeforeRouteLeave and onBeforeRouteUpdate keep their names and end with the component.
A library may not export a name; the table of each section of the reference shows which do (—). Check it before you use a name in a library you have not used.
Modules have no runtime dependency
A Hamur module keeps dependencies empty in its package.json. A library it needs is a peerDependencies entry, and what Bun or the Web platform lacks is written in the module. Do not add a runtime dependency to a module to save a few lines; the build warns <name> has dependencies; first-party modules keep it empty. See Modules.