# Access Request

> A prompt for the agent to widen its own access — network, credentials, folders — showing the agent's reason beside a system-rendered before → after of each setting, who else it affects, and Approve or Deny.

- Category: permissions
- Job: Oversee — Show progress and reasoning while the AI works, and let people approve, pause or stop it.
- Slug: `access-request`
- HTML: https://ai-patterns.app/patterns/permissions/access-request
- JSON: https://ai-patterns.app/api/patterns/permissions/access-request
- Seen in: [Claude](https://code.claude.com/docs/en/claude-code-on-the-web)

## Summary
A prompt the agent raises when it needs more access than it has — a wider network, a new credential, a broader folder, a shared resource — and only a person can grant it. The product, not the agent, renders what would change: the target and who owns it, each setting as before → after, and who else the change reaches. The agent's justification sits beside it, clearly attributed, so the person can weigh the reason against the facts. Approve and Deny are the only ways out, and the answer collapses to a one-line record.

## When to use
- An agent hits a boundary set by its environment or sandbox (blocked host, missing secret, read-only path) and the task can't continue without changing that boundary.
- The change outlives the current action — it's saved on an environment, a workspace or a team setting — so it needs a deliberate grant, not a per-call yes.
- The change can reach other people or sessions, and the person approving needs to see that before saying yes.

## When not to use
- Approving one tool call with no lasting effect. Use Tool Approval; it's lighter and offers allow-once.
- Choosing between several ways forward ("allow these three hosts, or everything?"). Ask that first with a Human in the Loop question, then raise one request for the option chosen.
- Granting access the person doesn't control (an admin-owned policy). Say who can grant it and how to ask them, instead of offering an Approve that will fail.
- Collecting the secret itself. Send the person to a secure form; the card never holds a token or password.

## Anatomy
- Header: a lock tile, the request as a question ("Update environment?"), and under it the target's name with an ownership badge (Personal, Team, Organization).
- Reason: the agent's own sentence in a muted block, captioned with the agent's name ("Claude's reason"), so it reads as a quote, not as a system fact.
- Changes: a compact table, one row per setting — label, old value struck through, arrow, new value — so values line up for scanning. A "Widens access" tag marks any row that lets the agent reach more than before.
- Footer: the impact line — who and what the change applies to beyond this moment ("this session and every session that uses this environment") — on the leading side, and the actions on the trailing side: a quiet Deny, then the primary button named for the effect ("Update environment"). On narrow screens the actions can stack full width below the impact line.
- Resolved state: a single row — "Access updated" with the new values, or "Request denied" and that the agent continues without it.

## Behavior
- The changes list and impact line come from the system that will apply the change, computed from the actual diff. The agent supplies only the reason; it can't word the change or soften its scope.
- Nothing changes until Approve. Deny is final for this request, and the agent must carry on without the access and say what remains blocked — it doesn't re-ask in chat or raise the same request again.
- Approving applies the change at once and the agent retries the blocked step; the resolved row records what was granted so it stays visible in the transcript.
- No default focus on Approve: a request that widens access shouldn't be one Enter away.
- Entry is a short rise and fade; the swap to the resolved row is a crossfade. Both drop to instant under reduced motion.

## Content guidelines
- Name the primary button after the effect ("Update environment", "Add credential"), not "OK" or "Allow".
- Values are literal and complete: "Any host", "api.example.com", "12 domains → discarded". Never "more access" or "some settings".
- The reason is one sentence about the task it unblocks ("Let the scout read public docs and changelogs"), not a plea or a claim that it's safe.
- Ask for the narrowest change the task needs; when the agent requests the widest option, the "Widens access" tag and the impact line have to make that plain.

## Accessibility
- The card is an `alertdialog` labelled by its title; the changes are a real table with row headers, and both actions are real buttons reachable by keyboard in the order shown.
- Column headers (Setting, Now, After approval) are visually hidden but read out; the strike and arrow are decoration.
- The "Widens access" tag pairs its colour with an icon and text, so it doesn't depend on colour alone.
- The resolved row is a status region, so the outcome is announced when the card collapses.

## Related patterns
- **Tool Approval** — Use it instead for a single call with no lasting change; use this when the grant is saved and outlives the action.
- **Human in the Loop Question** — Use it before this one when the person has to pick how much access to grant.
- **Connector Panel** — Use it as well, so people can review and revoke standing access later.
- **Autonomy Mode Switcher** — Use it beside this; it sets how often the agent asks, not what it can reach.

## Implementation

Reference implementation (React, TypeScript, Tailwind v4, Motion, Radix). Keep every rule from the spec above; if the host project has its own design system, re-express the markup and motion in it rather than copying these classes.

npm dependencies: `lucide-react`, `motion`

Local imports to provide: `@/lib/utils` (`cn` is the usual `clsx` + `tailwind-merge` helper).

```tsx title="component.tsx"
"use client";

import * as React from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { ArrowRight, Check, LockKeyhole, TriangleAlert, X } from "lucide-react";

import { cn } from "@/lib/utils";

export type AccessRequestDecision = "approve" | "deny";

export interface AccessChange {
  id: string;
  /** What changes, e.g. "Network access". */
  label: string;
  /** The current value. Omit when the change adds something new. */
  from?: string;
  /** The value after approval. */
  to: string;
  /** Marks a change that widens what the agent can reach. */
  widens?: boolean;
}

export interface AccessRequestProps {
  /** The question, e.g. "Update environment?". */
  title: string;
  /** The thing whose access changes. */
  target: { name: string; scope?: string };
  /** Who is asking — shown as the author of the reason. */
  requester: string;
  /** The agent's own words for why it needs the change. */
  reason: string;
  /** The exact change, rendered by the product, not paraphrased by the agent. */
  changes: AccessChange[];
  /** Who and what the change applies to beyond this moment. */
  impact: string;
  approveLabel?: string;
  denyLabel?: string;
  onDecision?: (decision: AccessRequestDecision) => void;
  className?: string;
}

export function AccessRequest({
  title,
  target,
  requester,
  reason,
  changes,
  impact,
  approveLabel = "Approve",
  denyLabel = "Deny",
  onDecision,
  className,
}: AccessRequestProps) {
  const [decision, setDecision] = React.useState<AccessRequestDecision | null>(null);
  const reduceMotion = useReducedMotion();
  const titleId = React.useId();

  function decide(next: AccessRequestDecision) {
    setDecision(next);
    onDecision?.(next);
  }

  const transition = reduceMotion ? { duration: 0 } : { duration: 0.22, ease: [0.22, 1, 0.36, 1] as const };

  return (
    <div className={cn("w-full", className)}>
      <AnimatePresence mode="wait" initial={false}>
        {decision ? (
          <motion.div
            key="resolved"
            initial={{ opacity: 0, y: 4 }}
            animate={{ opacity: 1, y: 0 }}
            exit={{ opacity: 0 }}
            transition={transition}
            role="status"
            className="flex items-center gap-3 rounded-2xl bg-card px-4 py-3 border"
          >
            <span
              className={cn(
                "flex size-8 shrink-0 items-center justify-center rounded-full",
                decision === "deny"
                  ? "bg-muted text-muted-foreground"
                  : "bg-emerald-100 text-emerald-600 dark:bg-emerald-500/15 dark:text-emerald-400"
              )}
            >
              {decision === "deny" ? <X className="size-4" /> : <Check className="size-4" />}
            </span>
            <div className="min-w-0 flex-1">
              <p className="text-xs font-medium">
                {decision === "deny" ? "Request denied" : "Access updated"} · {target.name}
              </p>
              <p className="truncate text-[11px] text-muted-foreground">
                {decision === "deny"
                  ? `${requester} continues without it`
                  : changes.map((c) => `${c.label}: ${c.to}`).join(" · ")}
              </p>
            </div>
          </motion.div>
        ) : (
          <motion.section
            key="pending"
            role="alertdialog"
            aria-labelledby={titleId}
            initial={reduceMotion ? false : { opacity: 0, y: 8, scale: 0.98 }}
            animate={{ opacity: 1, y: 0, scale: 1 }}
            exit={{ opacity: 0, scale: 0.98 }}
            transition={transition}
            className="overflow-hidden rounded-2xl bg-card border"
          >
            <header className="flex items-center gap-3 px-5 pt-5">
              <span className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-foreground text-background">
                <LockKeyhole className="size-4.5" />
              </span>
              <div className="min-w-0 flex-1">
                <h3 id={titleId} className="text-sm font-semibold">
                  {title}
                </h3>
                <p className="flex items-center gap-1.5 text-xs text-muted-foreground">
                  <span className="truncate">{target.name}</span>
                  {target.scope && (
                    <span className="shrink-0 rounded-full bg-muted px-1.5 py-px text-[10px] font-medium">
                      {target.scope}
                    </span>
                  )}
                </p>
              </div>
            </header>

            <figure className="mx-5 mt-4 rounded-lg bg-muted px-3.5 py-2.5">
              <figcaption className="text-[11px] text-muted-foreground">{requester}&rsquo;s reason</figcaption>
              <blockquote className="mt-0.5 text-sm">{reason}</blockquote>
            </figure>

            <div className="mx-5 mt-4">
              <p className="text-xs font-medium text-muted-foreground">What changes</p>
              <table className="mt-1.5 w-full border-collapse text-sm">
                <thead className="sr-only">
                  <tr>
                    <th scope="col">Setting</th>
                    <th scope="col">Now</th>
                    <th scope="col">After approval</th>
                  </tr>
                </thead>
                <tbody>
                  {changes.map((change) => (
                    <tr
                      key={change.id}
                      // On phones each row stacks: the label above, then "from → to".
                      className="border-t first:border-t-0 max-sm:flex max-sm:flex-wrap max-sm:items-center max-sm:py-2"
                    >
                      <th scope="row" className="py-2 pr-4 text-left text-xs font-normal whitespace-nowrap text-muted-foreground max-sm:basis-full max-sm:pt-0 max-sm:pb-1">
                        {change.label}
                      </th>
                      <td className="py-2 pr-2 whitespace-nowrap text-muted-foreground max-sm:py-0">
                        {change.from ? (
                          <span className="line-through decoration-muted-foreground/50">{change.from}</span>
                        ) : (
                          <span aria-label="Not set">—</span>
                        )}
                      </td>
                      <td className="w-px py-2 pr-2 max-sm:py-0" aria-hidden>
                        <ArrowRight className="size-3.5 text-muted-foreground" />
                      </td>
                      <td className="py-2 max-sm:py-0">
                        <span className="inline-flex flex-wrap items-center gap-2">
                          <span className="font-medium">{change.to}</span>
                          {change.widens && (
                            <span className="inline-flex items-center gap-1 rounded-full bg-amber-100 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:bg-amber-500/15 dark:text-amber-400">
                              <TriangleAlert className="size-3" aria-hidden />
                              Widens access
                            </span>
                          )}
                        </span>
                      </td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>

            <footer className="mt-4 flex flex-col gap-3 border-t bg-muted/40 px-5 py-3 sm:flex-row sm:items-center sm:gap-4">
              <p className="min-w-0 flex-1 text-xs text-muted-foreground">{impact}</p>
              <div className="flex shrink-0 items-center justify-end gap-2">
                <button
                  type="button"
                  onClick={() => decide("deny")}
                  className="rounded-full px-3.5 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
                >
                  {denyLabel}
                </button>
                <button
                  type="button"
                  onClick={() => decide("approve")}
                  className="rounded-full bg-foreground px-4 py-1.5 text-xs font-medium text-background transition-colors hover:bg-foreground/90"
                >
                  {approveLabel}
                </button>
              </div>
            </footer>
          </motion.section>
        )}
      </AnimatePresence>
    </div>
  );
}
```
