The rule belongs in CLAUDE.md at the repo root, with the non-negotiable prohibition stated in the first screen of that file, before any other instruction. Root CLAUDE.md loads automatically at session start, travels with the repo, and is the single file Claude Code reads without being prompted. A rule written there is in context before the first command runs. A rule written in a chat message, a wiki page, or a teammate's memory is not. Placement is not the whole story: enforcement beats prose, and the strongest configuration pairs the written rule with a hook that blocks the command outright.
Mechanism: how Claude decides whether to push
Claude Code assembles a context window at the start of every session. Files named CLAUDE.md are read into that window automatically: the repo root file first, then files in subdirectories, then a user-level file in the home directory. The ordering matters because it shapes recency and specificity, but the practical point is simpler. A rule in root CLAUDE.md is present in every session, in every worktree, for every collaborator who clones the repo. A rule in .claude/CLAUDE.md also loads, but readers looking for policy rarely check there first.
The instruction itself works through the model's next-token prediction over the command it is about to emit. When the context contains an explicit prohibition, the probability mass on git push origin main and its variants drops. That is a soft constraint, not a hard one. Context windows get compacted during long sessions, and compaction can drop older instructions. A prohibition buried 800 lines into a file is measurably less reliable than one in the first 40 lines. The counterintuitive detail: stating the rule five times does not help and can hurt, because repeated boilerplate gets skimmed as noise. One unambiguous sentence in the right place outperforms five hedged ones.
Claude also inherits enforcement from outside the model. Pre-commit hooks, branch protection rules on the remote, and permission allowlists operate at the git layer and do not depend on the model remembering anything. A hook that exits nonzero when the target branch is main blocks the push even if the model forgot the rule. This is the mechanism that makes the difference between a policy and a guarantee.
Quantified context: what placement actually buys you
The numbers here are structural, not measured failure rates, because no authoritative body publishes model-compliance statistics for git prohibitions. What can be stated precisely is the load geometry. A typical root CLAUDE.md runs 100 to 400 lines. The first screen of a terminal or editor shows roughly 30 to 50 lines, so a rule placed in the first 40 lines is visible without scrolling in most setups. Instructions placed after line 400 sit in the lowest-attention region of a file that may itself be truncated.
Consider the failure surface. A push to main can be triggered by at least five distinct command forms: git push, git push origin main, git push origin HEAD:main, git push --force, and a push executed inside a script or make target. Each form is a separate token sequence the model can emit. A single prohibition sentence covers the intent; a hook covers the forms. Writing five variant prohibitions to cover five forms inflates the file and dilutes attention. Writing one sentence plus one hook covers both.
The practical threshold: if a rule is not in the first 50 lines of root CLAUDE.md, and no hook enforces it, treat it as advisory. If it is in the first 50 lines and a hook enforces it, treat it as binding. Anything between is a judgment call about how much risk the team tolerates.
Edge cases that defeat a well-written rule
Subdirectory files override or supplement root instructions, and a subdirectory CLAUDE.md that conflicts with the root can create ambiguity. Resolve conflicts explicitly in the root file rather than leaving the model to infer priority.
Memory files in the user home directory are personal and do not travel with the repo. A rule that lives only there protects one developer and no one else. Onboarding a new teammate silently removes the protection.
Worktrees and CI runners may not read the same configuration. A rule that holds in an interactive session can be bypassed in an automated job that runs git push from a script. The hook must live in the repo and be installed by a setup step, not by a personal memory.
Long sessions trigger compaction. An instruction given early and never reinforced can fall out of the working context. Anchor rules survive compaction better than prose paragraphs because they are short and repeated by the hook's error message.
Red flags that the rule is not actually enforced: The prohibition appears only in a chat message or a PR comment. Root CLAUDE.md exists but the rule is after line 200. No pre-push hook or branch protection is configured. The rule says "prefer not to" or "try to avoid" instead of "never." A subdirectory file grants an exception the root file does not mention. The remote allows direct pushes to main for admin accounts.
Misconceptions about instruction placement
The most common misconception is that a rule in a prompt is a rule in the system. A prompt is a suggestion to a probabilistic model. A hook is a constraint on the process. Teams that rely on prose alone eventually ship a direct commit to main and then blame the model.
The second misconception is that more files mean more safety. Splitting policy across root CLAUDE.md, a CONTRIBUTING.md, and a wiki page fragments attention and guarantees that at least one copy will go stale. One canonical file, one canonical sentence.
The third is that the rule should describe the workflow in full. A 600-word essay on branching strategy buries the prohibition. State the prohibition first, then explain the workflow after it.
The professional caveat: branch protection on the remote is the only enforcement that survives a misconfigured local environment. If your team has not enabled it, the local rule is doing work that infrastructure should be doing.
| Placement | Loads automatically | Travels with repo | Survives compaction | Enforceable by hook |
|---|---|---|---|---|
| Root CLAUDE.md, first 40 lines | Yes | Yes | Anchor text helps | Yes |
| Root CLAUDE.md, later sections | Yes | Yes | Weak | Yes |
| .claude/CLAUDE.md | Yes | Yes | Weak | Yes |
| User home memory file | Yes | No | Weak | No |
| Chat prompt only | No | No | No | No |
| Wiki or CONTRIBUTING.md | No | Yes | No | No |
| PR comment | No | No | No | No |
Practical actions: wiring the rule so it holds
Put the prohibition in the first screen of root CLAUDE.md as a single imperative sentence. Follow it with a one-line reason and nothing else before the rest of your project instructions. Use the word "never" rather than "avoid."
Install a pre-push hook that inspects the target ref and exits nonzero when it resolves to main. Commit the hook to the repo and document its installation in a setup script so every clone gets it. Enable branch protection on the remote for main with at least one required review and no direct pushes, including for administrators.
Add a permission rule in .claude/settings.json that denies git push commands targeting main. Keep the deny list narrow so legitimate pushes to feature branches are not blocked.
Review the root file quarterly. Delete stale rules and keep the prohibition within the first 50 lines. Confirm that no subdirectory file contradicts it.
Timeline for a rollout:
| Day | Action | Verification |
|---|---|---|
| 0 | Add prohibition to root CLAUDE.md, first 40 lines | File renders in first screen |
| 1 | Commit pre-push hook and setup script | Fresh clone installs hook |
| 2 | Enable remote branch protection for main | Direct push is rejected |
| 3 | Add deny rule in .claude/settings.json | Push to main blocked locally |
| 7 | Audit subdirectory files for conflicts | No file grants exception |
| 30 | Review hook logs for attempted pushes | Zero successful direct pushes |
| 90 | Quarterly review of root file | Prohibition still in first 50 lines |
The one bulleted list of concrete thresholds: keep the prohibition within the first 50 lines, keep the sentence under 25 words, keep the deny rule scoped to main only, keep branch protection on for all accounts, and review the file every 90 days.
Limitations and what this cannot guarantee
No placement makes a probabilistic model infallible. Root CLAUDE.md reduces the chance of a skipped rule; it does not eliminate it. The only configuration that makes skipping impossible is one where the push physically fails, which means remote branch protection plus a local hook. Everything else is risk reduction.
Context compaction during very long sessions can drop even well-placed instructions. The hook's error message re-injects the rule at the moment it matters, which is why the enforcement layer doubles as a reminder. Treat the written rule and the hook as a pair, not as substitutes.
Finally, this article describes configuration mechanics, not a legal or security control. It is general educational information, not a guarantee of compliance or a substitute for your organization's change-management policy. Teams with regulatory or audit obligations should consult their security and compliance leads before relying on any single control, and should verify that remote protections meet their own requirements.