Human-in-the-Loop
Design confirmation flows, approval gates, and escalation patterns.
What You’ll Learn
AI agents that act without oversight are dangerous. AI agents that ask permission on every step are annoying. The best human-in-the-loop designs sit in the middle — involving humans at the right moments with the right information.
By the end, you’ll understand:
- The spectrum of autonomy and where each mode fits
- How to design confirmation flows that feel natural
- Approval gates: checkpoints where the AI waits for a human decision
- Escalation patterns for when the AI gets stuck
- The trust gradient: starting restrictive, opening up over time
The Problem
Consider two extremes:
Extreme 1: Fully Manual
User: "Fix the bug"
AI: "I'd like to read auth.ts. May I?"
User: "Yes"
AI: "I see the bug. May I edit line 42?"
User: "Yes"
AI: "May I run the tests?"
User: "Yes"
→ Correct but exhausting. 10 minutes for a 30-second fix.
Extreme 2: Fully Autonomous
User: "Fix the bug"
AI: *reads 50 files, edits 12, runs deploy, pushes to prod*
User: "Wait, I didn't mean--"
→ Fast but terrifying. One wrong assumption and you're debugging the debugger.
The real answer is in between. But where? It depends on the action, the stakes, and the trust level.
How It Works
The Autonomy Spectrum
Claude Code expresses the spectrum as permission modes, listed here from most oversight to least:
| Mode | Start with | What runs without asking | Fits |
|---|---|---|---|
| Plan | claude --permission-mode plan | Reads and research; edits wait until you approve a plan | Unfamiliar code, risky changes |
| Manual | claude --permission-mode manual | Reads only; edits and most commands prompt | Sensitive work, reviewing every action |
| Accept edits | claude --permission-mode acceptEdits | Reads, file edits, and common filesystem commands | Iterating on code you review afterward |
| Auto | claude --permission-mode auto | Most actions, with a classifier reviewing them instead of you | Long tasks with fewer prompts |
| Bypass | claude --dangerously-skip-permissions | Everything | Isolated containers and VMs only |
In Claude Code 2.1.305, an interactive terminal or VS Code session with no configured mode starts in auto mode (or Manual when auto mode isn’t available to you), while claude -p runs start in Manual mode and deny anything that would prompt. Press Shift+Tab to cycle modes during a session. Manual mode’s config value is default; manual is accepted as its alias on the command line and in settings. For unattended scripts, dontAsk mode denies everything you haven’t pre-approved (Session 24).
When Humans Should Be Involved
Not every action carries the same risk. The key is matching oversight to consequences:
| Action Type | Reversible? | Risk Level | Approach |
|---|---|---|---|
| Read files | Yes | None | Auto-allow |
| Search codebase | Yes | None | Auto-allow |
| Edit local files | Yes (git, /rewind) | Low | Prompt or allow |
| Run tests | Yes | Low | Allow with an allow rule |
| Run arbitrary commands | Maybe | Medium | Prompt user |
| Delete files | Partially | Medium | Always prompt |
| Git push | No | High | Always prompt |
| Deploy to production | No | High | Always prompt + confirmation |
| Database mutations | No | Critical | Multi-step confirmation |
The principle: reversibility determines autonomy. If you can undo it with git checkout, auto-allow it. If it changes production state, a human must approve.
Confirmation Flows
Claude Code’s permission system is a confirmation flow. In Manual mode, a Bash command that needs approval looks like this (simplified):
┌──────────────────────────────────────────────┐
│ Bash command │
│ │
│ Build the production bundle │
│ npm run build │
│ This command requires approval │
│ │
│ Do you want to proceed? │
│ ❯ 1. Yes │
│ 2. Yes, and don't ask again for: │
│ npm run build * │
│ 3. No │
│ │
│ Esc to cancel · Tab to amend │
└──────────────────────────────────────────────┘
When auto mode is available, Bash prompts in Manual and acceptEdits modes also offer Yes, and switch to auto mode. Choosing “don’t ask again” for a Bash command saves an allow rule for that repository in .claude/settings.local.json; an approval for file edits lasts until the session ends. Press Tab on Yes or No to attach a note: a No with a reason tells Claude what to do instead and lets it keep working, while a bare No stops the turn.
A good confirmation prompt has three properties:
- Clear action — exactly what will happen
- Sufficient context — why the AI wants to do it
- Fast decision — the user can say yes or no without deep analysis
Approval Gates
An approval gate is a designed checkpoint where the AI pauses and presents its plan before continuing. Unlike permission prompts, which fire per tool call, approval gates are strategic pauses in the workflow.
┌──────────────────────────────────────────────┐
│ Approval Gate Pattern │
│ │
│ Phase 1: Research (autonomous) │
│ ├── Read files │
│ ├── Search codebase │
│ ├── Analyze dependencies │
│ │ │
│ ▼ │
│ ╔══════════════════════════════════════════╗ │
│ ║ GATE: Present findings + proposed plan ║ │
│ ║ "I found 3 issues. Here's my plan..." ║ │
│ ║ User reviews and approves/modifies ║ │
│ ╚══════════════════════════════════════════╝ │
│ │ │
│ ▼ │
│ Phase 2: Implementation (semi-autonomous) │
│ ├── Edit files (per CLAUDE.md rules) │
│ ├── Run tests │
│ │ │
│ ▼ │
│ ╔══════════════════════════════════════════╗ │
│ ║ GATE: Show results before deployment ║ │
│ ║ "All tests pass. Ready to push?" ║ │
│ ╚══════════════════════════════════════════╝ │
│ │ │
│ ▼ │
│ Phase 3: Deploy (human-controlled) │
│ └── Push only with explicit approval │
│ │
└──────────────────────────────────────────────┘
Plan mode is Claude Code’s built-in version of the first gate. Start with claude --permission-mode plan, press Shift+Tab, or prefix a single prompt with /plan: Claude researches and writes a plan without editing your source, then asks how to proceed --- Yes, and use auto mode, Yes, manually approve edits, or No, keep planning. Press Ctrl+G to edit the plan yourself before you approve it.
For gates later in a workflow, encode them in your CLAUDE.md:
## Workflow Rules
- Always present a plan before making changes to more than 3 files
- Never push to remote without explicit user confirmation
- After running tests, report results and wait for approval before proceeding
CLAUDE.md shapes what Claude tries, but it doesn’t enforce anything. For actions that must never happen without you, back the rule with a permission rule (see The Trust Gradient below).
Escalation Patterns
When the AI encounters ambiguity or failure, it should escalate rather than guess:
┌──────────────────────────────────────────────┐
│ Escalation Ladder │
│ │
│ Level 1: Self-resolve │
│ AI encounters error → reads error message │
│ → tries alternative approach → succeeds │
│ │
│ Level 2: Inform and continue │
│ AI hits a non-blocking issue → reports it │
│ → continues with main task │
│ │
│ Level 3: Ask for clarification │
│ AI faces ambiguous requirement │
│ → asks specific question → waits │
│ │
│ Level 4: Stop and report │
│ AI cannot proceed safely │
│ → explains situation → presents options │
│ → waits for human decision │
│ │
└──────────────────────────────────────────────┘
The AI decides which level to use based on two factors: confidence and consequence.
| Low Consequence | High Consequence | |
|---|---|---|
| High Confidence | Level 1: Self-resolve | Level 2: Inform and continue |
| Low Confidence | Level 3: Ask for clarification | Level 4: Stop and report |
Claude can escalate with structured, multiple-choice questions through its AskUserQuestion tool. Auto mode nudges Claude to keep working instead of stopping for clarifying questions, so when a decision must come back to you, say so in your prompt, CLAUDE.md, or skill.
The Trust Gradient
Trust builds over time. A well-designed system starts restrictive and opens up gradually:
Session 1: ████░░░░░░ Plan or Manual mode, approve each action
Session 5: ██████░░░░ Allow rules for common commands
Session 20: ████████░░ Most routine work runs without prompts
Session 50: ██████████ Team trusts the setup; ask rules guard the rest
Claude Code supports this through permission rules in .claude/settings.json:
{
"permissions": {
"allow": [
"Bash(npm run test *)",
"Bash(npm run lint *)"
],
"ask": [
"Bash(git push *)"
],
"deny": [
"Read(./.env)"
]
}
}
Each allow rule is a trust decision: “I’ve seen this action enough times to trust it.” Read-only commands such as git status and git diff already run without a prompt, so they need no rule. Claude Code evaluates deny, then ask, then allow, and an ask rule prompts in every mode, auto mode included --- that is how you keep a human gate on irreversible actions. Rules you approve with “don’t ask again” land in .claude/settings.local.json; promote the ones your team agrees on to .claude/settings.json. A Bash rule matches command text, not every way to invoke a program, so pair hard boundaries with sandboxing or hooks (Session 18).
Key Insight
The best human-in-the-loop design makes human involvement feel natural, not annoying. The goal is not to minimize human interaction — it is to maximize the value of each interaction.
Bad HITL asks: “May I read this file?” (obviously yes, always) Good HITL asks: “I found 3 approaches. Which do you prefer?” (genuine decision point)
The framework:
- Auto-allow actions that carry no risk and have obvious intent
- Gate at strategic decision points where human judgment adds value
- Escalate when the AI is uncertain, not when it is confident
- Never ask questions with obvious answers
This mirrors how you manage a junior developer. You don’t watch them type every character. You review their plan, check their PR, and answer questions when they’re stuck.
Hands-On Example
Here is a deployment workflow with approval gates encoded in CLAUDE.md:
## Deployment Workflow
When I ask you to deploy:
1. RESEARCH PHASE (autonomous)
- Check git status (any uncommitted changes?)
- Run the full test suite
- Check for dependency vulnerabilities
2. APPROVAL GATE 1: Pre-deploy report
- Show: test results, git status, any warnings
- Wait for my "proceed" before continuing
3. BUILD PHASE (autonomous)
- Run production build
- Verify build output
4. APPROVAL GATE 2: Final confirmation
- Show: build size, any build warnings
- Explicitly ask: "Ready to push to main?"
- Only proceed with explicit "yes"
5. DEPLOY (with confirmation)
- git push origin main
- Report deployment status
With the ask rule for Bash(git push *) from the previous section, gate 2 holds even if the session runs in auto mode: the push itself still needs your approval.
When the AI follows this workflow, the interaction looks like this:
User: "Deploy the latest changes"
AI: [reads files, runs tests, checks status -- all autonomous]
AI: "Pre-deploy report:
- Tests: 47/47 passing
- Git: 3 files changed, no uncommitted work
- Dependencies: no vulnerabilities
Ready to build?"
User: "Yes, go ahead"
AI: [runs build -- autonomous]
AI: "Build complete:
- Bundle size: 245KB (down from 260KB)
- No warnings
Ready to push to main?"
User: "Push it"
AI: [pushes to main]
AI: "Deployed. Cloudflare build started."
Two human touchpoints. Each one is meaningful. The user keeps control over irreversible actions without micromanaging reversible ones.
What Changed
| No HITL Design | With HITL Design |
|---|---|
| AI asks about everything or nothing | Strategic checkpoints at decision points |
| Users feel anxious or annoyed | Users feel informed and in control |
| Trust is binary (on/off) | Trust builds gradually via allow, ask, and deny rules |
| Failures are silent or catastrophic | Failures escalate at the right level |
| Every session feels the same | Autonomy grows with confidence |
Next Session
You now know how to design the boundary between human and AI. Session 23 dives into Custom Agents & Skills — how to build your own Markdown-based extensions that encode workflow knowledge, specialized behaviors, and team standards into reusable, shareable components.