Add --update-cache option for Claude Code plugin development#82
Add --update-cache option for Claude Code plugin development#82thschaffr wants to merge 1 commit into
Conversation
…formats.py to refresh the local Claude Code plugin cache after a successful build.
After the normal build pipeline succeeds, --update-cache mirrors the
generated skills/software-security/ tree into:
~/.claude/plugins/cache/project-codeguard/codeguard-security/<version>/
skills/software-security/
so locally edited rules can be exercised in Claude Code immediately,
without waiting for a marketplace release.
Behavior:
- Off by default; no change to standard CI builds.
- Marketplace name (project-codeguard) and plugin name (codeguard-security)
match .claude-plugin/marketplace.json and .claude-plugin/plugin.json.
- Version is read from pyproject.toml via the existing helper and validated
against [A-Za-z0-9._-]+ before being spliced into a filesystem path
(defense-in-depth against path traversal).
- The versioned cache directory is fully replaced (rmtree of cache_base
followed by copytree) so stale rules from a previous build can't linger.
This is not atomic: there is a brief window where the directory is
missing or partially written. The flag is intended for dev use where
this is acceptable.
- All shutil operations are wrapped in try/except; failures exit non-zero
with a clear message.
No new dependencies; only stdlib (re, shutil, pathlib).
|
Thank you for looking into this. While reviewing, I noticed Claude Code has a flag for this. From the plugin docs: "Use the Since this repo is already a plugin ( uv run python src/convert_to_ide_formats.py
claude --plugin-dir .I tested it locally and edits to |
Hi Thomas, I will look into this. I remember having issues with ClaudeCode running in e.g. VSCode not being able to see new custom rule files. I saw that the model always referenced the cached version which was outdated. Therefore, I think it might not "just" be related to the SKILL.md file. I will double check it and get back to you. Thank you. |
Summary
This PR adds a
--update-cacheCLI option to the conversion script (src/convert_to_ide_formats.py) to streamline custom rule development for Claude Code environments. The flag is purely additive — it extends the existing converter; no other entry point or script is introduced.Problem
When developing or customizing CodeGuard rules for Claude Code, users face workflow friction:
skills/software-security/— The conversion script outputs Claude Code rules to the project'sskills/directory~/.claude/plugins/cache/project-codeguard/codeguard-security/{version}/skills/software-security/Solution
Extend the conversion script (
src/convert_to_ide_formats.py) with an opt-in--update-cacheflag that automatically syncs the just-generated rules to Claude Code's local plugin cache directory at the end of a successful conversion run. Off by default — no impact on standard CI builds or contributor workflow when the flag is not passed.Changes
All changes are scoped to
src/convert_to_ide_formats.py(the existing conversion script). No new scripts, modules, or dependencies are introduced.update_claude_cache(version)function tosrc/convert_to_ide_formats.pyto sync rules to the Claude Code plugin cache--update-cacheCLI flag to the same script's argparse setup, triggering the sync after a successful conversionpyproject.tomlvia the existingget_version_from_pyproject()helper and passed through toupdate_claude_cache()project-codeguard) and plugin name (codeguard-security) are pinned in the function to match.claude-plugin/marketplace.jsonand.claude-plugin/plugin.json[A-Za-z0-9._-]+allow-list before splicing into a filesystem path (defense-in-depth against path traversal)rmtreeofcache_base, thencopytree) so stale rules from a previous build can't linger. Note: this is not atomic — there is a brief window where the cache directory is missing or partially written; the flag is intended for dev use where this is acceptableshutiloperations intry/except; failures exit non-zero with a clear messageSKILL.mdwere actually copied before returning successNo new dependencies; only stdlib (
re,shutil,pathlib).Usage
Note: The
--sourceflag accepts multiple directories undersources/rules/. In the last example,customrefers to a hypotheticalsources/rules/custom/directory — this does not exist by default in the repository. Users can create their own source directories (e.g.,sources/rules/internal/) to organize organization-specific rules alongside the core rules.Use Cases
agentskills.pyor theSKILL.mdtemplateTest Plan
--update-cacheflag~/.claude/plugins/cache/project-codeguard/codeguard-security/{version}/skills/software-security/(tested with isolated$HOME: 23 rules +SKILL.mdcopied)--helpdocuments the new flag clearly