The Complete Production SOP: How to Deploy and Run chi Lightweight Composable Standard HTTP Router for Go in Autonomous AI Agents
Step-by-step SOP to install and run chi router skill in Codex, Claude Code, and Cursor. Includes verified Go prompts, URL params, and sub-router SOPs.
Technical Overview & Architectural Context
When autonomous coding agents generate Go microservices, they frequently introduce anti-patterns such as breaking net/http compatibility with non-standard router interfaces, mismanaging context propagation across nested routing trees, or failing to cleanly decouple middleware stacks. Agents often confuse `http.Request.Context()` lifetime rules, inject custom handler signatures that break interoperability, or create unhandled routing collisions when nesting sub-routers with `r.Route()` and `r.Mount()`. The chi-lightweight-composable-router skill enforces strict adherence to Go's standard library conventions using `github.com/go-chi/chi/v5`. It forces agents to utilize idiomatic `http.Handler` and `http.HandlerFunc` signatures, extract URL parameters strictly via `chi.URLParam(r, key)`, apply foundational middleware (`middleware.RequestID`, `middleware.RealIP`, `middleware.Logger`, `middleware.Recoverer`) in deterministic order, and mount modular sub-routers without context drift or memory leaks.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules into the agent runtime path.
Autonomous coding assistants search `.agents/skills` or `.claude/skills` within the project root to mount active task execution SOPs. By mounting this skill file, the agent's LLM engine registers trigger phrases and automatically references verified chi routing practices before generating any Go server code.
mkdir -p .agents/skills/chi-lightweight-composable-router && curl -fsSL https://askills.dev/api/skills/chi-lightweight-composable-router/raw -o .agents/skills/chi-lightweight-composable-router/SKILL.md---
name: "chi-lightweight-composable-router"
description: "Build 100% net/http compatible Go microservices with clean, composable chi routers."
metadata:
author: "Peter Bourgon & chi authors"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "create chi router"
- "chi.urlparam extraction"
- "standard http.handler chi"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# chi Lightweight Composable Standard HTTP Router for Go
Implements go-chi/chi: standard http.HandlerFunc compatibility, URL param extraction (chi.URLParam), sub-routers (r.Route), middleware chaining (r.Use), request context passing, and graceful shutdown.
## When to Invoke
Invoke this skill whenever you need to:
- create chi router
- chi.urlparam extraction
- standard http.handler chi
## Execution SOP & Rules
1. Create router: r := chi.NewRouter(); r.Use(middleware.RequestID, middleware.RealIP, middleware.Logger).
2. Extract route parameters: articleID := chi.URLParam(r, 'articleID').
3. Mount sub-routes: r.Route('/api', func(r chi.Router) { r.Mount('/v1', v1Router) }).
4. Pass router directly to standard http.ListenAndServe(':8080', r).
## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.Ensure the SKILL.md file remains under 300 lines to minimize context window penalty while maintaining high-priority routing guardrails.
If you are running in Cursor or Windsurf, ensure the directory is inside your active workspace root; global home directory installs may be ignored in restricted agent containers.
Environment Secrets & Dependency Validation
Import github.com/go-chi/chi/v5 and verify module dependencies inside the workspace boundary.
Chi requires no external dependencies outside the Go standard library, keeping builds hermetic and lightweight. Ensure the agent installs v5 specifically and synchronizes `go.mod` and `go.sum` without downloading extraneous web frameworks.
go get github.com/go-chi/chi/v5 && go get github.com/go-chi/chi/v5/middleware && go mod tidyNever allow agents to write authentication credentials or port bindings directly into Go source files; instruct them to read standard environment variables via `os.Getenv`.
Verify that previous references to `github.com/go-chi/chi` (v1-v4) are purged from `go.mod`, otherwise build collisions and package ambiguity will cause compilation failure.
Intent Matching & Trigger Invocation
Trigger deterministic chi router construction using explicit frontmatter-matched intent prompts.
Agent runtimes scan user prompts against the `triggers` block of available skills. When a matched trigger such as 'create chi router' or 'chi.urlparam extraction' is supplied, the agent adheres to standard HTTP handler patterns rather than inventing third-party or custom handler types.
Frame prompts using standard Chi idioms: explicitly specify sub-routing patterns, URL param keys, and middleware requirements in your initial message.
Avoid prompt instructions like 'build a lightweight web server' without naming chi, as generic phrasing may cause the agent to fall back on `net/http.ServeMux` or heavyweight frameworks like Gin or Fiber.
Verification, Linting & Output Quality Gate
Run Go compilation and unit tests against chi route bindings to verify deterministic execution.
Before completing the task, the agent must run `go vet` and `go test` with `httptest.NewRecorder` to ensure route resolution, middleware execution, and URL param extraction yield 200 OK statuses.
go vet ./... && go test -v -race ./...Require the agent to generate a complementary `_test.go` file using `net/http/httptest` to validate route parameter resolution automatically.
Ensure that `shell_exec: false` permissions in the skill manifest are respected; execute the verification command in your own terminal if agent shell execution is locked down.
Real-World Scenario: Scaffold a Versioned REST API with Param Extraction and Middleware
“create chi router for a microservice with standard http.handler chi handlers. Set up default middleware (RequestID, RealIP, Logger, Recoverer), route group /api/v1, and implement chi.urlparam extraction for GET /api/v1/workspaces/{workspaceID}/users/{userID}.”
Runtime Troubleshooting & Failure Modes
Root Cause: The route handler was mounted with standard `http.Handle("/resource/*", ...)` or `r.Mount()` rather than `r.Route()`, which strips the Chi routing context from the request context before the handler evaluates it.
Use `r.Route("/resource", func(r chi.Router) { r.Get("/{id}", handler) })` instead of `r.Mount("/resource/", ...)` to preserve context parameter mapping.Root Cause: The Go workspace is importing legacy v1-v4 imports (`github.com/go-chi/chi`) while go.mod references `github.com/go-chi/chi/v5`, or module dependencies were not updated post-generation.
go get github.com/go-chi/chi/v5@latest && go mod tidyFrequently Asked Questions (chi Lightweight Composable Standard HTTP Router for Go SOP)
Q:Can I use chi Lightweight Composable Standard HTTP Router for Go across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification supported across all modern agent runtimes. Simply place the file in `.agents/skills/chi-lightweight-composable-router/SKILL.md` within your project repository.
Q:How does chi Lightweight Composable Standard HTTP Router for Go prevent context window overflow during long agent sessions?
By establishing concise procedural boundaries and deterministic validation gates rather than polluting system prompts with redundant rules. It confines agent output to canonical `net/http` implementations without unnecessary framework abstractions.
Q:Does this skill require escalated root or container permissions?
No. It is audited with a security score of 98/100, requiring only workspace file read/write access. It executes without root privileges, outbound network requirements, or shell execution rights.
Ready to equip your autonomous agent with chi Lightweight Composable Standard HTTP Router for Go?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.