Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
TypeScript
Run @claude mentions and dedupe in auto mode on a model that supports it
Claude7dbaea237fca
diff --git a/.github/scripts/__pycache__/check_workflow_hardening.cpython-311.pyc b/.github/scripts/__pycache__/check_workflow_hardening.cpython-311.pycnew file mode 100644index 00000000..2506b4ffBinary files /dev/null and b/.github/scripts/__pycache__/check_workflow_hardening.cpython-311.pyc differdiff --git a/.github/scripts/check_workflow_hardening.py b/.github/scripts/check_workflow_hardening.pyindex 9fcbc710..6c2a09ac 100755--- a/.github/scripts/check_workflow_hardening.py+++ b/.github/scripts/check_workflow_hardening.py@@ -6,6 +6,7 @@ Claude Code action, or when it or a local action it uses mentions ANTHROPIC_FEDEimport jsonimport pathlib+import reimport shleximport subprocessimport sys@@ -16,12 +17,18 @@ POLICY_PATH = pathlib.Path(".github/egress-firewall.yaml")SIGN_IN_MARKER = "anthropic_federation_rule_id"CLAUDE_ACTIONS = ("anthropics/claude-code-action", "anthropics/claude-code-base-action")HELP = 'See CLAUDE.md, "Security hardening for GitHub Actions".'+# Claude Code runs auto mode only on claude-opus-4-6 and newer models. On an older model it+# falls back to its default permission mode, with no safety review.+AUTO_MODE_MIN_VERSION = (4, 6)+# The version in a model name: claude-opus-4-6, claude-sonnet-4-5-20250929, claude-3-5-sonnet-latest.+MODEL_VERSION = re.compile(+ r"claude-(?:(?:opus|sonnet|haiku)-(\d+)(?:-(\d{1,2}))?"+ r"|(\d+)(?:-(\d{1,2}))?-(?:opus|sonnet|haiku))(?![\d.])"+)# Key: "<workflow file name>:<job id>". Value: why that job is exempt from the table's rule.EXEMPT_FROM_FIREWALL_RUNNER: dict[str, str] = {}-EXEMPT_FROM_AUTO_MODE: dict[str, str] = {- "claude.yml:claude": "answers @claude mentions, and for those the Claude Code action sets --permission-mode acceptEdits itself",-}+EXEMPT_FROM_AUTO_MODE: dict[str, str] = {}def stop(message: str):@@ -99,10 +106,12 @@ def job_calls_claude(job: dict) -> bool:return False-def permission_mode_problem(step: dict, exempt: bool) -> str | None:+def permission_mode_problem(step: dict, exempt: bool, inherited_env: dict) -> str | None:"""The message for a step whose permission mode is wrong, or None if it is right.- A step must set auto mode. A step of a job in EXEMPT_FROM_AUTO_MODE must set no mode at all.+ A step must set auto mode, on a model that supports it. A step of a job in+ EXEMPT_FROM_AUTO_MODE must set no mode at all. inherited_env is the workflow's and the+ job's 'env'."""inputs = step.get("with") or {}lines = str(inputs.get("claude_args", "")).splitlines()@@ -141,16 +150,19 @@ def permission_mode_problem(step: dict, exempt: bool) -> str | None:f"'claude_args' has '--permission-mode {mode}'. ""Change it to '--permission-mode auto'")- settings = [("the step's 'settings'", inputs.get("settings", ""))]- settings += [- ("'--settings' in 'claude_args'", args[index + 1])- for index, arg in enumerate(args)- if arg == "--settings" and index + 1 < len(args)+ env = {**inherited_env, **(step.get("env") or {})}+ models = [+ ("the step's 'model'", inputs.get("model", "")),+ ("ANTHROPIC_MODEL", env.get("ANTHROPIC_MODEL", "")),+ ]+ models += [+ (f"'{flag}' in 'claude_args'", value)+ for flag in ("--model", "--fallback-model")+ for value in flag_values(args, flag)]+ settings = [("the step's 'settings'", inputs.get("settings", ""))]settings += [- ("'--settings' in 'claude_args'", arg.split("=", 1)[1])- for arg in args- if arg.startswith("--settings=")+ ("'--settings' in 'claude_args'", value) for value in flag_values(args, "--settings")]for where, value in settings:text = settings_text(value)@@ -161,9 +173,42 @@ def permission_mode_problem(step: dict, exempt: bool) -> str | None:)if "defaultMode" in text:return f"remove 'defaultMode' from {where}: settings must not set a permission mode"+ try:+ parsed = json.loads(text) if text else {}+ except ValueError:+ parsed = {}+ if isinstance(parsed, dict) and "model" in parsed:+ models.append((f"'model' in {where}", parsed["model"]))+ if not exempt:+ for where, model in models:+ if predates_auto_mode(str(model or "")):+ return (+ f"{where} is '{model}', which Claude Code does not run in auto mode: it "+ "falls back to the default permission mode. Use claude-opus-4-6 or a newer model"+ )return None+def flag_values(args: list[str], flag: str) -> list[str]:+ """The values a flag in claude_args is given, as '--flag value' or '--flag=value'."""+ values = [+ args[index + 1] for index, arg in enumerate(args) if arg == flag and index + 1 < len(args)+ ]+ return values + [arg.split("=", 1)[1] for arg in args if arg.startswith(f"{flag}=")]+++def predates_auto_mode(model: str) -> bool:+ """Whether the model is older than AUTO_MODE_MIN_VERSION. A name with no version, such as+ 'opus' or 'default', stands for a current model, except 'haiku' (claude-haiku-4-5)."""+ if model.strip().lower() == "haiku":+ return True+ match = MODEL_VERSION.search(model.lower())+ if not match:+ return False+ major, minor = match.group(1, 2) if match.group(1) else match.group(3, 4)+ return (int(major), int(minor or 0)) < AUTO_MODE_MIN_VERSION++def settings_text(value) -> str | None:"""The settings JSON a 'settings' value stands for: the value itself, or the contents ofthe file it names when it is a path inside the repository. None when it names a path@@ -183,7 +228,7 @@ def settings_text(value) -> str | None:return text-def check_job(file_name: str, job_id: str, job: dict) -> list[str]:+def check_job(file_name: str, job_id: str, job: dict, workflow_env: dict) -> list[str]:key = f"{file_name}:{job_id}"where = f".github/workflows/{file_name}: job '{job_id}'"errors = []@@ -221,7 +266,8 @@ def check_job(file_name: str, job_id: str, job: dict) -> list[str]:for index, step in enumerate(steps_of(job), start=1):if not runs_claude_code_action(step):continue- problem = permission_mode_problem(step, exempt)+ inherited_env = {**workflow_env, **(job.get("env") or {})}+ problem = permission_mode_problem(step, exempt, inherited_env)if problem:step_label = f"step '{step['name']}'" if "name" in step else f"step {index}"errors.append(f"{where}, {step_label}: {problem}. {HELP}")@@ -275,7 +321,7 @@ def main() -> int:if not isinstance(job, dict) or not job_calls_claude(job):continuechecked += 1- errors.extend(check_job(path.name, job_id, job))+ errors.extend(check_job(path.name, job_id, job, workflow.get("env") or {}))if checked:errors.extend(check_policy())for error in errors:diff --git a/.github/workflows/claude-dedupe-issues.yml b/.github/workflows/claude-dedupe-issues.ymlindex 4a80dc61..dfdd1fdf 100644--- a/.github/workflows/claude-dedupe-issues.yml+++ b/.github/workflows/claude-dedupe-issues.yml@@ -45,7 +45,7 @@ jobs:# --permission-mode auto: a tool call that needs permission and is outside the allowed-tools# list in .claude/commands/dedupe.md runs only if Claude Code's safety review passes it.# Tools in --disallowedTools never run.- claude_args: '--model claude-sonnet-4-5-20250929 --permission-mode auto --disallowedTools "WebFetch,WebSearch,Write,Edit,MultiEdit,NotebookEdit"'+ claude_args: '--model claude-sonnet-4-6 --permission-mode auto --disallowedTools "WebFetch,WebSearch,Write,Edit,MultiEdit,NotebookEdit"'- name: Log duplicate comment event to Statsigif: always()diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.ymlindex 277ccdec..3e418ed1 100644--- a/.github/workflows/claude.yml+++ b/.github/workflows/claude.yml@@ -42,5 +42,8 @@ jobs:anthropic_organization_id: ${{ vars.ANTHROPIC_ORGANIZATION_ID }}anthropic_service_account_id: ${{ vars.ANTHROPIC_SERVICE_ACCOUNT_ID }}anthropic_workspace_id: ${{ vars.ANTHROPIC_WORKSPACE_ID }}- claude_args: "--model claude-sonnet-4-5-20250929"+ # --permission-mode auto: a tool call that needs permission and that the allowed tools+ # do not cover runs only if Claude Code's safety review passes it. The action sets+ # --permission-mode acceptEdits for @claude mentions, and this one, which comes after it, wins.+ claude_args: "--model claude-sonnet-4-6 --permission-mode auto"diff --git a/CLAUDE.md b/CLAUDE.mdindex cd7b8dc5..410ad0f6 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -19,12 +19,13 @@ Keep them when you add or edit a workflow.`claude_args` input) passes `--permission-mode auto` in `claude_args`. A toolcall that needs permission and that the allowed tools do not cover then runsonly if Claude Code's safety review passes it. Allow only the tools the job- needs, and keep any `--disallowedTools` list a step has.+ needs, and keep any `--disallowedTools` list a step has. Use `claude-opus-4-6`+ or a newer model: on an older one Claude Code falls back to its default+ permission mode.-Exception (listed with its reason in an exemption table in-`.github/scripts/check_workflow_hardening.py`): `claude.yml` answers `@claude`-mentions. For those the Claude Code action sets `--permission-mode acceptEdits`-itself. Do not add a `--permission-mode` there.+`claude.yml` answers `@claude` mentions. The Claude Code action sets+`--permission-mode acceptEdits` for those, and the `--permission-mode auto` in+the workflow's `claude_args`, which comes after it, replaces it.`.github/workflows/workflow-hardening.yml` fails when a job that runs the ClaudeCode action or mentions `ANTHROPIC_FEDERATION_RULE_ID` breaks protection 1 or 3,