paste into the Claude Code chat together with the guide fileBuild me a working Claude Code setup from the attached guide “Keep your Claude sharp”, then fine-tune it together with me.
There are no ready-made files: you create everything yourself from this prompt; the guide is a model of how it's built. Product, desk and server names and the numbers in the guide are the author's: you carry over the structure, not them. Go step by step, don't skip ahead.
## Rules for the whole job
- Don't overwrite existing files: only a diff and my “yes”. New files are fine.
- Before editing any settings.json (VS Code, ~/.claude, the project) — a backup next to it: settings.json.bak-YYYYMMDD-HHMM, then a diff, then my “yes”.
- Don't read or print secrets (~/.ssh, .env, keys, tokens, wallets, seed phrases), don't put them into memory, chat or git. If you see such a file — name only its path.
- Deploy nothing to servers, no restarts, git push — only with my “yes”. Don't touch anything I call off-limits.
- Keep a list of every file you created or changed — it's needed for rollback.
- Run every hook with test input and show the output. Not checked — say so.
- Talk to me in plain words: I may not know the terminal or git. If I have to do something — one step per line and what it does.
## Step 1. Read and look around (change nothing)
1. Read the whole guide.
2. Project: CLAUDE.md or .claude/CLAUDE.md, .claude/agents/, .claude/settings*.json, STATE.md, test and build commands (package.json, Makefile, pyproject, etc.).
3. ~/.claude: CLAUDE.md, settings.json, agents/, this project's auto-memory folder (~/.claude/projects/‹project path, slashes replaced with hyphens›/memory/).
4. Tools: versions of python3, node, bash, git; is gh installed and logged in (gh auth status). Is the folder already a git repository? Is there a remote?
5. Files that look like secrets (.env*, *.key, *.pem, id_rsa*, id_ed25519*, *keypair*.json, wallet*, seed*): only a list of paths, don't open them.
6. Briefly show what already exists and what will conflict.
## Step 2. Questions (in one message, numbered)
1. What are you building and how do you make money; the main goal, ideally as one number.
2. Which areas do you run, by importance. They'll become desk sessions; where is each one's folder.
3. Stack: languages, frameworks, services. Is there a server where prod lives, and how do you deploy now.
4. What is irreversible and done only with your “yes” (money, wallets, broadcasts, data deletion, other people's services).
5. Subscription and models: which is the main session, which are subagents, which model is the cheapest; context window 200k or 1M.
6. Which language should I talk to you in, and text rules: tone, banned words and letters.
7. How to check each project: a test or build command; if there isn't one — what counts as “works”.
8. What must never be touched: folders, services, projects.
9. GitHub: do you have an account; what to name the private repository; push after every task on my own or only on your word.
Don't guess. No answer — leave a ‹answer› placeholder and carry it into the report.
## Step 3. Plan — wait for “yes”
Show a list grouped by the sections of step 4: files to create, edits to existing ones as a diff, settings blocks, context thresholds, models and agent caps, the first desk and its entry phrase, what goes into git and what into .gitignore. You don't go further without my “yes”.
## Step 4. Build — in the order of the guide's sections
### 4.1 Workplace
- We work only in VS Code with the Claude Code extension, in the open project folder. The Claude app is for the subscription, not for work.
- VS Code user settings.json: "claudeCode.preferredLocation": "panel", "claudeCode.hideOnboarding": true.
- ~/.claude/settings.json (keep my keys, extend arrays):
"language": ‹from answer 6›, "effortLevel": "high", "cleanupPeriodDays": 3650,
"autoContinueAtUsageLimit": true, "subagentPromptCacheTtl": "1h",
"env": {"CLAUDE_CODE_SUBAGENT_MODEL": "‹subagent model from answer 5›", "CTX_GUARD_SOFT": "…", "CTX_GUARD_HARD": "…"}.
1M window: thresholds 650000 and 700000 and "autoCompactWindow": 1000000 (auto-compaction is only a safety net at the wall).
200k window: 140000 and 170000, don't set autoCompactWindow.
A key that doesn't exist in my version of Claude Code — don't set it: say so and skip it.
- In the report, one line per key on why: effort high — one step higher is 2.5 times pricier with almost no quality gain; 3650 days — chat history won't disappear; subagent model — without it a subagent takes the master's expensive model.
- A desk = its own tab: the first phrase says which area it is, name the tab via /rename. Start with one or two desks, not all of them.
- Models: master (main session) — the top model, subagents — one step lower, mechanics and search — the cheapest.
### 4.2 Private GitHub — .gitignore before the first commit
1. Folder not in git — git init, branch main.
2. .gitignore first: .env, .env.*, *.key, *.pem, id_rsa*, id_ed25519*, *keypair*.json, wallet and seed phrase files, *.bak-*, node_modules/, .venv/, dist/, __pycache__/, large data and logs.
Check: git check-ignore -v .env fires; git status shows not a single file from the secrets list of step 1.
3. Memory and rules live outside the folder — a copy of them goes into the repository. Script .claude/hooks/sync-copy.sh: auto-memory folder → .claude/memory-copy/, ~/.claude/CLAUDE.md and ~/.claude/agents/ → .claude/global-copy/. Copy ~/.claude/settings.json only if it has no tokens in it; otherwise a copy without the env block.
No auto-memory — memory goes straight into the project's .claude/memory/ and a line @.claude/memory/MEMORY.md into CLAUDE.md.
4. First commit — after the self-check (step 5): sync-copy.sh, git add, then git diff --cached --name-only and compare against the secrets list. Found something — stop and tell me.
5. Private repository. gh installed and logged in: gh repo create ‹name› --private --source . --remote origin (without --push).
No gh or git — explain to me step by step: install git (Mac: xcode-select --install, Windows: git-scm.com); on github.com New repository → Private → no README; send you the URL. You add the remote.
The first git push -u origin main — only after my “yes”.
6. A “Versions and rollback” section in CLAUDE.md: after every finished task — sync-copy.sh and a one-line commit “what was done”; push — as in answer 9.
Rollback: git log --oneline → git revert ‹commit› (safe, history stays) or a single file: git restore --source ‹commit› ‹file›.
Explain it to me in words: “restored file X as it was in the commit from ‹date›”. git push --force and git reset --hard — only with my “yes”.
### 4.3 Project rules, desks and STATE
- The project's CLAUDE.md from the answers. Sections:
who and what — the product in one line, the target number, the entry phrase;
style — answer 6, direct and to the point, no pleasantries;
boundaries — product development is my zone, the agent is executor, reviewer and debugger, don't invent a backlog unasked; plan first, then work, after “yes” — a finished result with no interim reports; “done” only after a check (if there's prod — on the live URL from outside, without cookies); the irreversible from answer 4 — only with “yes”; the off-limits from answer 8; don't swap my task for your own, related stuff — as a list at the end of the report; money and trading rules (limits, stops, pause) are enforced by code with a test, not by the agent's memory;
check — a command for each project from answer 7, “done” only after it; no check — build it first, then the code;
diagnostics — one hypothesis at a time, out loud; at most three checks, then a report on what you ruled out, and a question; don't deploy during diagnostics; fix what broke;
always-on work — deadlines into the registry, not into text; memory holds only what can't be looked up again; STATE is short; a hard rule is a hook or a ban, not a line here;
versions and rollback (4.2) · subagents (4.5) · context (4.6) · Compact instructions (4.6).
- A desk = a session for one area from answer 2. Build the first one now. Its STATE.md (target under 25 KB, limit 60 KB):
# STATE ‹desk› — updated ‹YYYY-MM-DD HH:MM› UTC
## Live — what, when deployed, file and md5, where the backup is, how to roll back
## Open — the task, where we stopped, the next step as one action
## Waiting on me — as one list, with a recommendation; remove closed items so I'm not asked again
## Deadlines — not here, in the registry (4.8)
History — in docs/history/STATE-‹year-month›.md: move it, don't delete.
- The desk's entry prompt for the phrase “‹desk›, let's continue”: what to read and in what order (CLAUDE.md, STATE, HANDOFF).
- HANDOFF.md in the root — a log between desks, line format “- ‹date UTC› ‹from› → ‹to›: ‹what›”. Messages between sessions in batches, one for several topics; whatever can wait goes into HANDOFF. A desk writes its report on what's done as a line in its own STATE, not as a message.
### 4.4 Memory and index
- In the memory folder MEMORY.md is the index: one line = one topic with a link to the file. Header:
# Memory index. One line = one topic. Time in UTC.
# Only the first ~25 KB / 200 lines load, the tail is invisible: keep under 23 KB and 180 lines.
A section has grown — into a sub-index _index_‹topic›.md, one link stays in the index.
- Memory file:
---
name: ‹type›_‹short›
description: ‹one sentence on when this is needed: the agent sees only this in the index and decides from it whether to open the file›
metadata:
type: feedback | project | reference | user
---
**Rule:** what to do, in one sentence.
**Why:** the incident with a date. Without a reason, a month later the rule will be judged outdated.
**How to apply:** a check that can be done by hand.
(later) **‹date› — closed by code:** where it's enforced now and which test.
Create one such file from my answers as an example.
- Into memory — only what can't be looked up again. Whatever lives in a database, a file or on a server — a pointer and a command, not a copy of the numbers.
- My “don't do that again” → a memory file and an index line right away. Broken a second time → a hook, test or ban.
- Weekly review: orphans (files with no link from the index), outdated stuff, duplicates, contradictions with CLAUDE.md. Don't silently rewrite a contradicting file: put a note at the top “> **Update ‹date›:** ‹what's wrong and what the fix is›”, the fix after my “yes”.
### 4.5 Subagents
- Agents in .claude/agents/. Model set explicitly in the header (without it an agent inherits the master's expensive model), turn cap maxTurns:
executor — the subagent model; tools: Read, Grep, Glob, Bash, Edit, Write; maxTurns 150. Body:
You are the executor. Your inputs are only the BRIEF.md file (and CONTRACT.md), path given in the task.
1. Read the brief and the files it names; others only if you can't do without them, and say which.
2. The minimal change that fully solves the task: what already exists in the project → standard library → new code. No abstractions “for the future”.
3. Branching, money, parsers, security — at least one test or assert. Mark a deliberate simplification shortcut: ‹limitation›, ‹when to update›.
4. Run the check from the brief. Answer in up to 15 lines: files and md5, the check command and its output, what's unchecked and the risk.
Bans: ssh, scp, server restarts, edits outside the brief's paths, plus the bans from answers 6 and 8.
skeptic — the subagent model; tools: Read, Grep, Glob, Bash, no Edit or Write (it can't “tweak a bit” and sweep a problem under the rug); maxTurns 80. Reads the brief and the diff, runs the check, gives a score 1–10, flags only blockers; “no blockers” is a normal answer; 7 or higher — OK to deploy.
mechanic — the cheapest model; tests, md5, grep, copies; no decisions and no prod; maxTurns 60.
explore — the cheapest model; tools: Read, Grep, Glob; file search; maxTurns 40.
- Templates in .claude/templates/:
BRIEF.md: # ‹code› — ‹what to do in one line›; project root; contract — CONTRACT.md next to it; You edit ONLY: ‹files›; Don't touch: prod, server, Claude settings, secrets; Why (2–3 lines); What to read first (files and lines); What to do (numbered, every item checkable; tests for empty, zero, dependency failure; old tests green); Check: ‹command› → ‹what it prints›; Report up to 15 lines; don't deploy.
CONTRACT.md: # ‹Feature› — contract between subtasks; source of the decision and a data check of the idea (a number or “never happened”); constants (one name everywhere); fields and schema (name, type, meaning, what if there's no data); calculation rules and edge cases; files and events (who writes, who reads); the master's post-review decisions with a date.
- Subagent rules in CLAUDE.md:
the master (main session) does the breakdown, plan, report and deploy itself;
no more than 3 agents at once, inside a workflow too — in chunks of 3:
for (let i = 0; i < items.length; i += 3) out.push(...await parallel(items.slice(i, i + 3).map(x => () => agent(...))))
don't message an agent inside a workflow; inputs go as a file before launch;
small code up to ~150 lines the master writes itself, a subagent is for big code;
skeptic — only for money and numbers for users, everything else — /code-review on the diff;
the skeptic isn't a gate: show reversible things right away, irreversible ones wait for the verdict;
one review round, a second only if the score is 6 or lower; review fixes — by the same executor if it waited less than an hour, otherwise a fresh one with the brief and the diff;
search and mechanics — on the cheapest model; ssh and restarts are banned for subagents.
### 4.6 Context and /clear
- In CLAUDE.md:
don't switch models mid-session — each model has its own cache, a switch = rereading the whole context at full price;
limit ran out — wait for the reset, or /clear and a new session on a lower model;
soft threshold — between steps prepare a continuation prompt in STATE; hard — finish the step and advise me to /clear; after /clear — the desk's entry phrase;
read images in batches and once, large files and logs — in parts;
quality isn't enough — first a check, then effort up one step, then a higher model.
- At the end of CLAUDE.md a “# Compact instructions” section: on compaction keep the changed files with md5, what's deployed and what isn't, open decisions, check commands; drop log output, intermediate hypotheses, contents of files read.
- The context counter itself is the context-guard hook in 4.7.
### 4.7 Hooks and harness check
Hooks in .claude/hooks/, you write them yourself, python3 and bash with no dependencies. Input for all of them is JSON on stdin: session_id, transcript_path, hook_event_name (Stop also has stop_hook_active). The hook's own error — exit 0, don't break the turn.
a) session-start.sh (SessionStart). Read-only. Prints up to 40 lines to stdout — this goes into the model's context:
date in UTC; overdue items and the next 3 days from the deadline registry; the last 3 lines of HANDOFF.md; the “Waiting on me” block from STATE.md; how many files are uncommitted (git status --short | wc -l); one line of the harness check (“harness N of M” and the FAIL names); once a week — memory review candidates: files older than 21 days with no link from the index (week stamp — the file ~/.claude/.memory-review-stamp). Always exit 0.
b) context-guard.py (UserPromptSubmit and PostToolUse). Skips subagents: agent_id or agent_type is present, or the transcript name starts with agent-.
Reads the tail of the transcript (~2 MB, JSONL), takes the last type=assistant line without isSidechain that has message.usage.
Context = input_tokens + cache_read_input_tokens + cache_creation_input_tokens. Thresholds — env CTX_GUARD_SOFT and CTX_GUARD_HARD (4.1). Below soft — silent.
Soft: to the model “context ~Nk, between steps prepare a continuation prompt in STATE, keep working”. Hard: “finish the step, the prompt must be ready, advise /clear”. It cleans nothing itself — I decide.
Output — one JSON line: {"systemMessage": "‹line for me›", "hookSpecificOutput": {"hookEventName": "‹event›", "additionalContext": "‹text for the model›"}}.
On PostToolUse — hard only, and no more often than once per 25000 tokens (CTX_GUARD_STEP; state — a temp file with session_id in its name). exit 0.
c) stop-verify.py (Stop). Skips subagents. If stop_hook_active — don't hold a second time, exit 0.
Takes project files changed since the last stop (marker — a temp file with session_id; the first time — the last 15 minutes) and those mentioned in the tail of the transcript.
Checks: .py — python3 -m py_compile; .js .mjs .cjs — node --check; .sh — bash -n; .json — parse. Skips node_modules, .venv, .git, dist, __pycache__. Timeout per file 20 s.
Errors found — a list to stderr (file and the last line of the error, up to 8 of them) and exit 2: the turn won't close until it's fixed. Otherwise exit 0.
Full project tests — not here, but before deploy, with the single command from the “check” section.
d) health.py — the harness check, deterministic, no network. One line per item: OK or FAIL with a reason; at the end “N of M”; the --line flag — only the summary line; FAIL — exit 1. Items:
CLAUDE.md exists; memory index under 23 KB and 180 lines; every index link points to a file; memory files without a link — as a list; settings.json is valid JSON; every hook from settings exists and passes a syntax check; context-guard and stop-verify are connected; every agent has model and maxTurns, skeptic has no Edit or Write; STATE.md under 60 KB; deny contains bans on secrets; .gitignore covers .env and keys, git ls-files has no files from the secrets list; the deterministic cases of the mistake catalog (4.9) pass.
Run it after any edit to rules, memory, settings, hooks or agents.
e) Wiring in the project's .claude/settings.json (backup, diff, “yes”; keep my keys):
"hooks": SessionStart → bash "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh";
UserPromptSubmit and PostToolUse (matcher "*") → python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/context-guard.py";
Stop → python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/stop-verify.py", timeout 60.
"permissions.deny": Read(~/.ssh/**), Read(./.env), Read(./**/.env*), key and wallet files from step 1.
"permissions.ask": rm -rf, git push --force, git reset --hard, deploy commands, everything irreversible from answer 4 and every off-limits path from answer 8 — in the rule syntax of my Claude Code version.
This is exactly “a hard rule is a hook or a ban”: the agent can't do anything on the deny list, even if asked; an ask waits for my manual “yes” every time.
### 4.8 Deadline registry
- .claude/hooks/followups.py, stdlib only, file .claude/followups.json:
add YYYY-MM-DD "what" [--owner desk] [--ref file] → prints the id;
due [--days 3] → overdue (“OVERDUE N d”), today and upcoming, with the owner in brackets;
list → all open; done id → close with a date.
- A line in CLAUDE.md: “Deadlines go into the registry, not into text. Any future date (check, renew, key expires) — followups.py add; done — done ‹id›”.
- A line in session-start.sh: python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/followups.py" due --days 3 2>/dev/null || true
### 4.9 Mistake catalog
- .claude/evals/cases.json — an array of cases. One case:
{"id": "‹desk›-‹what broke›", "department": "‹desk›", "source": "‹memory file with the rule›.md",
"situation": "‹the task the way I phrase it›", "trap": "‹what went wrong, with the cost›",
"expected": "‹what the agent should do instead›",
"grader": {"type": "deterministic", "check": "‹a command that fails on a violation›"},
"severity": "users | money | time | data"}
If code can't catch it yet: "grader": {"type": "rubric", "check": ["‹question for the reviewer›?", "…"]}.
- Rule in CLAUDE.md: a new rule after a mistake = a new case right away, five lines of JSON. Over time turn question-based cases into commands.
- Now — one case from my answers (for example, about the irreversible from answer 4).
### 4.10 Server — plan only, install nothing
If answer 3 mentions a server — into the report and into the deadline registry for week 2–4:
- one deploy command: tests → lock “one deploy at a time” → a backup with as many copies as there are prod files, otherwise stop → upload under a temp name and syntax check → swap all files at once → restart → smoke test → outside check over https without cookies → a line in STATE (time, files, md5, backup path); failure after the swap — rollback from the backup with one command;
- one sender for service notifications: a log as JSON lines, a repeat pause per key of one day, a “handled” mark; the alert text names what broke, the cause and whose zone it is; new watchdogs start quiet;
- an on-call agent — only once there's an event log: an hourly timer; nothing new — no model call; something new — the cheapest model in single-command mode (claude -p) with a cap on turns and spend, read-only access to logs and statuses, permissions as separate --allowedTools arguments; it fixes nothing, writes the owner one line.
### 4.11 Deadlines
Every deadline I've mentioned — into the registry. Plus one in 7 days: “a week with the setup: review of rules and memory”.
## Step 5. Self-check (show me the output)
- Every hook with test input:
echo '{"session_id":"t","transcript_path":"/none","hook_event_name":"Stop"}' | python3 .claude/hooks/stop-verify.py; echo $?
stop-verify: a deliberately broken temp .py → exit 2, then delete it.
context-guard: a temp transcript with usage above the hard threshold → JSON with both fields; below soft → silence.
session-start: run → up to 40 lines, exit 0.
followups: add, due, done on a test entry, then remove it.
- python3 .claude/hooks/health.py — the full output. Goal — no FAIL; if one remains — what it is and how to close it.
- git: git check-ignore -v .env fires; git status is clean after the commit; git log -1 shows the first commit.
- Tell me to restart Claude Code so the hooks get picked up.
## Step 6. Commit and report
- First commit per 4.2. Push — only after my “yes”.
- What was created and what changed: the path and one line on what's inside. Where the settings backups are.
- Rollback: which files to delete, which settings.json backup to restore, which diffs to revert; the commit to go back to.
- The first desk's entry phrase and the ‹answer› placeholders that stayed empty.
- A 7-day tuning plan:
day 1 — one check command per project in CLAUDE.md;
days 2–3 — every “don't do that again” from me goes straight into a memory file, an index line and a catalog case;
days 4–5 — a second desk with its own STATE and entry phrase; the first big task — to a subagent, brief as a file;
day 7 — health.py, a review of memory and rules (orphans, outdated, duplicates, contradictions), a check that everything is committed and pushed.
Every mistake becomes a rule, a repeated one — a hook, test or ban.