---
name: claude-code-cli
description: Set up and run Claude Code CLI with --dangerously-skip-permissions mode. Requires a non-root user. Handles OAuth login, special user creation, and credential management.
compatibility: Created for Zo Computer
metadata:
  author: rob.zo.computer
---
# Claude Code CLI with Skip Permissions

> **⚠️ Deprecated** — Use [`claude-code-delegate`](../claude-code-delegate/SKILL.md) instead. It provides tmux-backed persistent sessions, prompt file management, completion detection, and a unified CLI. This skill is kept for reference only.

This skill helps you get Claude Code running in `--dangerously-skip-permissions` mode, which is needed for automated workflows and background tasks that shouldn't prompt for file/directory permissions.

## Why Non-Root?

Claude Code blocks `--dangerously-skip-permissions` when running as root/sudo for security reasons. This skill creates a dedicated user with your credentials copied over.

## Quick Start

If you're already authenticated as root, do steps 2-3 directly:
```bash
# 1. Initialize skill
skill="Skills/claude-code-cli"
source "$skill/scripts/init.sh"

# 2. Set up claude-code user (copies root credentials automatically)
"$skill/scripts/setup-user.sh"

# 3. Run Claude CLI from the new user
sudo -u claude-code claude --dangerously-skip-permissions -p "your prompt here"
```

## Step 1: OAuth Authentication (if needed)

Only do this if you don't already have valid credentials at `~/.claude/.credentials.json`.

### Running the OAuth flow

This uses `tmux` to manage the interactive `/login` TUI:

```bash
# Kill any existing session
tmux kill-session -t claude_auth 2>/dev/null || true

# Start Claude in a tmux session
tmux new-session -d -s claude_auth -x 120 -y 30 'claude'

# Wait for TUI to initialize
sleep 4

# Send /login command
tmux send-keys -t claude_auth '/login' Enter

# Wait for menu to appear
sleep 2

# Press Enter to select option 1 (Claude subscription)
tmux send-keys -t claude_auth Enter

# Wait for OAuth URL
sleep 4

# Capture and display the output
tmux capture-pane -t claude_auth -p -S -100
```

The output will contain a URL like:
```
https://claude.ai/oauth/authorize?code=true&client_id=...
```

**Open this URL in your browser** and authenticate with your Claude account.

### Submit the auth code

Once you're authenticated, you'll get a code (looks like `EVRvZM...#MZfo6x...`):

```bash
# Paste the code into the waiting session
tmux send-keys -t claude_auth 'YOUR_CODE_HERE' Enter

# Wait for processing
sleep 3

# Press Enter to confirm (may be needed)
tmux send-keys -t claude_auth Enter

# Wait and check result
sleep 3
tmux capture-pane -t claude_auth -p -S -50
```

Look for: `Logged in as <email>` and `Login successful`

### Clean up

```bash
# Press Enter to dismiss success message
tmux send-keys -t claude_auth Enter
sleep 1

# Kill the tmux session
tmux kill-session -t claude_auth

# Verify credentials were saved
ls -la ~/.claude/.credentials.json
```

## Step 2: Set Up the claude-code User

Create a dedicated non-root user and copy your Claude credentials:

```bash
bash Scripts/claude-code-cli/scripts/setup-user.sh
```

This script:
- Creates user `claude-code` with UID 1001
- Copies `~/.claude/.credentials.json` from root to the new user
- Copies `~/.claude/settings.json` for preference consistency
- Sets correct ownership (claude-code:claude-code)

### Manual setup (if needed)

```bash
# Create the user
useradd -m -s /bin/bash claude-code

# Create .claude directory
mkdir -p /home/claude-code/.claude

# Copy credentials from root (run as root)
cp ~/.claude/.credentials.json /home/claude-code/.claude/
cp ~/.claude/settings.json /home/claude-code/.claude/

# Set ownership
chown -R claude-code:claude-code /home/claude-code/.claude
```

## Step 3: Use Claude CLI in Skip Permissions Mode

Now you can run Claude Code without permission prompts:

```bash
# Basic one-off prompt
sudo -u claude-code claude --dangerously-skip-permissions -p "hello"

# Longer prompt
sudo -u claude-code claude --dangerously-skip-permissions -p "count to 5, then say goodbye"

# Code generation
sudo -u claude-code claude --dangerously-skip-permissions -p "write a python function that reverses a string"

# File analysis (needs actual file paths)
sudo -u claude-code claude --dangerously-skip-permissions -p "summarize the file at /home/workspace/notes.md"
```

## Common Flags

```bash
# Print mode (non-interactive, exits after response)
-p, --print

# Skip permissions (requires non-root)
--dangerously-skip-permissions

# Help
--help

# Version
--version
```

## Troubleshooting

### Credentials not found

```bash
# Check root credentials
cat ~/.claude/.credentials.json

# Check claude-code credentials
cat /home/claude-code/.claude/.credentials.json

# Verify ownership
ls -la /home/claude-code/.claude/
```

### OAuth login fails

- Ensure you opened the correct URL in the browser
- Make sure you're logged into Claude.ai in your browser
- Check the tmux capture: `tmux capture-pane -t claude_auth -p -S -50`
- Retry the entire flow, killing any existing sessions first

### Permission denied errors

```bash
# Verify claude-code user exists
id claude-code

# Verify ownership
ls -ld /home/claude-code/.claude
# Should show drwxr-xr-x claude-code claude-code

# Reset ownership if needed
chown -R claude-code:claude-code /home/claude-code/.claude
```

### Running as claude-code user directly

Instead of using `sudo -u`, you can also:

```bash
# Switch to the user
su - claude-code

# Then run directly
claude --dangerously-skip-permissions -p "hello"

# Exit back to root
exit
```

## Security Notes

- The `claude-code` user has standard user privileges (not root)
- Credentials contain access/refresh tokens - protect the `.claude` directory
- `setup-user.sh` copies credentials only from root → claude-code, not vice versa
- Consider setting a password for the `claude-code` user if needed for interactive use

## Files Modified/Created

- `/home/claude-code/.claude/` - Claude config directory
- `/home/claude-code/.claude/.credentials.json` - Copied OAuth credentials
- `/home/claude-code/.claude/settings.json` - Copied settings (optional)
- `/home/claude-code/` - User home directory