git-agent for Next.jsConventional commits for Next.js App Router and Pages Router
git-agent understands Next.js routing conventions, Server Actions, API routes, and middleware, producing atomic conventional commits that accurately reflect your Next.js-specific changes.
diff example
diff --git a/app/api/revalidate/route.ts b/app/api/revalidate/route.ts
index new file mode 100644
--- /dev/null
+++ b/app/api/revalidate/route.ts
@@ -0,0 +1,22 @@
+import { revalidatePath } from "next/cache";
+import { NextRequest, NextResponse } from "next/server";
+
+const SECRET = process.env.REVALIDATION_SECRET;
+
+export async function POST(req: NextRequest) {
+ const { secret, path } = await req.json();
+
+ if (!SECRET || secret !== SECRET) {
+ return NextResponse.json({ error: "unauthorized" }, { status: 401 });
+ }
+
+ if (!path || typeof path !== "string") {
+ return NextResponse.json({ error: "path required" }, { status: 400 });
+ }
+
+ revalidatePath(path);
+ return NextResponse.json({ revalidated: true, path });
+}git-agent output
feat(api): add on-demand revalidation endpoint for ISR paths
- implement POST /api/revalidate secured by REVALIDATION_SECRET env var
- validate path param before calling revalidatePath to avoid silent no-ops
- return structured JSON for both success and error cases
Allows the CMS webhook to trigger cache purges for specific pages without
a full rebuild; secret validation prevents unauthorised cache busting.Why it works for Next.js
- Understands App Router (app/) and Pages Router (pages/) directory conventions
- Separates Server Action changes from client component changes
- Groups next.config.js and middleware changes into appropriate commit types
- Handles route handler files (route.ts) and page files (page.tsx) distinctly
install
brew install gitagenthq/brew/git-agent
# inside your Next.js project
git-agent init # detects app/ or pages/ layout and suggests route scopesFAQ
Does git-agent understand Next.js dynamic route segments?Yes. Directory names like [id] and [...slug] are recognised as route parameters, and the LLM includes the route pattern in the commit scope.
How does git-agent handle changes to both layout.tsx and page.tsx?If the layout and page changes are logically related (e.g., both add the same auth guard), git-agent commits them together. Unrelated changes are split into separate commits.
Can git-agent commit my Server Actions separately from UI components?Yes. Files in a dedicated actions/ directory or files with 'use server' at the top are treated as a separate concern from UI components and committed independently when the changes are independent.