| name | gw-config-management |
| description | Configure .gw/config.json for gw-tools repos โ auto-copy files, hooks, cleanup thresholds, update strategy, and the config migration system. Use when: setting up gw for a new project, adding or changing a config field, adding a hook, configuring auto-copy patterns, asking what fields gw config supports, running gw init, adding a migration, bumping configVersion, keeping schema.json in sync, or troubleshooting missing env files in worktrees.
|
| license | MIT |
| disable-model-invocation | true |
| metadata | {"author":"mthines","version":"4.0.0","workflow_type":"advisory"} |
gw Configuration Management
Config lives at .gw/config.json (committable) and .gw/config.local.json
(gitignored, personal overrides). All worktrees in a repo share the same config.
MANDATORY: Config-Change Rules
Non-negotiable in any gw-tools repo.
| Situation | Required action |
|---|
Adding or renaming a Config field in types.ts | Add a migration in config-migrations.ts, increment CURRENT_CONFIG_VERSION, update gw-config.schema.json, and update types.ts |
Removing a field from Config | Same as above โ use a migration to delete it; never just remove from code |
| Old field in existing configs must keep working | Write a migration that renames/transforms it. NEVER add backcompat shims in command code |
configVersion in a committed config | Never edit it manually; gw manages it automatically |
gw-config.schema.json diverges from Config | Fix immediately โ the schema is additionalProperties: false and IDE errors surface in every committed config |
The canonical migration guide is in the project root CLAUDE.md under
"Config Migration System". See also packages/gw-tool/src/lib/config-migrations.ts
(current version: CURRENT_CONFIG_VERSION = 2).
Rules
| Rule | Description |
|---|
| fundamentals | HIGH - Config file location, creation, and precedence |
| options-reference | HIGH - Complete reference for all config options |
| setup | HIGH - Initial setup flow, secrets, team onboarding |
| auto-copy | HIGH - File patterns to copy, what to include/exclude |
| team-config | MEDIUM - Sharing config, documentation, onboarding |
| advanced | LOW - Multiple sources, secret management integration |
| troubleshooting | HIGH - Common issues and solutions |
Complete Config Reference
{
"$schema": "https://raw.githubusercontent.com/mthines/gw-tools/main/packages/gw-tool/schemas/gw-config.schema.json",
"configVersion": 3,
"defaultBranch": "main",
"autoCopyFiles": [".env", ".env.local", "secrets/"],
"hooks": {
"checkout": {
"pre": ["echo 'Creating: {worktree}'"],
"post": ["cd {worktreePath} && pnpm install"],
},
},
"cleanThreshold": 7,
"autoClean": false,
"updateStrategy": "merge",
"protectedBranches": ["staging", "release/v2"],
}
Local overrides โ create .gw/config.local.json to override any field for your machine only.
It is gitignored automatically and shallow-merged on top of config.json (local wins).
Hook Variables
Available for substitution in any hook command string:
| Variable | Value |
|---|
{worktree} | Worktree name (e.g. feat/my-feature) |
{worktreePath} | Absolute path to the new worktree |
{gitRoot} | Absolute path to the bare git repository root |
{branch} | Branch name (same as worktree name for gw checkout) |
Example using variables:
{
"hooks": {
"checkout": {
"post": ["cd {worktreePath} && pnpm install", "echo 'Ready at {worktreePath}'"],
},
},
}
Adding a Migration (required when changing Config)
When any field in packages/gw-tool/src/lib/types.ts's Config interface is
added, renamed, or removed, follow this checklist โ see root CLAUDE.md for
the full authoritative process:
- Increment
CURRENT_CONFIG_VERSION in config-migrations.ts
- Add a migration entry to the
MIGRATIONS array that transforms old configs and sets config.configVersion = <new version>
- Update
types.ts to reflect the new shape
- Update
schemas/gw-config.schema.json โ add/remove/rename properties, update "default" on configVersion to the new version
- Remove any command-level backcompat code โ migrations own backwards compatibility
Migration skeleton:
{
version: 3,
description: 'Rename oldField to newField',
migrate: (config) => {
if (config.oldField !== undefined) {
config.newField = config.oldField;
delete config.oldField;
}
config.configVersion = 3;
return config;
},
}
Quick Command Reference
| Task | Command |
|---|
| Initialize config | gw init |
| Init with options | gw init --auto-copy-files .env,secrets/ --post-checkout "pnpm install" |
| Interactive setup | gw init --interactive |
| Clone and initialize | gw init git@github.com:user/repo.git |
| Show generated init command | gw show-init |
| Sync files to current worktree | gw sync |
| Sync to specific worktree | gw sync feat/branch |
| Sync specific files | gw sync feat/branch .env .env.local |
| Add file to autoCopyFiles (VS Code) | Command palette โ gw: Add to Auto-Copy Files, or right-click a file in the Explorer or editor tab. Supports multi-file selection. Requires .gw/config.json to exist (gw init first). |
Anti-Patterns
| Anti-pattern | Correct approach |
|---|
Adding a Config field without a migration | Always add a migration; bump CURRENT_CONFIG_VERSION |
| Handling an old field name in command code | Delete the handling; write a migration instead |
Editing configVersion in a config file by hand | Let gw manage it; never edit manually |
Updating types.ts without updating gw-config.schema.json | Both files must stay in sync โ the schema is additionalProperties: false |
Listing node_modules/ or dist/ in autoCopyFiles | Only list secrets and env files that won't regenerate |
Committing .gw/config.local.json | It is gitignored by design; keep machine-specific overrides out of version control |
Adding absolute paths to autoCopyFiles | Paths must be relative to the repo root |
Key Principles
- Set up secrets in
defaultBranch first โ source must exist before auto-copy works.
- Commit
config.json to version control โ team members get it automatically.
- Copy secrets, not dependencies โ
.env yes, node_modules/ no.
- Migrations own backwards compat โ never add shims in command code.
gw show-init documents your setup โ generates a shareable init command from current config.
Related Skills
Resources