AI News Daily한국어
← AI tool tips
Claude Code✓ Confirmed in official docsAdded Nov 25

How to auto-answer MCP server input requests with a Claude Code Elicitation hook

MCP servers can ask you for input mid-task (elicitation). Claude Code then shows a dialog in the terminal: in form mode you fill in fields the server defines, and in URL mode it asks whether to open a link in your browser. For a question you always answer the same way, an Elicitation hook can answer for you without the dialog.

  1. Create .claude/hooks/answer-project-key.sh in your project. This example fills in DOCS when the issue-tracker server asks for a form whose only field is project_key. For any other request it prints nothing, so the dialog appears as usual.
#!/bin/bash
input=$(cat)
fields=$(jq -c '.requested_schema.properties // {} | keys' <<<"$input")

if [ "$fields" = '["project_key"]' ]; then
  jq -n '{hookSpecificOutput: {hookEventName: "Elicitation", action: "accept", content: {project_key: "DOCS"}}}'
fi
  1. Make it executable.
chmod +x .claude/hooks/answer-project-key.sh
  1. Register it as an Elicitation hook in the project's .claude/settings.json. The matcher is the MCP server name.
{
  "hooks": {
    "Elicitation": [
      {
        "matcher": "issue-tracker",
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/answer-project-key.sh"
          }
        ]
      }
    ]
  }
}

A hook can return one of three action values: accept answers with the values in content (keys are the property names from the request's requested_schema), decline refuses, and cancel cancels. Printing nothing and exiting 0 leaves the request to the user's dialog. Exiting with code 2 or printing a top-level "decision": "block" also declines. When several hooks match the same request, a decline from one overrides an accept or cancel from another.

To always decline URL-mode requests, such as browser sign-in flows:

#!/bin/bash
if [ "$(jq -r '.mode')" = "url" ]; then
  exit 2
fi

Returning accept for a URL-mode request skips the dialog, so the URL never opens. Neither you nor the server sees why a hook declined, because Claude Code doesn't show the hook's stderr or reason. Auto-accepting a question that confirms an irreversible action removes that confirmation, so only auto-answer questions whose answer never changes, like a project key.

Get notified when a new tip lands

Tip alerts only go out in the app. Install it and turn notifications on.

Get the app

All tips →