<!-- skill: Claude Code | version: 1.0.0 | description: Init CLI projects, CLAUDE.md, MCP servers and guardrails | category: AI & Automation -->
## Instructions
- Init with claude CLI in repo root: claude init scaffolds CLAUDE.md, .claude/ settings, respects existing git remote.
- Write CLAUDE.md conventions: build/test/lint commands, code style, branch naming, never-paste secrets rule.
- Wire skills explicitly: /load python-automation for scripts, /load git-workflows for commits, list allowed skills only.
- Add MCP servers via .mcp.json: filesystem scoped to repo, github with read-only token, postgres with row limits.
- Create slash commands in .claude/commands/: review.md, ship.md, debug.md with $ARGUMENTS placeholders and steps.
- Set cost guardrails: max-turns 15, model sonnet for code + haiku for lint, daily spend alert via /cost watch.
- Require plan-then-act: claude plan > PLAN.md approval before edits on migrations, auth, or deletions.
- Enforce verification: npm test + tsc --noEmit + eslint must pass before any commit message is drafted.
- Scope file access: ignore node_modules/.env/dist in MCP filesystem, deny absolute paths outside repo root.
- Commit via CLI flow: /ship runs diff review, conventional message, push only on explicit yes confirmation.
- Log sessions: --verbose to ./logs/YYYY-MM-DD.md, keep prompt/turn counts for cost postmortems.
- Pin versions: .claude/settings.json pins CLI + MCP server versions, bump monthly after changelog read.
## Examples
- Example 1: New TS repo: claude init, CLAUDE.md with pnpm test, MCP filesystem+github, /review catches N+1.
- Example 2: Slash ship: /ship auth-refresh runs tests, drafts feat(auth): refresh rotation, waits for yes to push.
- Example 3: Cost save: default haiku for docs, sonnet only for src/, max-turns 10 cuts bill 40% same week.
- Example 4: Guardrail hit: delete-migration blocked pending PLAN.md approval, rewritten as additive migration.
## Workflows
- Workflow A — Init: 1. claude init 2. Edit CLAUDE.md 3. .mcp.json 4. /cost set 5. Test /review dry-run.
- Workflow B — Feature: 1. /plan prompt 2. Approve PLAN.md 3. Implement 4. Tests green 5. /ship commit.
- Workflow C — MCP add: 1. Pick server 2. Scope config 3. Token least-privilege 4. Connection test 5. Pin version.
- Workflow D — Audit: 1. /cost report 2. Logs review 3. Unused skill prune 4. Settings bump 5. Commit.
## Templates
- CLAUDE.md starter:
```md
# Project X — Claude rules
Build: pnpm build | Test: pnpm test | Lint: pnpm lint
Style: strict TS, no any, Conventional Commits.
Skills: git-workflows, typescript-codebase only.
Never: commit .env, push without yes, delete-migrate without PLAN.md.
Verify: tests + tsc --noEmit green before /ship.
```
- .mcp.json scoped:
```json
{"mcpServers": {"fs": {"command": "mcp-filesystem", "args": ["--root", "."], "deny": ["../*", ".env"]}, "gh": {"command": "mcp-github", "env": {"TOKEN": "${GH_RO}"}}}}
```
- Slash command .claude/commands/review.md: `Review $ARGUMENTS: 1. git diff 2. List N+1/secrets 3. Suggest patch 4. Score 1-5. Max 15 turns.`.
- Cost guard: `.claude/settings.json {"model": "sonnet", "lintModel": "haiku", "maxTurns": 15, "costAlertUSD": 5}`.
## Tools
- Claude Code CLI — init, plan, slash commands, --verbose logs and /cost tracking per repo.
- MCP filesystem server — scoped file reads/writes so agent cannot escape repo root.
- MCP github server — read-only PR/diff context with fine-grained token for reviews.
- MCP postgres/sqlite server — row-limited queries for schema-aware migrations and seed checks.
- GitHub gh CLI — paired with Claude for PR create, check status, merge queue after green tests.
- pnpm/npm scripts — canonical build/test/lint targets referenced by CLAUDE.md and CI.
## Advanced
- Chain commands: /plan then /implement PLAN.md then /review --strict keeps turns under 15 with audit trail.
- Model routing: haiku triage issues, sonnet implement, opus only for security review — set per command header.
- Sandbox exec: allow pnpm test only, deny curl/rm -rf via permissions list in settings.json.
- Cache context: pin CLAUDE.md under 2k tokens, move long guides to docs/ loaded on demand via @mention.
- Multi-repo: one .claude/ per repo, shared commands symlinked from ~/claude-commands with version tag.
- Trace spend: parse ./logs for tokens/turn, alert Slack when daily USD doubles 7-day average.
- Roll back agent edits: git stash push pre-run, diff review, drop stash only after tests pass.
- Lock MCP upgrades: renovate bot PRs for mcp-* packages, eval /review on fixture repo before merge.
## Documentation
- Claude Code docs — init, CLAUDE.md schema, slash commands, permissions and /cost.
- MCP spec — server config, filesystem scoping, auth env handling and transport options.
- MCP servers registry — vetted filesystem/github/postgres servers with version pins.
- Prompt-craft for agents — plan-then-act, small diffs, verification gates for coding agents.
- CLI changelog — model names, max-turns flags, breaking settings.json migrations.
