claude-code - 💡(How to fix) Fix [FEATURE] Add --no-hooks flag to claude -p (non-interactive mode without breaking OAuth/subscription auth) [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48840Fetched 2026-04-16 06:49:28
View on GitHub
Comments
2
Participants
3
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×3commented ×2

Error Message

"Job failed: $JOB_NAME — Error: $ERROR. Read logs, fix the code, open a PR."

Root Cause

The headless use case (`claude -p`) is increasingly used for:

  • Webhook-triggered autonomous agents (CI, monitoring, on-call)
  • Local automation scripts replacing cron jobs
  • Pipe-based scripting (`cat logs | claude -p "summarize"`)

In all these contexts, hooks are irrelevant or actively harmful (they add latency, side effects, and are designed for interactive sessions). But these users often have subscriptions — they should not be forced onto the per-token API key model just to avoid hooks.

Fix Action

Fix / Workaround

The workaround — creating a custom `settings.json` with `disableAllHooks: true` and passing `--settings ./no-hooks.json` — works but is awkward for scripted environments and requires managing an extra file per project.

RAW_BUFFERClick to expand / collapse

Problem

When running `claude -p` in headless/scripted mode, there is no clean way to disable hooks without also losing OAuth subscription auth.

The only current option to skip hooks is `--bare`, but `--bare` deliberately ignores OAuth tokens and requires `ANTHROPIC_API_KEY` — which means paying per-token even if you have a Pro/Max/Team subscription.

This creates a forced tradeoff:

GoalFlagSide effect
Disable hooks`--bare`❌ Breaks OAuth, requires API key
Keep OAuth subscription(no flag)❌ Hooks always run
Disable hooks + keep OAuthImpossible today

The workaround — creating a custom `settings.json` with `disableAllHooks: true` and passing `--settings ./no-hooks.json` — works but is awkward for scripted environments and requires managing an extra file per project.

Concrete use case

I run Claude as an autonomous agent triggered by Dagster pipeline failures on my local machine. The sensor posts to a local FastAPI webhook, which calls:

```bash claude -p
--model sonnet
--max-turns 15
--allowedTools "Read" "Edit" "Bash(git *)" "Bash(gh pr create *)"
"Job failed: $JOB_NAME — Error: $ERROR. Read logs, fix the code, open a PR." ```

I want this to:

  • ✅ Use my existing Max subscription (not burn API credits)
  • ✅ Skip all hooks (session-start hooks, stop hooks, etc. are irrelevant in automated context)
  • ✅ Be a one-liner, not require a settings file sidecar

Today this is impossible. `--bare` solves hooks but kills OAuth. `--settings` solves it but adds file management overhead.

Proposed solution

Add a `--no-hooks` flag that:

  • Skips all hook execution (PreToolUse, PostToolUse, Stop, etc.)
  • Does not affect the auth chain — OAuth subscription still works normally
  • Is composable with all existing `-p` flags

```bash

Desired behavior

claude -p --no-hooks --model sonnet --max-turns 10 "query"

→ runs with subscription auth, no hooks fired

```

Internally this is equivalent to injecting `{ "disableAllHooks": true }` into the effective settings without touching the auth stack — which `--bare` does too aggressively.

Why this matters

The headless use case (`claude -p`) is increasingly used for:

  • Webhook-triggered autonomous agents (CI, monitoring, on-call)
  • Local automation scripts replacing cron jobs
  • Pipe-based scripting (`cat logs | claude -p "summarize"`)

In all these contexts, hooks are irrelevant or actively harmful (they add latency, side effects, and are designed for interactive sessions). But these users often have subscriptions — they should not be forced onto the per-token API key model just to avoid hooks.

Alternatives considered

OptionWorks?Drawback
`--bare`Hooks disabled ✅OAuth broken ❌
`--settings ./no-hooks.json`Both work ✅Extra file to manage, not composable inline ❌
`ANTHROPIC_API_KEY` env varWorks ✅Pays per-token, bypasses subscription ❌
`--no-hooks` (proposed)Both work ✅

Related

  • The `disableAllHooks` setting already exists in `settings.json` — this flag would just expose it as a CLI argument, consistent with how `--tools ""` exposes tool restrictions inline.

extent analysis

TL;DR

The proposed solution is to add a --no-hooks flag to the claude -p command to skip all hook execution without affecting OAuth subscription authentication.

Guidance

  • The current workaround using --settings ./no-hooks.json works but is awkward for scripted environments and requires managing an extra file per project.
  • The proposed --no-hooks flag would solve this issue by allowing users to skip hooks without breaking OAuth authentication.
  • To verify the fix, test the claude -p command with the --no-hooks flag and ensure that hooks are skipped and OAuth subscription authentication works as expected.
  • Consider the tradeoffs between using the --bare flag, which disables hooks but breaks OAuth, and the proposed --no-hooks flag, which would allow users to skip hooks without affecting authentication.

Example

# Desired behavior
claude -p --no-hooks --model sonnet --max-turns 10 "query"
# → runs with subscription auth, no hooks fired

Notes

The proposed solution would provide a more convenient and composable way to skip hooks in headless/scripted mode, without forcing users to manage extra files or switch to the per-token API key model.

Recommendation

Apply the proposed workaround by adding a --no-hooks flag to the claude -p command, as it would provide a more convenient and composable way to skip hooks in headless/scripted mode without affecting OAuth subscription authentication.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [FEATURE] Add --no-hooks flag to claude -p (non-interactive mode without breaking OAuth/subscription auth) [2 comments, 3 participants]