Claude settings generator

Build a project .claude/settings.json for Claude Code. Start from a template, tune the options, then commit the file so the rules travel with the repo. Defaults follow the Yeo Lab AI knowledge base and Anthropic's current guidance: let the model and auto mode handle routine work, and use deny rules, the sandbox and hooks for anything you can't take back.

Project type

Permissions

Claude can read these but not edit them, e.g. raw data.

Claude can't read or edit these. Class 3 data (PHI, identifiable genomic data) must not be in the repo at all.

Sandbox

Verification hooks

Runs on the edited file (passed as "$f"). A failure exits 2 so Claude sees it and fixes it.

If this fails, Claude is sent back to fix it instead of finishing.

Other

Advanced: extra rules and environment

Never put secrets here. This file is committed.

.claude/settings.json
{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "permissions": {
    "allow": [
      "Bash(pytest *)",
      "Bash(python -m pytest *)",
      "Bash(ruff check *)",
      "Bash(ruff format *)",
      "Bash(nbstripout *)"
    ],
    "ask": [
      "Bash(git push *)",
      "Bash(pip install *)",
      "Bash(pip3 install *)",
      "Bash(conda install *)",
      "Bash(mamba install *)",
      "Bash(uv add *)",
      "Bash(uv pip install *)",
      "Bash(npm install *)",
      "Bash(rm -rf *)",
      "Bash(curl *)",
      "Bash(wget *)",
      "Bash(scp *)",
      "Bash(rsync *)",
      "Bash(ssh *)",
      "Bash(gh pr merge *)",
      "Bash(sbatch *)",
      "mcp__*",
      "Bash(aws s3 cp *)",
      "Bash(aws s3 sync *)",
      "Bash(gsutil *)",
      "Bash(rclone *)"
    ],
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(**/*.pem)",
      "Read(**/auth.json)",
      "Read(**/credentials)",
      "Read(~/.ssh/**)",
      "Read(~/.aws/**)",
      "Read(~/.gnupg/**)",
      "Read(~/.config/ai-cli/**)",
      "Read(~/.config/gh/**)",
      "Bash(git push --force *)",
      "Bash(git push -f *)",
      "Bash(git push --force-with-lease *)",
      "Bash(git reset --hard *)",
      "Bash(git clean *)",
      "Bash(git branch -D *)",
      "Bash(git commit --no-verify *)",
      "Edit(./data/raw/**)",
      "Read(./data/private/**)",
      "Read(./data/collaborator/**)",
      "Edit(./data/private/**)",
      "Edit(./data/collaborator/**)"
    ],
    "disableBypassPermissionsMode": "disable"
  },
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false,
    "autoAllowBashIfSandboxed": true,
    "excludedCommands": [
      "git push *",
      "gh *"
    ],
    "filesystem": {
      "denyRead": [
        "./.env",
        "~/.ssh",
        "~/.aws",
        "~/.gnupg",
        "~/.config/ai-cli",
        "~/.config/gh",
        "./data/private",
        "./data/collaborator"
      ],
      "denyWrite": [
        "./data/raw"
      ]
    },
    "network": {
      "allowedDomains": [
        "pypi.org",
        "files.pythonhosted.org",
        "conda.anaconda.org",
        "repo.anaconda.com",
        "rest.ensembl.org",
        "eutils.ncbi.nlm.nih.gov",
        "www.ncbi.nlm.nih.gov",
        "rest.uniprot.org",
        "api.genome.ucsc.edu",
        "www.encodeproject.org"
      ]
    }
  },
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "f=$(python3 -c 'import json,sys; print(json.load(sys.stdin).get(\"tool_input\",{}).get(\"file_path\",\"\"))'); ( case \"$f\" in *.py|*.ipynb) ruff check --fix \"$f\" ;; esac ) 1>&2; rc=$?; [ $rc -eq 0 ] || [ $rc -eq 127 ] || exit 2",
            "timeout": 60
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "grep -q '\"stop_hook_active\": *true' && exit 0; cd \"$CLAUDE_PROJECT_DIR\" && ( pytest -q ) 1>&2 || exit 2",
            "timeout": 600
          }
        ]
      }
    ]
  },
  "attribution": {
    "commit": "",
    "pr": ""
  }
}
~/.claude/settings.json (merge in)
{
  "permissions": {
    "defaultMode": "auto"
  },
  "autoMode": {
    "environment": [
      "$defaults"
    ],
    "soft_deny": [
      "$defaults",
      "Never modify or delete raw data",
      "Never upload data, results or notebooks to an external service"
    ]
  }
}

Why each part is there

  • Tests, linters and dry runs are pre-approved so Claude can check its own work without waiting on you. anthropic
  • Secrets are denied: .env files, keys, cloud credentials and the lab's ~/.config/ai-cli. Deny rules are checked before auto mode, so they hold in every mode. ai-kb
  • git push asks first (lab rule for every project). Force-push, hard reset, clean and branch -D are denied because they can't be undone. ai-kb
  • Installs, deletes, network transfers, merges, cluster jobs, MCP tools and this project's deploy or release commands ask first (lab human-in-the-loop gates). ai-kb
  • Read-only: data/raw. Raw data is read-only in lab projects. ai-kb
  • No access: data/private, data/collaborator. Class 3 data (PHI, identifiable genomic data) must not be in a repo used with AI tools at all. ai-kb
  • Bash rules match command text, so `git -C . push` or `sh -c '...'` can slip past them. The sandbox and branch protection are the real boundary. anthropic
  • No starting mode is set, so each person's own setting applies (auto mode out of the box). The deny and ask rules here still apply in auto mode. Pick Manual to match the lab template. anthropic
  • Bypass-permissions mode is disabled for this project. generator
  • Shell commands and everything they start run in the OS sandbox: they can't read your keys or protected paths, can't write to read-only paths, and can only reach the listed domains. This stops a compromised dependency in a test run, which no permission rule can. anthropic
  • The sandbox fails closed: if it can't start, commands don't run unsandboxed. ai-kb
  • Sandboxed commands such as tests run without a prompt, as in the lab coding template. Specific ask rules (git push, installs) and deny rules still apply. ai-kb
  • git push and gh run outside the sandbox so they can reach GitHub; push still asks first. Don't add github.com to allowed domains: it can be used to send data out. generator
  • Each edited file is linted. Failures exit 2 so Claude sees them and fixes them (exit 1 is ignored). A missing linter (exit 127) is skipped. anthropic
  • Before Claude finishes, the checks run. If they fail, Claude is sent back to fix them. The stop_hook_active guard stops it looping forever on a check it can't fix. anthropic
  • No Claude co-author trailer: AI is never an author. Say AI was used in the commit or PR. ai-kb
  • Auto mode and its plain-English guidance only work from ~/.claude/settings.json, not a project file. That snippet applies to every project, so keep it general. "$defaults" keeps the built-in blocks such as force-push and data exfiltration. anthropic