◉CLAUDE LABJP
●CC 2.1.331 — 2.1.331 adds an API connectivity check to claude doctor and fixes MCP tool calls hanging for up to 30 minutes●SONNET 4.5 — Sonnet 4.5 retires from the Claude API on 11/30, 6 days left. Move to claude-sonnet-5-5●OFFICE — Users report the Microsoft 365 add-in disappearing seconds after install on macOS●NEW — New: Count how many input tokens one more tool costs with count_tokens●GEMINI 2.5 — Using Gemini 2.5 alongside Claude? From 12/1 requests reroute to newer models, billed at their rates. 7 days left●WORKBENCH — Trying the API in Workbench for the first time? Check the billing pages before you start●CC 2.1.331 — 2.1.331 adds an API connectivity check to claude doctor and fixes MCP tool calls hanging for up to 30 minutes●SONNET 4.5 — Sonnet 4.5 retires from the Claude API on 11/30, 6 days left. Move to claude-sonnet-5-5●OFFICE — Users report the Microsoft 365 add-in disappearing seconds after install on macOS●NEW — New: Count how many input tokens one more tool costs with count_tokens●GEMINI 2.5 — Using Gemini 2.5 alongside Claude? From 12/1 requests reroute to newer models, billed at their rates. 7 days left●WORKBENCH — Trying the API in Workbench for the first time? Check the billing pages before you start
Articles/Claude Code
⟐ Claude Code/2026-03-23Intermediate

Claude Code --bare Flag: Headless Automation and Scripted Execution

Learn how to use Claude Code's new --bare flag for fast, lightweight scripted automation. This guide covers CI/CD pipelines, batch processing, and safety best practices for headless Claude Code execution.

claude-code134automation110ci-cd8bare-flagheadless15scripting

What Is the Claude Code --bare Flag?

On March 20, 2026, Anthropic added the --bare flag to Claude Code — a new option designed for scripted, non-interactive execution. When combined with the -p (prompt) flag, --bare skips all unnecessary initialization overhead, giving you the fastest possible startup time for automated workflows.

If you're running Claude Code inside CI/CD pipelines, batch scripts, or cron jobs, --bare is exactly what you've been waiting for. It strips away hooks, LSP connections, plugin syncing, and skill directory scanning — leaving you with a lean, predictable execution environment.

Before --bare, running Claude Code with -p still triggered all of these background processes. For a single invocation that didn't matter much, but in batch scenarios where you might run Claude dozens of times in succession, the cumulative startup overhead added up. The --bare flag solves this problem cleanly.

Getting Started with --bare

Basic Syntax

The --bare flag must always be paired with -p (prompt mode):

# Basic usage
claude -p "Find bugs in this code" --bare
 
# Explicitly specifying your API key
ANTHROPIC_API_KEY=sk-ant-xxx claude -p "Generate unit tests for src/utils.ts" --bare
 
# Get structured JSON output
claude -p "Analyze the dependencies in package.json" --bare --output-format json

What --bare Skips

When you pass --bare, the following initialization steps are completely bypassed:

✗ Hooks (pre-tool-use / post-tool-use hooks)
✗ LSP (Language Server Protocol) connections
✗ Plugin synchronization
✗ Skill directory scanning
✗ OAuth / keychain authentication
✗ Auto-memory features

This results in significantly faster startup and a clean execution environment with no external dependencies.

Authentication Constraints

Since --bare disables OAuth and keychain auth, you're limited to two authentication methods:

# Option 1: Environment variable (recommended)
export ANTHROPIC_API_KEY="sk-ant-your-key-here"
claude -p "Analyze this code" --bare
 
# Option 2: API key helper via --settings
claude -p "Analyze this code" --bare \
  --settings '{"apiKeyHelper": "op read op://vault/anthropic/api-key"}'

Practical Example: Automated Code Review in GitHub Actions

One of the most compelling use cases for --bare is automated code review in CI/CD pipelines:

# .github/workflows/claude-review.yml
name: Claude Code Review
on:
  pull_request:
    types: [opened, synchronize]
 
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
 
      - name: Install Claude Code
        run: npm install -g @anthropic-ai/claude-code
 
      - name: Run Claude Review
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: |
          # Get the diff against the base branch
          DIFF=$(git diff origin/main...HEAD)
 
          # Fast review with --bare
          claude -p "Review the following code diff.
          Flag any bugs, security issues, or performance concerns.
 
          $DIFF" \
            --bare \
            --output-format json \
            --max-turns 3 \
            --max-budget-usd 0.50

Here's why this configuration works well:

  • --bare eliminates startup overhead in the ephemeral CI environment
  • --max-turns 3 caps reasoning loops to prevent runaway execution
  • --max-budget-usd 0.50 sets a hard cost ceiling per review
  • --output-format json makes the output easy to parse for downstream steps

Practical Example: Batch Test Generation

Here's a script that generates unit tests for any source file that doesn't already have them:

#!/bin/bash
# generate-tests.sh — Batch generate tests for uncovered files
 
set -euo pipefail
 
find src/ -name "*.ts" -not -name "*.test.ts" -not -name "*.d.ts" | while read -r file; do
  test_file="${file%.ts}.test.ts"
 
  if [ ! -f "$test_file" ]; then
    echo "📝 Generating test: $file"
 
    claude -p "Generate unit tests for the following file.
    Use Jest and cover all major functions.
    Output only the test file contents.
 
    File: $file
    $(cat "$file")" \
      --bare \
      --max-turns 5 \
      --output-format text > "$test_file"
 
    echo "✅ Done: $test_file"
  fi
done
 
echo "🎉 Batch test generation complete"

The key advantage here is speed — without --bare, each iteration would spend time initializing hooks and scanning for plugins. Over dozens of files, the savings are significant.

Combining --bare with the --channels Permission Relay

Another feature that shipped on the same day (March 20) is the --channels permission relay, which forwards tool approval prompts to your phone via Telegram or Discord. When combined with --bare, you get a powerful pattern: automated execution with human oversight for critical operations.

# Forward approval prompts to your phone
claude -p "Run the production database migration" \
  --bare \
  --channels permission-relay \
  --max-turns 10
 
# What happens:
# 1. --bare ensures fast startup
# 2. When Claude attempts file changes or command execution,
#    an approval request is sent to Telegram/Discord
# 3. You approve or deny from your phone
# 4. Execution continues after approval

This strikes the right balance between automation efficiency and human-in-the-loop safety — especially for high-stakes operations.

Safety Best Practices for --bare Automation

When running Claude Code in automated workflows, safety guardrails are essential:

# Recommended: Always set these three safety flags together
claude -p "$PROMPT" \
  --bare \
  --max-turns 5 \        # Cap reasoning loops
  --max-budget-usd 1.00  # Set cost ceiling (USD)
 
# For stricter control
claude -p "$PROMPT" \
  --bare \
  --max-turns 3 \
  --max-budget-usd 0.50 \
  --output-format json \
  --allowedTools "Read,Grep,Glob"  # Restrict available tools

Safety Checklist for Production

Before deploying --bare in production, make sure you've addressed these items:

  1. Always set --max-turns — prevents infinite reasoning loops
  2. Always set --max-budget-usd — prevents unexpected cost spikes
  3. Use least-privilege API keys — create a dedicated key with minimal permissions
  4. Validate outputs — never execute Claude's output directly without validation
  5. Use branch protection — route all changes through pull requests

When to Use --bare vs. Standard -p Mode

The --bare flag is powerful, but it's not always the right choice:

ScenarioRecommended ModeWhy
CI/CD pipelines-p --bareFast startup, no external dependencies
Batch scripts-p --bareCumulative time savings over many runs
Cron jobs-p --bareMinimal environment, stable execution
Local development-p (without bare)Hooks and plugins add real value
MCP server workflows-p (without bare)LSP and plugins are needed
Interactive codingNormal modeFull UI is required

Wrapping Up

The --bare flag is a significant quality-of-life improvement for anyone running Claude Code in automated workflows. By stripping away unnecessary initialization, it delivers faster startup times and a more predictable execution environment — exactly what you need in CI/CD pipelines and batch scripts.

Start small: try adding --bare to a simple automation script, then gradually incorporate it into your GitHub Actions workflows and scheduled jobs. Combined with --max-turns, --max-budget-usd, and the new --channels permission relay, you have a robust toolkit for safe, efficient headless automation.

For more on Claude Code automation, check out the Batch Command Guide and the CI/CD Integration Guide.

Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

⟐ Claude Code2026-08-09
One Transient 401 Replaced My Long-Lived Token — Giving Credentials a Provenance Field
A shared credential file can lose its long-lived token to a single transient 401. I injected exactly one 401 into a 24-worker fleet, measured the blast radius, and compared a provenance guard against full isolation.
⟐ Claude Code2026-04-30
Composing Claude Code Skills — Building Automation a Single Skill Can't Reach
A practical guide to going beyond one-skill-at-a-time and composing multiple Claude Code Skills into real workflows. Pipeline, branching, and meta-skill patterns with full implementation examples and the failure modes you should design against.
⟐ Claude Code2026-04-08
iOS Test Automation with Claude Code — Where XCTest, Swift Testing, and XCUITest Each Belong
How I rebuilt an iOS test suite with Claude Code: where XCTest, Swift Testing, and XCUITest each belong, the pipefail trap that turns failed tests green in CI, and a hook that hands only test failures back to Claude.