Instructions for AI coding agents (Claude Code, GitHub Copilot). Project-specific rules take precedence over general ones.
- Reply in the language the user writes in. If unclear, use the Windows display language (
Get-UICulture). - Code, identifiers, code comments, commit messages and branch names are always in English.
- Before changing files, propose a short plan and wait for confirmation. Exceptions: read-only access, analysis, and temporary files outside the project.
- Ask when requirements are unclear instead of making assumptions. With several possible solutions, give a recommendation with reasons.
- Keep changes small and traceable. No unrequested refactoring of existing code. Report findings outside the task, do not fix them.
- Follow the existing style and conventions of the project.
- Never delete, overwrite, commit or push without explicit approval. An approval applies only to that action, not to later ones.
- After changes, summarize briefly: what changed, what was tested, what is open.
- Commit messages in imperative mood, subject line max. ~72 characters.
- No force push, no rewriting of already pushed history.
- No attribution to AI tools: no
Co-Authored-By: ...trailer in commit messages, no "Generated with ..." line in pull request descriptions.
- Keep the encoding and line endings (CRLF) of existing files.
- In PowerShell 5.1 always specify the encoding explicitly when writing files.
- Windows 11. Take the regional settings (decimal separator, date format) into account when parsing and formatting. For persistence and data exchange use locale-independent formats.
Principles of Clean Code / Clean Code Developers, as rules for everyday work:
- Single responsibility (SRP): each procedure/method does exactly one thing, each class/module has one reason to change. Split long procedures into named steps.
- Separation of concerns: keep logic, UI and data access apart. Event handlers contain no logic; they only call well-named procedures.
- Keep code testable: logic does not depend on UI or on concrete data access; dependencies are passed in.
- KISS: choose the simplest solution that works and can be read at once.
- YAGNI: build only what is needed now; no speculative options, parameters or layers.
- DRY: no duplicated logic - extract shared code instead of copying it. Do not abstract before the duplication is real.
- Principle of least astonishment: names, behavior and side effects match what a reader expects.
- Meaningful, intention-revealing names; no abbreviations that need explanation (established prefixes of the project's style guide are allowed).
- No magic numbers or strings: use named constants or enums.
- Comments explain why, not what. Remove commented-out and dead code in the parts you change; report it elsewhere.
- Tell, don't ask; avoid long call chains (law of Demeter).
- Errors: never swallow errors silently. Handle an error where it can be handled, otherwise pass it on.
- Tests: logic is covered by automated tests; refactor only with tests as safety net.
- Boy scout rule within the task: leave code you touch a little cleaner. Findings outside the task are reported, not fixed (no unrequested rewrites).
- Work in small, understandable steps.
- Treat every input as untrusted (user input, form fields, files, command-line arguments, database content, results of other systems). Validate type, length, range and format; prefer allow-lists over block-lists.
- Prevent injection: never concatenate unchecked values or identifiers into SQL, filter or expression strings, shell commands or file paths. Use parameter queries; where dynamic SQL is unavoidable, use the safe building blocks of the platform or project.
- No secrets in code, repository, logs or test data (passwords, tokens, connection strings with credentials). Keep them in
.env.localor the secret store of the environment; keep such files out of version control. - Error messages shown to users contain no internal details (SQL text, paths, stack information). Details go to the log.
- Least privilege: request only the permissions and access that are needed; do not widen them to make a problem disappear.
- Handle files and paths defensively: build paths from validated parts, check that the target is where you expect it, never delete or overwrite based on unchecked input.
- Do not invent your own cryptography, hashing or authentication; use proven platform or library functions.
- Use third-party and library code only from known sources; report outdated versions instead of updating them unasked.
- Do not execute strings as code (
Eval,Application.Runwith user input,Shell,Invoke-Expressionand similar) unless the content is fully under your control.
Option Compare TextandOption Explicitin every module, test classes included.Option Compare Textis set explicitly so that a changed database collation can never switch string comparison or sorting to binary or another order. Declare all variables with explicit types.- 64-bit: API declarations with
PtrSafe, handles/pointers asLongPtr. - Naming, layout and comments: see the VBA coding style. Structure (SRP, layers, event procedures without logic): see the VBA architecture rules.
Event procedures (
Form_Load,cmd..._Click,WithEventshandlers) only call well-named procedures (e.g.Form_Load->InitItemsForm,InitFilterManager). - Security basics (input validation, no injection, no secrets): see the secure coding rules. In Access in particular, do not pass unchecked values to
DoCmd.RunSQL,Eval,Application.Run,Shellor pass-through queries.
- Use
Me.for methods and properties of the form, controls included (Me.Requery,Me.Dirty,Me.txtCustomerNo). - Use
Me!only for fields of the record source (Access.AccessField):Me!<FieldName>, e.g.Me!CustomerID. TheMe.<FieldName>property is generated when the record source is set, but it can get lost on a reimport with the msaccess-vcs-addin or after other changes, which breaks compilation.Me!<FieldName>resolves the field at runtime (late binding).
Follow the project's own rule if there is one (e.g. a global handler such as vbWatchdog). Otherwise:
- No blanket error handling that shows the error in a
MsgBoxand then continues. - Add local error handling only where cleanup is needed on failure (open recordsets, transactions, object references):
save
Err.Number,Err.Source,Err.Description, clean up, roll back transactions, then re-raise withErr.Raiseusing the saved values. NoMsgBox, do not swallow the error. - Handle expected errors specifically and locally (e.g. error 2101 when saving is cancelled, checked against a named constant); pass all others on.
- Use DAO or ADODB. Close recordsets and objects and set them to
Nothing. - Prefer parameter queries /
QueryDefparameters over concatenated SQL. - Use dynamic SQL only when necessary and always protect it against SQL injection (never concatenate unchecked values or identifiers into SQL).
- Dates and numbers in SQL strings must be locale independent:
#yyyy-mm-dd#, decimal point. - Boolean values in SQL strings against ODBC-linked SQL Server tables: use
True/Falsein theWHEREclause, never-1/0; Access then converts them correctly to1/0for SQL Server. Where possible build the SQL with helper methods that already handle this (e.g. ACLibSqlTools, if the project uses ACLib). - Data in linked SQL Server tables/views may be read only in approved databases (see the SQL Server rules); local configuration tables are not affected.
.accdb/.mdbare binary: work only with exported text files.- Exported VBA files are usually ANSI (Windows-1252) or UTF-8 with BOM: keep the encoding (umlauts!).
- Never work with more than one Access instance on the same
.accdb/.mdbat the same time (MCP server, automation, or the user's own Access window). Before switching, release the current instance and verify that noMSACCESS.EXEstill holds the file open (.laccdb); ask the user to close Access if necessary. Exception: if the user has opened the file in Access, you may use exactly that running instance, but only after asking and with explicit approval (valid for the current session). Never open a further instance on that file (no tool that starts Access itself); if a tool cannot attach to the existing instance, do not use it. Never close the user's instance.
MS Access project (Microsoft 365, 64-bit). Check the project for whether front end and tables are in one file or split.
<Database>.accdb: binary, never edit directly, do not version.<Database>.accdb.src/: source export by the msaccess-vcs-addin. Work here.modules/(.bas,.cls),forms/,reports/,queries/(.sql+ metadata),tbldefs/.- The actual folder structure of the export takes precedence over this overview.
<Database>.accdb.src/AGENTS.mdandvcs-agent-docs/are generated by the add-in and overwritten on every export: read them (encoding, line endings,@Folderplacement, file types), but never edit them.
- Before editing: run Export Source Files in Access via the add-in so the source is current. If unsure, ask whether it was exported.
- Edit only the files in the source folder where possible; otherwise use the MCP server
access. - Back into the database: add-in Build From Source (or merge build).
- Then compile in Access (Debug -> Compile) and test.
- Automate Access only through the MCP servers below, not with your own COM scripts.
- Before driving Access through the MCP servers, scripts or UI Automation, read
C:\dev\AgentsConfig\docs\access-automation.md(experience and recipes; the rules here take precedence). Add new insights to it as they come up.
- Registered as MCP server in the project's
.mcp.jsonor in the user scope; target database viaACCESS_VCS_DATABASEin.env(personal overrides in.env.local). - Read-only tools (
vcs_export_database,vcs_export_object,vcs_list_objects,vcs_diff_database,vcs_execute_sql,vcs_check_vba_compiled,vcs_get_log) may be used without asking. - Writing tools (
vcs_import_object(s),vcs_rebuild_database,vcs_compile_vba,vcs_set_option) only after approval. - Typical flow: export -> edit source files ->
vcs_import_object->vcs_compile_vba-> checkvcs_get_log->vcs_export_object. - An approval for an import covers the compile, log check and export that follow in this flow; anything beyond it needs a new approval.
- If compilation fails, make no further changes: ask the user to run Debug -> Compile in the VBE and to report the affected line.
- Change add-in metadata/JSON files only when necessary and with a note.
McpAllowRunVBAstays off;vcs_call_vbaandvcs_run_vbaare not used.
- Registered as MCP server in the project's
.mcp.jsonor in the user scope; source: https://github.com/unmateria/MCP-Access, locally atC:\dev\tools\MCP-Access. - For creating and designing objects (forms, reports, controls), e.g.
access_build_form,access_set_multiple_controls. Do not write VBA code with it (access_set_code,access_vbe_*); code is edited in the.cls/.basfiles (see division of work). - Code execution (
MCP_ACCESS_ALLOW_CODE_EXEC) stays disabled.
- Imports and updates ACLib modules (see the ACLib rules, skill
/aclib-import). - It attaches to a running Access instance on the database, otherwise it starts its own hidden instance and closes it after the call. The single-instance rule applies: release the other servers first.
- After an import, export the imported modules with
vcs_export_objectbefore editing them in the source folder.
- Before every switch between the servers (
access,msaccess-vcs-mcp,aclib-import) runaccess_closeorvcs_end_session(single-instance rule). - Layout: structural changes (new forms, adding/removing controls) with the server
access; then immediatelyaccess_closeandvcs_export_object. Small property changes (caption, position, format) may be made directly in the.form/.reportfile; mention them in the summary. - Code: edit only in the
.cls/.basfiles, thenvcs_import_object->vcs_compile_vba-> check log ->vcs_export_object. - Never import code while a layout change in the database has not yet been exported (the import would overwrite the layout).
- Version the source folder; put
*.accdb,*.laccdband backups into.gitignore. Commit after each completed step, only with approval.
- ACLib provides reusable, unit-tested and widely used code modules for many areas (dynamic SQL, filters, string handling, ...). Prefer an ACLib module over newly generated code: it is verified and proven in use. Before writing your own helper code, check whether a module already provides the functionality.
- Find modules in the ACLib module catalog (
_codelib/catalog/catalog.md, in the local ACLib repository or at https://github.com/AccessCodeLib/AccessCodeLib). Never guess module names or paths; if no catalog is available, ask the user. - For dynamic SQL, use the ACLib data modules (e.g. SqlTools, FilterStringBuilder) to protect it against SQL injection instead of building SQL strings by hand.
- Import and update ACLib modules with the skill
/aclib-import(aclib-import MCP server): show the plan first, import only after approval, then compile. Do not copy module code manually. Without the skill or the MCP server, ask the user to import the module with the ACLib Import Wizard. - ACLib modules may be edited in the project when needed. Keep such changes small and tell the user about them: they have to be
sent back to the CodeLib (export with the ACLib Import Wizard into the CodeLib), otherwise they stay local and a later
import with
overwritereplaces them. Do not export into the CodeLib yourself. - Do not import test or example modules unless the user asks (tests need the AccUnit environment).
Applies to standard modules (.bas), class modules and code-behind (.cls), and form/report files
(.form/.report from the msaccess-vcs-addin, .frm/.rep from the ACLib Import Wizard).
- Access objects with a one-letter type prefix: tables
t...(tCustomers), formsf...(fCustomer). - Controls with a type prefix (
txt,lbl,chk,cmd, ...), e.g.txtCustomerNo,cmdSave. - VBA variables, constants, procedures and classes with meaningful names without type prefix (
ErrNumber,SaveRecord,CustomerRepository). - Standard modules (
.bas) with the prefixmod(modDaoTools,modProjectRules). Class modules get no prefix. Exceptions without prefix only where a module is used like a namespace (AppConfig.Value) or a special case such as_configapplies; decide per project in the context of its use and record it in the project facts. Often a better solution is a self-instancing class (VB_PredeclaredId = True, used asAppConfig.Value): it needs no prefix and its procedures cannot be called without the class name. Use its default instance only for stateless helpers, factories or read-only configuration; logic classes do not reach for it but receive the values they need (no hidden global state, see the architecture rules). Keep the existing names of imported third-party code (e.g. ACLib modules). - Procedures: verb + object (
LoadCustomer,CalculateTotal); functions that return a Boolean read as a question (IsValid,HasItems). - Interfaces start with
I(ICustomerRepository); implementing classes are named after what they do (CustomerRepository,CustomerRepositoryFake). - Test classes are named
<ClassUnderTest>Tests(see AccUnit rules). - Constants in
PascalCase(no all-caps, noc/kprefix); enum names singular, members prefixed with the enum name where this avoids clashes.
- Indent with 4 spaces (no tabs); keep the indentation style of an existing file.
- One statement per line; avoid line continuations unless they clearly help readability; lines at most ~100 characters.
- Declare variables close to their first use, one per line, always with an explicit type. No
Variantunless required. - Use
ByValfor parameters unless the procedure has to change the caller's value; declare scope (Public/Friend/Private) explicitly. - Module order:
Optionlines, constants and enums, private members, events, public properties, public procedures, private procedures. - Standard modules that must not be accessed from outside the project get
Option Private Module(afterOption Explicit). Use it for internal helpers, so that theirPublicprocedures stay out of other VBA projects, the macro list andApplication.Runcalls from outside. Do not set it on modules whose procedures are called from queries, form/report properties or macros: such calls may stop working, so check the callers first. Class modules have noOption Private Moduleeffect; limit what they expose withFriendandPrivatemembers. - Place objects in the
@Folderstructure used by the project (seevcs-agent-docs); do not invent a new structure.
- Comments explain why, not what. No commented-out code.
- A public procedure whose name and parameters do not explain it fully gets a short comment line above it.
- Keep the encoding and line endings of existing files (usually ANSI/Windows-1252 or UTF-8 with BOM, CRLF); take care with umlauts.
- Single responsibility is the main rule.
- A procedure does one thing; split long procedures into named steps, a reader should grasp it without scrolling.
- A class or module has one reason to change. When a class needs "and" to describe it, split it.
- Treat length as a warning signal, not as a hard limit: a procedure over ~30 lines or a class over ~300 lines is a reason to check for several responsibilities.
- Layers (dependencies point downwards only):
- UI: forms and reports. Event procedures contain no logic; they call well-named procedures that only read inputs, delegate and show results.
- Logic: classes and standard modules with the rules of the application. No reference to forms (
Forms!...,Me), noMsgBox, no direct database access (CurrentDb,DoCmd). - Data access: own classes or modules (repository style) that read and write data, built on DAO/ADODB or the ACLib data modules.
- Apply the layers to new code with real application logic; forms that only show and edit data need no extra layers (YAGNI).
- Testable by design: logic receives what it needs through parameters or properties (dependency injection), not by reaching for globals or the database.
Describe collaborators with an interface (
Implements) when a fake is useful in tests. Logic classes keep no hidden global state. - If the project uses AccUnit, new logic comes with tests (see the AccUnit rules).
- Put logic into classes or modules, not into form modules; a form module only wires the UI to the logic.
- Return results and raise errors; the UI layer decides how to show them.
- Reuse before writing new code: check the AccessCodeLib modules first, then existing project modules; write new code only if neither fits.
- Do not restructure existing code unasked. In code you touch for another reason, apply these rules to the new and changed parts; report further findings instead of fixing them.
- Access add-in "ACLib DBMS Connection Wizard": configures a DBMS connection and imports the ACLib DbConnection framework into the target database.
source\(msaccess-vcs-addin export) is the single source of truth; binary files (.accdb,.accda) are not edited as source and are not committed.- The add-in file is built from
source\with msaccess-vcs-build (GitHub action or localBuild.ps1); do not run a build without approval. doc\holds the interface documentation generated with Natural Docs (doc\GenerateDoc.cmd); do not edit generated output by hand..accdb/.accdafiles in the root (e.g.Test.accdb,TestAddIn.accda) are local test or build files.