Teams adopting Claude Code often hit the same ceiling: single prompts write code quickly, yet every fresh session forgets test commands, skips checks, or stalls in PR review loops. Written for solo builders and engineering leads, this guide lays out an end-to-end workflow from repo context to merged pull requests. One rule anchors the setup: keep repository knowledge in lean CLAUDE.md and path-scoped rules, and move every non-negotiable guardrail into Hooks, permissions, and /ship gates.

One-page workflow overview

Before editing config files, map how each layer is enforced and how changes roll back (if you still need initial installation steps, start with our Claude Code 30-minute walkthrough guide):

Stage Artifact / Command Enforcement Scope & Trigger Boundaries & Rollback
1. Context CLAUDE.md, .claude/rules/ Non-deterministic Root/parents at launch; paths: rules on demand Keep <200 lines/file; cannot block tools
2. Guardrails PreToolUse / PostToolUse / Stop Deterministic Tool calls, turn end, or config changes Exit 2 or deny blocks; Stop caps at 8
3. Local Review /code-review (/review) Read-only / --fix Any plan; background subagent on branch diff Reads CLAUDE.md only; bg --fix skips /rewind
4. PR Delivery /ship + /steward; Claude Ship Auto fix + policy /ship CLI v2.1.330+; Cloud Team/Enterprise PR Steward cannot merge; no ZDR/HIPAA/CMEK
5. Governance default/auto/plan, /rewind Hard rules + snapshots deny → ask → allow; 100 checkpoints (30d) Bash-only & symlinks skipped; keep Git

Step 1: Layer context with CLAUDE.md and .claude/rules/

Official docs distinguish non-deterministic instructions (prompts, CLAUDE.md, AGENTS.md) from deterministic controls (hooks, deny rules, managed settings). Because CLAUDE.md is advisory context, files load from broadest scope to most specific:

  • Managed policy: /Library/Application Support/ClaudeCode/CLAUDE.md (macOS), /etc/claude-code/CLAUDE.md (Linux/WSL), or C:\Program Files\ClaudeCode\CLAUDE.md (Windows).
  • User: ~/.claude/CLAUDE.md for personal defaults across projects.
  • Project: ./CLAUDE.md or ./.claude/CLAUDE.md (plus AGENTS.md), committed to Git; supports @path/to/file imports up to 4 hops.
  • Local: ./CLAUDE.local.md (gitignored) for local URLs or fixtures; across Git worktrees, import from ~/.claude/ instead.

Follow two rules: first, keep each CLAUDE.md under 200 lines with only facts Claude cannot infer from source files—exact test commands, legacy traps, and repeated corrections. Bootstrap with /init (set CLAUDE_CODE_NEW_INIT=1 for the guided flow), check loaded files with /context all, and audit stale rules via /doctor prompt-audit (v2.1.283+). Second, isolate folder rules in .claude/rules/*.md with YAML paths: so they load on demand (1,000-pattern / 4 MiB brace limit):

# Commands
- Unit tests: pytest -q tests/unit
- Typecheck: mypy src/
- Lint: ruff check .

# Conventions
- Sync OpenAPI schema and tests with API edits
- src/legacy/ is live; do not copy its patterns

# Gotchas
- Integration tests need DATABASE_URL (.env.example)
---
paths:
  - "src/api/**/*.{ts,tsx}"
---
# API Path Rules
- Validate every handler input via shared schema
- Update contract tests when response fields change
Four-tier CLAUDE.md load order, path-scoped .claude/rules/ loading, and deterministic vs non-deterministic split
CLAUDE.md precedence and on-demand .claude/rules/ scoping (FindGoodAI, from Claude Code docs)

Step 2: Enforce red lines with deterministic Hooks

Any rule you keep bolding in CLAUDE.md—like blocking generated-dir edits or requiring tests before finishing—belongs in Hooks. Defined in ~/.claude/settings.json, .claude/settings.json (shared), or .claude/settings.local.json, hooks follow three levels: Hook Event → Matcher Group → Handler (command, http, mcp_tool, prompt, or experimental agent).

Core lifecycle events include session bounds (SessionStart, SessionEnd), prompt/rule loading (UserPromptSubmit, InstructionsLoaded), tool execution (PreToolUse, PermissionRequest, PermissionDenied, PostToolUse, PostToolUseFailure, PostToolBatch), turn gates (Stop, StopFailure), and workspace shifts (ConfigChange, CwdChanged, FileChanged, PreCompact). Below are three high-signal guardrails:

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "if": "Bash(rm *)",
      "hooks": [{
        "type": "command",
        "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/guard.sh"
      }]
    }],
    "PostToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{
        "type": "command",
        "command": "npx prettier --write ."
      }]
    }],
    "Stop": [{
      "hooks": [{
        "type": "command",
        "command": "pytest -q || exit 2"
      }]
    }]
  }
}
#!/bin/bash
CMD=$(jq -r '.tool_input.command // ""')
if echo "$CMD" | grep -qE 'rm -rf|push --force'; then
  jq -n '{
    hookSpecificOutput: {
      hookEventName: "PreToolUse",
      permissionDecision: "deny",
      permissionDecisionReason: "Blocked risky command"
    }
  }'
  exit 0
fi
exit 0

Remember three mechanics: 1) exit 0 proceeds and applies stdout JSON, while exit 2 blocks (denying a PreToolUse call or continuing on Stop); 2) Stop caps at 8 consecutive blocks (CLAUDE_CODE_STOP_HOOK_BLOCK_CAP)—check stop_hook_active or use /goal to avoid loops; 3) PostToolUse on Edit|Write misses files rewritten by Bash, so use FileChanged or "*" for disk-wide triggers. For automated CI prompt regression tests, pair hooks with Promptfoo.

Claude Code hook resolution flow across PreToolUse deny, PostToolUse auto-check, and Stop verification gate
Deterministic hook enforcement across PreToolUse, PostToolUse, and Stop (FindGoodAI, from Claude Code Hooks docs)

Step 3: Pair local /code-review with GitHub Code Review

  1. Local /code-review (/review): Available on every plan; runs a background forked subagent over branch diffs or targets like main...feature and PR numbers. Supports --fix, --comment (GitHub or GitLab via glab), low–max effort, and ultra cloud sandbox runs. It reads CLAUDE.md, not REVIEW.md.
  2. Managed GitHub Code Review (GA): For Team and Enterprise GitHub repos (including GHES and GHE Cloud with data residency). Runs on Anthropic infrastructure via Find → Verify → Rank → Post at Quick, Standard (default), or Deep depth—read-only without running code, and never approves or blocks PRs alone. Configure team checks in REVIEW.md on the base/default branch.

For IDE-native vs CLI workflows, compare our Cursor review and AI Coding Agents & Dev Stack collection.

Step 4: Deliver PRs via /ship, PR Steward & Claude Approvals

Building on our Claude Ship launch report, separate the local CLI from the cloud org suite:

  • Local /ship & /steward (CLI v2.1.330+): Requires a local terminal clone (no cloud sessions; native Windows cannot start watches), gh 2.63+, and git 2.38+. On private GitHub repos without secret-like filenames (e.g. .env), /ship commits and pushes after an Esc to cancel window, opens the PR, runs /code-review, and starts a 7-day watch (/steward --tend) to fix CI and conflicts; run /steward on already-open PRs. Watches block gh/git merge, approve, auto-merge, force-push, and git stash/reset/checkout/add -A/commit -a, yet still run local tests under your credentials—use only on trusted repos and stop via /ship stop.
  • Cloud Claude Ship (Beta on Team/Enterprise GitHub): Unites GA Code Review with beta PR Steward and Claude Approvals. PR Steward (claude[bot]) pushes as Claude <noreply@anthropic.com> with revert hints, accepts @claude or @claude stop, and is blocked from approving or merging PRs. Both share .claude/skills/steward/SKILL.md:
---
name: steward
description: Repo rules for /ship and PR Steward
user-invocable: false
disable-model-invocation: true
---
- 仅修失败 CI、冲突与 Important 级审阅意见
- 架构调整建议留待 PR 作者本人处理
- 锁文件须由包管理器生成,禁止手改
# .claude/approvals.yml
version: 1
mode: observe
rules:
  - purpose: "须过 Code Review 且保留人工确认"
    paths: ["**"]
    verdict: { claude: comments, seats: 2 }
    advisory: [claude/code_review]

Watch one .claude/approvals.yml gotcha: adding a policy file disables automatic Code Reviews by default (even in mode: observe) unless a rule sets advisory: [claude/code_review].

Comparison of local /code-review and /ship watch loop vs cloud Claude Ship (Code Review, PR Steward, Claude Approvals) and compliance gates
Local /ship CLI flow vs cloud Claude Ship pipeline, safety gates, and exclusions (FindGoodAI, from official docs)

Step 5: Permissions, /rewind recovery & cost/compliance limits

  • Permission modes: Select default (Manual), acceptEdits, plan, auto (background classifier), dontAsk, or sandbox-only bypassPermissions. Rules evaluate deny → ask → allow and update live via /permissions.
  • /rewind (/undo / double Esc) limits: Tracks up to 100 prompt checkpoints (30-day default retention) to restore code, conversation, or summarize history. Three exclusions apply: 1) Bash-only edits to previously untouched files; 2) background subagent edits (including background /code-review --fix) on new files; 3) symlinks and hard links. Rely on Git for durable history, and run @claude stop before git revert on PR Steward commits.
  • Costs & compliance exclusions: Monitor spend and Prompt cache (main) hits via /usage (press f to apply fixes), audit friction with /insights, and cap -p runs with --max-budget-usd (enterprise average ~$13/active dev-day, $150–250/month). GitHub Code Review, PR Steward, and Claude Approvals (classifiers and triggered reviews even in observe mode) bill on org usage credits—set monthly caps in org settings (eligible Enterprise orgs can claim ≥$10,000 credits by Jan 15, 2027, valid 30 days). Crucially, orgs using ZDR, HIPAA, or CMEK cannot use cloud Claude Ship and should stick to local /code-review, Hooks, and self-hosted CI runners.

Frequently asked questions

Why do I still need Hooks if rules are in CLAUDE.md?

CLAUDE.md is non-deterministic context, so adherence is never 100% guaranteed. Hooks run deterministically in the Claude Code runtime at PreToolUse, PostToolUse, or Stop, enforcing exit code 2 or JSON deny blocks regardless of model choices.

Can /rewind undo all edits made by /code-review –fix?

Not always. Terminal /code-review defaults to a background subagent, so /rewind restores only files already edited in the main conversation. Other files modified by the review remain on disk and must be reverted with Git unless run in the foreground.

Can /ship or PR Steward merge pull requests on their own?

PR Steward is explicitly blocked from approving or merging PRs. Local /ship watches block gh and git merge, approve, auto-merge, and force-push commands during autonomous turns, though GitHub branch protection should still require human sign-off.

Why did automatic GitHub Code Reviews stop after adding .claude/approvals.yml?

Adding a Claude Approvals policy disables automatic Code Reviews for covered files by default, even in observe mode. Include claude/code_review under the advisory key of your rule to keep automatic reviews active.

Which workflow components work under ZDR, HIPAA, or CMEK?

CLAUDE.md hierarchies, .claude/rules/, Hooks, permissions, /rewind, local /code-review, and self-hosted CI runners all work locally or on approved providers. Cloud Claude Ship (Code Review, PR Steward, and Claude Approvals) excludes ZDR, HIPAA, and CMEK organizations.

Sources

SHARE THIS ARTICLE

Copy the link to save or share this article.

Related tools