Warns when a turn writes sensitive files nobody asked for (lockfiles, manifests, CI, .env, migrations, infra) or too many files at once.

Tells you when a turn reaches further than you asked: it writes a sensitive file your prompt never named, or changes too many files at once.
▲ touched pnpm-lock.yaml (lockfile), .env (env) without being asked · /jr-scope hides
One row on the left, only while there is something to act on.
At the end of each turn, the files Claude wrote (Write, Edit, NotebookEdit) are checked against the prompt that started the turn:
| Kind | Files |
|---|---|
| lockfile | package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lock, Cargo.lock, poetry.lock, uv.lock, Gemfile.lock, composer.lock, go.sum |
| manifest | package.json, Cargo.toml, pyproject.toml, requirements*.txt, Gemfile, go.mod, composer.json |
| CI | .github/workflows/*, .gitlab-ci.yml, .circleci/*, Jenkinsfile, azure-pipelines.yml |
| env | .env, .env.* |
| migration | anything under migrations/, migration/ or migrate/ |
| infra | *.tf, *.tfvars, terraform/, infra/, k8s/, helm/, Dockerfile, docker-compose*.yml |
A sensitive file is fine when the prompt names it (its file name or its path). The warning shows as a toast and stays above the prompt until the next turn.
/jr-scope hides or shows the band, in every session and across restarts; /jr-scope on and /jr-scope off set it./config)| Option | Default | |
|---|---|---|
| Too many files | 15 | Warn when one turn changes more files than this |
| Show the band | on | Keep the last warning above the prompt |
/plugin install jr-scope --marketplace jrlprost/claude-code-mods
Watches Write, Edit and NotebookEdit calls and reads the prompt of each turn. Never blocks a call. Runs nothing, sends nothing over the network. Remembers whether the band is hidden.
hooks/register.tsx 119 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import { judge, summary } from './scope'
5
6const warning = atom({ plugin: 'jr-scope', key: 'warning' } as const, null)
7const bandHidden = atom({ plugin: 'jr-scope', key: 'isBandHidden' } as const, false)
8const commands = { isRegistered: false }
9const band = { isLoaded: false }
10
11async function ensureCommand($: EngineInterface) {
12 if (commands.isRegistered) return
13 commands.isRegistered = true
14 await $.command.register({ name: 'jr-scope', description: 'Show or hide the scope warning band: /jr-scope toggles, /jr-scope on or off' })
15}
16
17/** True while the band is hidden: one choice for every session, read from the store once per load. */
18async function isBandHidden($: EngineInterface) {
19 if (!band.isLoaded) {
20 if ((await $.store.get('isBandHidden')) === true) await update($, bandHidden, () => true)
21 band.isLoaded = true
22 }
23 return read($, bandHidden)
24}
25
26// The main loop's current turn: its prompt and the files written so far.
27const turn = { prompt: '', files: new Set<string>() }
28
29const touchedPath = (tool: string, input: Record<string, unknown>) => {
30 if (tool === 'Write' || tool === 'Edit' || tool === 'MultiEdit') return typeof input.file_path === 'string' ? input.file_path : null
31 if (tool === 'NotebookEdit') return typeof input.notebook_path === 'string' ? input.notebook_path : null
32 return null
33}
34
35export const register: Register = (on, options) => {
36 const maxFiles = Number(options.maxFiles ?? 15)
37 const showBand = options.showBand !== false
38
39 // A /clear starts a new conversation with empty state and no session.start: load again once it has begun.
40 on('session.end', async ($, e, next) => {
41 const ended = await next(e)
42 if (e.reason === 'clear') {
43 band.isLoaded = false
44 $.clock.after(1000, () => {
45 void isBandHidden($)
46 })
47 }
48 return ended
49 })
50
51 on('session.start', async ($, e, next) => {
52 const started = await next(e)
53 await isBandHidden($)
54 await ensureCommand($)
55 return started
56 })
57
58 on('turn.start', async ($, e, next) => {
59 if (e.agentId === undefined) {
60 turn.prompt = e.text
61 turn.files = new Set()
62 await update($, warning, () => null)
63 }
64 return next(e)
65 })
66
67 on('tool.call', async ($, e, next) => {
68 const ran = await next(e)
69 const file = touchedPath(String(e.tool), e as unknown as Record<string, unknown>)
70 if (file && !ran.isError && ran.deny === undefined) turn.files.add(file)
71 return ran
72 }).catch(($, e, next) => next(e))
73
74 on('turn.complete', async ($, e, next) => {
75 const done = await next(e)
76 if (e.agentId !== undefined || turn.files.size === 0) return done
77 const root = await $.session.root()
78 const verdict = judge(turn.prompt, [...turn.files], root, maxFiles)
79 const text = summary(verdict, root)
80 if (text) {
81 $.ui.toast(`jr scope · ${text}`)
82 await update($, warning, () => text)
83 }
84 return done
85 })
86
87 on('command.run', { command: 'jr-scope' }, async ($, e) => {
88 const arg = e.args.trim().toLowerCase()
89 const hide = arg === 'off' || arg === 'hide' ? true : arg === 'on' || arg === 'show' ? false : arg === '' ? !(await isBandHidden($)) : null
90 if (hide === null) return { text: 'jr scope · usage: /jr-scope toggles the band, /jr-scope on or off' }
91 await $.store.set('isBandHidden', hide)
92 await update($, bandHidden, () => hide)
93 return { text: hide ? 'jr scope · hidden (/jr-scope to bring it back)' : 'jr scope · shown' }
94 })
95
96 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
97 const below = await next(e)
98 if (!commands.isRegistered) {
99 $.clock.after(0, () => {
100 void ensureCommand($)
101 })
102 }
103 if (await read($, bandHidden)) return below
104 const text = await read($, warning)
105 if (!showBand || !text || e.props.hasSurvey) return below
106 const { Box, Text } = $.ui.resolve(e)
107 return (
108 <Box flexDirection="column">
109 <Text wrap="truncate-end">
110 <Text color="#ff8c42">{'▲ '}</Text>
111 <Text>{text}</Text>
112 <Text dimColor>{' · /jr-scope hides'}</Text>
113 </Text>
114 {below}
115 </Box>
116 )
117 })
118}
119hooks/scope.ts 39 lines1/** What makes a file sensitive: changing it reaches beyond the code at hand. */
2export const SENSITIVE: { kind: string; test: RegExp }[] = [
3 { kind: 'lockfile', test: /(^|\/)(package-lock\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb?|Cargo\.lock|poetry\.lock|Gemfile\.lock|composer\.lock|go\.sum|uv\.lock)$/ },
4 { kind: 'manifest', test: /(^|\/)(package\.json|Cargo\.toml|pyproject\.toml|requirements[^/]*\.txt|Gemfile|go\.mod|composer\.json)$/ },
5 { kind: 'CI', test: /(^|\/)(\.github\/workflows\/[^/]+|\.gitlab-ci\.yml|\.circleci\/[^/]+|Jenkinsfile|azure-pipelines\.yml)$/ },
6 { kind: 'env', test: /(^|\/)\.env(\.[^/]*)?$/ },
7 { kind: 'migration', test: /(^|\/)(migrations?|migrate)\// },
8 { kind: 'infra', test: /(\.tf$|\.tfvars$|(^|\/)(terraform|infra|k8s|helm)\/|(^|\/)(Dockerfile|docker-compose[^/]*\.ya?ml)$)/ },
9]
10
11export const sensitiveKind = (file: string) => SENSITIVE.find(s => s.test.test(file))?.kind ?? null
12
13const baseName = (file: string) => file.split('/').pop() ?? file
14
15/** A file counts as asked for when the prompt names it (its name, or its path from the project root). */
16export const isNamedIn = (prompt: string, file: string, root: string) => {
17 const rel = file.startsWith(`${root}/`) ? file.slice(root.length + 1) : file
18 const p = prompt.toLowerCase()
19 return p.includes(baseName(file).toLowerCase()) || p.includes(rel.toLowerCase())
20}
21
22export type ScopeVerdict = { sensitive: { file: string; kind: string }[]; total: number; isTooMany: boolean }
23
24/** The turn's touched files judged against the prompt: sensitive files nobody asked for, and the count. */
25export const judge = (prompt: string, files: readonly string[], root: string, maxFiles: number): ScopeVerdict => {
26 const sensitive = files
27 .map(file => ({ file, kind: sensitiveKind(file) }))
28 .filter((f): f is { file: string; kind: string } => f.kind !== null && !isNamedIn(prompt, f.file, root))
29 return { sensitive, total: files.length, isTooMany: files.length > maxFiles }
30}
31
32export const summary = (v: ScopeVerdict, root: string) => {
33 const rel = (f: string) => (f.startsWith(`${root}/`) ? f.slice(root.length + 1) : f)
34 const parts: string[] = []
35 if (v.sensitive.length) parts.push(`touched ${v.sensitive.map(s => `${rel(s.file)} (${s.kind})`).join(', ')} without being asked`)
36 if (v.isTooMany) parts.push(`${v.total} files changed in one turn`)
37 return parts.join(' · ')
38}
39types/index.d.ts 9 lines1/** The last turn's scope warning, kept until the next turn starts. */
2export type JrScopeWarning = string
3
4declare module 'claude-code' {
5 interface PluginState {
6 'jr-scope': { warning: JrScopeWarning | null; isBandHidden: boolean }
7 }
8}
9