common-aaz-custom-code-generation
Skill4.6k starsChanged 3 months agoMITView on GitHub
Use after routing to AAZ subclass custom, or when adding/updating Azure CLI AAZ generated command customization. Generates custom classes that subclass AAZ generated commands while limiting uncertainty with required slots, templates, and validation gates.
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about Azure/azure-cli
- NixOS/nixpkgs“Build failure: azure-cli”GitHub · Aug 27, 2025 · 39 reactions
- hashicorp/terraform-provider-azuread“azuread_group_role_management_policy throws 403 permission scope not granted error”GitHub · Jun 11, 2024 · 28 reactions
- hashicorp/terraform-provider-azurerm“[preview] Support for mutual TLS and shared ssl policy in application_gateway”GitHub · Mar 29, 2021 · 25 reactions
- A Hacker News story“Azure CLI converts local accounts to MSFT online accounts on Win11”Hacker News · Jul 16, 2024 · 6 points
- A Hacker News story“Azure CLI takes ~700MB of disk space”Hacker News · Nov 30, 2023 · 3 points
The biggest 5 of 5 mentions linking to the repository that our crawl found. Each line is their own headline.
In this repository10 other files it gives its agents.
- common-custom-code-routerSkill
- common-legacy-non-sdk-custom-code-generationSkill
- common-legacy-sdk-backed-custom-code-generationSkill
- common-live-test-from-helpSkill
- openspec-apply-changeSkill
- openspec-archive-changeSkill
- openspec-exploreSkill
- openspec-proposeSkill
- openspec-sync-specsSkill
- openspec-update-changeSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
39 rules. About 0 are common, 26 are distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈26
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 9
Use this workflow to generate or update hand-written custom code for Azure CLI commands whose primary implementation is an AAZ generated …
- Distinctive: line 17
Use this skill for:
- Distinctive: line 26
Do not use this skill for:
- Very specific: line 59
Read the generated _create.py, _show.py, _list.py, _update.py, _delete.py, or _wait.py enough to confirm:
- Very specific: line 64
Search the target module for existing class XxxCustom(GeneratedClass) patterns.
- Very specific: line 65
Search commands.py or the module loader for existing command table replacement style.
- Distinctive: line 70
Before generating code, reduce uncertainty with these gates:
- Distinctive: line 72
If the generated command path is missing, do not create an AAZ subclass.
- Very specific: line 73
If the requested behavior requires a new REST operation not present in generated AAZ code, do not invent AAZHttpOperation by hand in custom …
- Distinctive: line 74
If the behavior can be expressed as schema customization, argument normalization/validation, or resource/operation guard checks, subclass …
- Distinctive: line 75
If multiple customization goals apply, keep one custom class and combine the smallest necessary hooks.
- Very specific: line 76
If a guard check requires raw HTTP or a secondary command invocation, keep it isolated in pre_operations or post_operations and validate …
- Distinctive: line 77
If the module already has a local helper for shared schema or validation, reuse it instead of duplicating logic.
- Distinctive: line 81
Add imports in the manual code file:
- Distinctive: line 85
Add helper functions only when shared by multiple custom classes or when they reduce repeated validation/schema code.
- Distinctive: line 86
Add a custom class that subclasses the generated base class.
- Very specific: line 89
Update parameters/help/tests only if the module's AAZ/manual help pattern requires it or the user requested examples/tests.
- Distinctive: line 90
Run the narrowest validation available: command load, help for the target command, a focused unit test, or a targeted scenario test.
- Distinctive: line 98
If no template matches the requested business logic, do not force the request into one of these examples.
- Distinctive: line 110
Use this when generated arguments need aliases, relaxed required flags, additional CLI-only arguments, or hidden generated arguments.
- Distinctive: line 138
Use this when user-friendly CLI arguments must be converted into the generated AAZ argument shape before the HTTP operation runs.
- Very specific: line 164
Use azure.mgmt.core.tools.is_valid_resource_id when accepting resource IDs.
- Very specific: line 168
Use this when create/update/delete must check resource existence, dependencies, or state before or after the generated operation.
- Distinctive: line 177
Call an argument normalization helper first only if the guard check depends on the normalized argument value.
- Very specific: line 179
When using send_raw_request, keep URL construction explicit and validate any resource URI before concatenating it.
- Distinctive: line 203
Prefer generated AAZ operations or existing SDK helpers over raw HTTP when a local pattern exists.
- Distinctive: line 207
Use this when the command needs both CLI-friendly arguments and generated argument normalization.
- Distinctive: line 222
Use this when replacing the generated AAZ command class with the custom subclass.
- Distinctive: line 231
If the module already uses a different manual registration style for AAZ custom classes, follow that local style exactly.
- Very specific: line 253
If blocked_on is non-empty, ask a focused question instead of generating code.
- Distinctive: line 255
After editing, report the files changed and the validation command/result.
- Distinctive: line 259
Prefer the narrowest validation available:
- Distinctive: line 266
If the generated command cannot be loaded because dependencies are unavailable in the local environment, state that clearly and provide the …
- Very specific: line 270
Do not edit generated AAZ files under aaz/latest for manual customization.
- Very specific: line 271
Do not copy generated operation classes into custom.py.
- Distinctive: line 272
Do not invent argument names.
- Very specific: line 273
Do not assume every AAZ custom needs resource_group and name aliases.
- Distinctive: line 274
Do not overwrite command table entries before confirming the full command key.
- Distinctive: line 275
Do not swallow non-404 HTTP errors in pre-operation checks.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Common AAZ Custom Code Generation
Use this workflow to generate or update hand-written custom code for Azure CLI commands whose primary implementation is an AAZ generated command.
This skill starts after the route is known or strongly suspected to be aaz-subclass-custom. If the route is unclear, use common-custom-code-router first.
Scope
This is module-general and applies across Azure CLI command modules under src/azure-cli/azure/cli/command_modules.
Use this skill for:
- subclassing generated AAZ command classes such as
Create,Show,List,Update,Delete, orWait - changing generated command argument UX through
_build_arguments_schema - normalizing or validating CLI arguments before generated operations run
- adding resource or operation guard checks around a generated command, such as existence checks or dependency checks
- shaping generated command output when local module patterns support it
- replacing a generated command table entry with a hand-written subclass
Do not use this skill for:
- legacy SDK-backed custom functions using
CliCommandType(..., client_factory=...) - Legacy Non-SDK Custom: local tool, subprocess, data-plane, raw HTTP, or diagnostic workflows whose public command is not an AAZ subclass
- editing generated files under
aaz/latestunless the user explicitly asks to modify generated output and accepts regeneration risk
Slots To Resolve
Resolve these slots before editing the related code. Prefer repository evidence over asking the user. These are not all user-provided inputs; some are derived or conditional.
module_name: "<module under command_modules>"
command_group: "<az command group, e.g. network vnet or aks safeguards>"
command_verb_or_action: "<CLI verb/action used to locate the generated file, e.g. create/show/wait or custom action>"
generated_module_import: "<relative import from .aaz.latest...>"
generated_base_class: "<Python class imported from the generated module and inherited by the custom class, e.g. Create/Show/Wait>"
custom_class_name: "<ModuleResourceVerbCustom>"
manual_code_file: "<custom.py or module-local manual file>"
command_table_key: "<full command name; required only when replacing a command_table entry; derive from @register_command(...) when possible>"
registration_file: "<commands.py or loader file; required only when adding/updating a command_table override>"
customization_goals: "<schema-extension | argument-normalization | argument-validation | resource-guard | operation-guard | output-shaping | wait-customization>"
validation_command: "<narrow command-load/help/test command or unknown>"command_verb_or_action and generated_base_class often correspond for standard commands, but they are not the same slot. The verb/action helps locate generated files such as _show.py or _wait.py; the base class is the concrete Python class the custom class will inherit.
If generated_module_import or generated_base_class cannot be resolved, stop and ask one focused question or ask for the generated command path. Do not guess an AAZ import path. If command_table_key cannot be resolved but no command table override is needed, set it to not-needed. If an override is needed and the key cannot be derived, ask one focused question.
Evidence To Gather
Gather only the evidence needed for the slots.
- Confirm the generated command exists under
src/azure-cli/azure/cli/command_modules/<module>/aaz/latest/.... - Read the generated
_create.py,_show.py,_list.py,_update.py,_delete.py, or_wait.pyenough to confirm:- command name in
_aaz_infoor examples - generated class name
- argument names in
_build_arguments_schema - operation hooks available in the class
- command name in
- Search the target module for existing
class XxxCustom(GeneratedClass)patterns. - Search
commands.pyor the module loader for existing command table replacement style. - Inspect the nearest sibling command with the same verb or resource family.
Uncertainty Gates
Before generating code, reduce uncertainty with these gates:
- If the generated command path is missing, do not create an AAZ subclass. Route back to SDK or non-SDK evaluation.
- If the requested behavior requires a new REST operation not present in generated AAZ code, do not invent
AAZHttpOperationby hand in custom code. - If the behavior can be expressed as schema customization, argument normalization/validation, or resource/operation guard checks, subclass the generated command instead of copying generated code.
- If multiple customization goals apply, keep one custom class and combine the smallest necessary hooks.
- If a guard check requires raw HTTP or a secondary command invocation, keep it isolated in
pre_operationsorpost_operationsand validate inputs before constructing URLs. - If the module already has a local helper for shared schema or validation, reuse it instead of duplicating logic.
Implementation Workflow
- Add imports in the manual code file:
- AAZ argument helpers from
azure.cli.core.aazonly when needed. - The generated base class from
.aaz.latest.... - Existing local validators/helpers when available.
- AAZ argument helpers from
- Add helper functions only when shared by multiple custom classes or when they reduce repeated validation/schema code.
- Add a custom class that subclasses the generated base class.
- Override only the hooks needed for the requested behavior.
- Register the custom class by replacing the generated command table entry in the module's command registration file.
- Update parameters/help/tests only if the module's AAZ/manual help pattern requires it or the user requested examples/tests.
- Run the narrowest validation available: command load, help for the target command, a focused unit test, or a targeted scenario test.
Hook Templates
Use only the templates needed by the requested behavior. Treat templates as patterns, not fixed implementations. Replace every placeholder and every example argument with names found in the generated AAZ schema or the target module's local conventions. Never leave angle-bracket placeholders such as <AAZArgType> or <generated_arg_name> in generated code.
Fallback: Unmatched Business Logic
If no template matches the requested business logic, do not force the request into one of these examples. First identify the smallest AAZ hook that can express the behavior:
_build_arguments_schemafor CLI argument surface changespre_operationsfor validation, normalization, or checks before generated operationspost_operationsfor checks or output changes after generated operations_outputonly when local module patterns support custom output shaping- another generated lifecycle hook only after reading the generated base class and confirming the hook exists
Then generate the smallest subclass that overrides only that hook. If the behavior requires replacing the generated REST operation itself, route back to evaluation instead of stretching these templates.
Template: Schema Extension
Use this when generated arguments need aliases, relaxed required flags, additional CLI-only arguments, or hidden generated arguments.
from azure.cli.core.aaz import <AAZArgType>
from .aaz.latest.<resource_path>._<verb> import <GeneratedBase>
def _add_<resource>_args(args_schema):
args_schema.<new_cli_arg_name> = <AAZArgType>(
options=["--<option-name>"],
required=<TrueOrFalse>,
help="<help text>",
)
args_schema.<generated_arg_name>._required = False # pylint: disable=protected-access
return args_schema
class <CustomClassName>(<GeneratedBase>):
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
args_schema = super()._build_arguments_schema(*args, **kwargs)
return _add_<resource>_args(args_schema)Replace placeholder argument names with real generated argument names. Do not add resource_group, name, resource_id, or any other example argument unless it matches the command's UX and generated schema.
Template: Argument Normalization Or Validation
Use this when user-friendly CLI arguments must be converted into the generated AAZ argument shape before the HTTP operation runs.
from azure.cli.core.aaz import has_value
from azure.cli.core.azclierror import ArgumentUsageError
def _validate_and_set_<resource>_argument(ctx):
args = ctx.args
has_generated_arg = has_value(args.<generated_arg_name>)
has_cli_arg_set = has_value(args.<cli_arg_name>)
if has_generated_arg == has_cli_arg_set:
raise ArgumentUsageError(
"Provide either '<generated option>' or '<friendly option set>', but not both."
)
if not has_generated_arg:
args.<generated_arg_name> = <normalize_cli_args_to_generated_value>(ctx, args)
class <CustomClassName>(<GeneratedBase>):
def pre_operations(self):
_validate_and_set_<resource>_argument(self.ctx)Use azure.mgmt.core.tools.is_valid_resource_id when accepting resource IDs. Normalize and validate resource IDs before using them in URLs. For non-resource-ID arguments, use the generated schema and neighboring command behavior to choose validation rules.
Template: Resource Or Operation Guard Check
Use this when create/update/delete must check resource existence, dependencies, or state before or after the generated operation.
class <CustomClassName>(<GeneratedBase>):
def pre_operations(self):
super().pre_operations()
_check_<condition>(self.ctx)Call an argument normalization helper first only if the guard check depends on the normalized argument value.
When using send_raw_request, keep URL construction explicit and validate any resource URI before concatenating it. Use raw HTTP only as a small guard around an AAZ subclass; if raw HTTP is the primary command implementation, route to legacy non-SDK custom instead.
def _check_<condition>(ctx):
from azure.cli.core.azclierror import HTTPError
from azure.cli.core.util import send_raw_request
from knack.util import CLIError
resource_uri = ctx.args.<resource_id_arg>.to_serialized_data()
if not resource_uri.startswith("/subscriptions/"):
raise CLIError(f"Invalid resource ID format: {resource_uri}")
url = f"https://management.azure.com{resource_uri}/providers/<Provider>/<childType>/default?api-version=<api-version>"
try:
response = send_raw_request(ctx.cli_ctx, "GET", url)
except HTTPError as ex:
if ex.response.status_code == 404:
return
raise
if response.status_code == 200:
raise CLIError("The resource already exists. Use update to modify it or delete it before creating a new one.")Prefer generated AAZ operations or existing SDK helpers over raw HTTP when a local pattern exists.
Template: Combined Schema And Pre-Operation Custom Class
Use this when the command needs both CLI-friendly arguments and generated argument normalization.
class <CustomClassName>(<GeneratedBase>):
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
args_schema = super()._build_arguments_schema(*args, **kwargs)
return _add_<resource>_args(args_schema)
def pre_operations(self):
_validate_and_set_<resource>_argument(self.ctx)Template: Command Table Override
Use this when replacing the generated AAZ command class with the custom subclass.
with self.command_group('<command_group>'):
from .custom import <CustomClassName>
self.command_table["<full command name>"] = <CustomClassName>(loader=self)If the module already uses a different manual registration style for AAZ custom classes, follow that local style exactly.
Output Expectations
Before editing, report:
route: aaz-subclass-custom
module_name: "..."
command_verb_or_action: "..."
generated_module_import: "..."
generated_base_class: "..."
custom_class_name: "..."
command_table_key: "... | not-needed"
registration_file: "... | not-needed"
customization_goals: "..."
planned_hooks:
- "_build_arguments_schema"
- "pre_operations"
blocked_on: []If blocked_on is non-empty, ask a focused question instead of generating code.
After editing, report the files changed and the validation command/result.
Validation
Prefer the narrowest validation available:
az <target command> -hor the repo's equivalent command-load/help test command.- A focused existing unit test for the target module.
- A command table import/load check for the target module.
git status --shortand a diff review only when executable validation is unavailable.
If the generated command cannot be loaded because dependencies are unavailable in the local environment, state that clearly and provide the attempted command.
Common Mistakes To Avoid
- Do not edit generated AAZ files under
aaz/latestfor manual customization. - Do not copy generated operation classes into
custom.py. - Do not invent argument names; read the generated argument schema first.
- Do not assume every AAZ custom needs
resource_groupandnamealiases. - Do not overwrite command table entries before confirming the full command key.
- Do not swallow non-404 HTTP errors in pre-operation checks.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

