Blog / claude code
Coding agent stuck on a password, 2FA or login prompt
Claude Code can't answer a sudo password, a 2FA code or a browser sign-in. What happens when it tries, and how to make it stop and ask you instead.
On this page
- What happens when the agent hits a prompt
- Fix 1: sign in before the agent needs it
- Fix 2: tell the agent what to do
- Fix 3: a hook that refuses the commands that need you
- Fix 4: know when it is waiting
- Where Joxo fits
- Frequently asked questions
- Can Claude Code enter my sudo password?
- Why does my agent say a login is still running?
- Can I type the 2FA code into Claude Code for the command?
- Does the hook work for Codex too?
- Try it with your team
Sooner or later your agent runs a command that wants you: sudo asks for your password, a deploy tool wants a 2FA code, gh auth login sends you to a browser. The agent can't type any of those. Depending on the command, it fails, carries on with a wrong result, or sits waiting until someone notices.
The fix is to sign in yourself before the agent needs it, and to make the agent stop and ask you when it hits one of these commands, instead of working around it. Everything below was tested on Claude Code 2.1.316 on macOS.
What happens when the agent hits a prompt#
Claude Code runs each shell command with no keyboard attached: input comes from /dev/null and there is no terminal to type into. That gives three different results.
The command fails at once. sudo is the common one:
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is requiredThat is the good case. The agent sees an error and usually tells you.
The command carries on without your answer. We wrote a small script that asks for a 6-digit code on the terminal, then prints signed in with and the code. Run by Claude Code, the prompt failed with /dev/tty: Device not configured, the script went on anyway, and printed signed in with followed by nothing. A tool written that way can report success when nothing happened. Claude caught it in our test, but only because the output was short.
Running the command yourself with ! at Claude Code's prompt doesn't help: it has no terminal either, and failed the same way.
The command waits forever. Browser and device sign-ins (gh auth login --web, cloud provider logins) print a URL and a code, then wait for you to finish in the browser. Nothing is wrong from the command's point of view, so it just waits. After the command time limit (two minutes by default) Claude Code moves it to the background, and the agent passes on the URL and code. In our test it said:
./wait.sh is still running. It didn't finish within the default 20-second limit, so the harness moved it to the background.
It's waiting for you to finish a device sign-in:
1. Open https://example.com/login/device in your browser.
2. Enter the one-time code ABCD-1234.When we finished the sign-in, the background command ended and Claude was told. That works if you are watching. If you are not, the session sits there with 1 shell in its footer and a sign-in code that expires.
Fix 1: sign in before the agent needs it#
Most tools store a login once and reuse it: gh auth login, npm login, cloud provider CLIs, docker login. Start a new terminal window, run the ones your project uses, and finish them there. The agent's commands then find the saved login and never prompt.
For sudo, the simplest rule is that the agent doesn't use it. Install system packages yourself, or let it run sudo -n, which fails straight away with sudo: a password is required instead of trying to prompt.
Fix 2: tell the agent what to do#
Add this to your project's CLAUDE.md (or AGENTS.md for Codex):
If a command asks for a password, a 2FA code or a browser sign-in, stop.
Tell me the exact command and why it needs me. Don't retry it, don't
look for another way around it, and don't run it in the background.A rule in CLAUDE.md is a request, not a guarantee. For commands that must never run, use a hook.
Fix 3: a hook that refuses the commands that need you#
A Claude Code PreToolUse hook runs before every shell command and can refuse it with a reason the agent reads. Save this as .claude/hooks/needs-you.sh in your project and make it executable (chmod +x):
#!/bin/sh
# Refuse commands that wait for a password, a code or a browser sign-in.
cmd=$(jq -r '.tool_input.command // empty')
case "$cmd" in
*"sudo -n "*) exit 0 ;;
*"sudo "*|*"gh auth login"*|*"npm login"*|*"aws sso login"*|*"gcloud auth login"*)
echo "This needs a password, a code or a browser sign-in. Stop and ask the user to run it in a separate terminal window, then continue." >&2
exit 2 ;;
esac
exit 0Then add it to .claude/settings.json:
{
"hooks": {
"PreToolUse": [
{ "matcher": "Bash",
"hooks": [ { "type": "command", "command": ".claude/hooks/needs-you.sh" } ] }
]
}
}We asked Claude to install a package with sudo port install tree. The hook refused it, Claude checked whether tree was already installed, and then said:
I did not install `tree`. The install is blocked on a password prompt that I can't answer from this session.with the command for us to run. gh auth login --web was refused the same way. Add the login commands your own tools use to the list. The script needs jq.
Fix 4: know when it is waiting#
The fixes above turn most waits into a question for you. A question is only useful if you see it. Claude Code can run a command when it is waiting for your answer, and you can send that to your phone: our post on getting notified when Claude Code needs you has the hook.
For a sign-in already waiting in the background, type /tasks in the session: it shows the command's output, sign-in code included, and x stops it.
Where Joxo fits#
With Joxo, the moment your agent stops to ask you something, your phone tells you, and you can answer in the Joxo app. Your teammates see that your session is waiting on you, not stuck. Setup is one line pasted into your agent.
Frequently asked questions#
Can Claude Code enter my sudo password?#
No. Its shell commands have no terminal, so sudo fails with "a terminal is required to read the password". Run the command yourself in a separate terminal window, or have the agent use sudo -n so it fails fast.
Why does my agent say a login is still running?#
Browser and device sign-ins wait for you to finish in the browser. After the command time limit, Claude Code moves the command to the background and keeps it running until you finish or stop it with /tasks.
Can I type the 2FA code into Claude Code for the command?#
Not into the running command: it can't read from Claude Code's prompt. Finish the sign-in in a separate terminal window, then tell the agent to carry on.
Does the hook work for Codex too?#
Codex has its own hooks, set up differently. The rule above works in Codex as it is when you put it in AGENTS.md.