No slash command · from programming-tasuke
Prefer yq over Python or ad-hoc text substitution for reading or transforming YAML, XML, TOML, and CSV. Assumes mikefarah/yq, whose syntax differs from the Python-based kislyuk/yq. Use when reading or rewriting configuration files in those formats from the command line.
Ships in programming-tasuke. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
YAMLやXMLやTOMLやCSVといった構造化データを読み取ったり変換したりする用事には、
yqを使ってください。
Pythonなどの汎用スクリプト言語や、
sedによる場当たり的なテキスト置換を持ち出さないでください。
JSONを扱う時はyqではなくjqを使ってください。
yqでもJSONは扱えますが、
形式ごとに道具を使い分けたほうが読み手に意図が伝わります。
programming-tasuke:prefer-jqスキルを参照してください。
汎用スクリプト言語は何でも出来てしまいます。
コマンドの実行を承認する人間は毎回スクリプトの中身を読んで安全性を判断しなければならず、
Bash(python:*)のような包括的な許可を出すことも危険です。
yqの出来ることはデータの変換にほぼ限られていて副作用が少ないため、
包括的な許可を出しやすく、
承認の手間が発生しません。
sedによる置換はYAMLの構造を理解しないため、
同じ名前のキーが別の階層にもある場合などに、
意図しない箇所まで書き換えてしまいます。
yqはパスを指定して構造として扱うのでその危険がありません。
インデントやアンカーの扱いを自前で組み立てるより、 yqに任せた方が短く書けて読みやすいという利点もあります。
yqという名前のコマンドには互換性のない2つの実装があります。
yq-go。このスキルはこちらを前提とします。yq。フィルタの構文はjqと同一です。構文が違うので、
書いたフィルタが構文エラーになった時は実装の違いを疑ってください。
yq --versionで判別できます。
mikefarah版はyq (https://github.com/mikefarah/yq/) version v4.53.2のように出力します。
読み取り。
yq '.services.web.image' compose.yaml
書き換え。
-iで入力ファイルを直接書き換えます。
コメントは保持されます。
yq -i '.version = "2"' compose.yaml
出力形式の変換は-oで指定します。
yq -o=json '.' compose.yaml
入力形式は既定ではautoで、
ファイルの拡張子から判別されます。
拡張子から判別できない入力を渡す時は-pで明示してください。
標準入力を渡す場合や、
.txtのように中身と一致しない拡張子のファイルを渡す場合が該当します。
判別できない入力は黙ってYAMLとして解釈されるため、
気付かないまま誤った結果を得ることがあります。
auto, yaml, kyaml, json, props, csv, tsv, xml, base64, uri, toml, hcl, lua, iniをサポートします。
yq -p=xml -o=yaml '.root.item' response.txt
出力形式も-oで明示してください。
出力形式の既定もautoですが、
こちらが見ているのは入力形式ではなく入力ファイルの拡張子で、
-pを付けても連動しません。
拡張子から判別できないままだと、
YAMLへ倒した旨の警告が出力されます。
リモートから取得したデータをcurlからyqへ直接パイプするのは避けてください。
一度ファイルへ保存して中身を確認してから処理してください。
想定と違う形式が返っていたり、
巨大なデータが返っていたりすることに気付けます。
シェルの値はフィルタへ文字列連結せずに、
環境変数を経由して渡します。
jqの--argに相当します。
version=2 yq -i '.version = strenv(version)' compose.yaml
複数のファイルやドキュメントを横断して処理する時はeval-allを使います。
yq eval-all '. as $item ireduce ({}; . * $item)' base.yaml override.yaml
autoですが、入力形式ではなく入力ファイルの拡張子から決まります。拡張子から判別できない場合はYAMLになります。JSONが欲しい時は-o=jsonを付けます。-o=jsonでは"a"のようにクォートが付きます。生の値が欲しい時は--unwrapScalarの短縮形である-rを明示してください。--argではなくenv(NAME)とstrenv(NAME)で参照します。-sはjqのslurpではなく--split-expで、式の評価結果を名前にしたファイルを生成します。入力をまとめたい時はeval-allや[...]を使ってください。リポジトリ内の設定ファイルを人間が読む前提で書き換える時は、
Editツールを優先してください。
差分が読みやすいためです。
yq -iは多数のファイルへ同じ変更を機械的に適用する場合などに使ってください。
以下の場合はPythonなどを使って構いません。
例外に当たる場合でも、 値を取り出す部分だけをyqへ切り出せるなら切り出してください。
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
9 skills in this plugin
/commandGuidelines for shell commands. Avoid `cat`, `find`, `grep`, `head`, and `tail`; prohibit `rm` (use `trash` instead). Use when invoking shell commands via Bash./comparison-operatorPrefer left-to-right ascending comparisons with less-than operators over greater-than operators, so values read in number-line order. Use when writing or reviewing comparison or range-check expressions./githubHow to access GitHub. Avoid direct URL fetches; prefer GitHub MCP tools or the `gh` CLI subcommands. Use when fetching GitHub information or operating on issues, pull requests, or workflows./naming-ruleGeneral naming rules across programming languages. Avoid meaningless words like `common` or `util`, and prefer singular base forms. Use when creating or reviewing names of files, directories, modules, functions, or variables./prefer-jqPrefer jq over Python or other general-purpose scripting languages for reading, filtering, or transforming JSON. Use when extracting values from JSON, parsing an API response, or writing anything that would otherwise reach for Python's json module or a `node -e` one-liner./sopsGuidelines for handling secrets encrypted with sops. Never let decrypted plaintext reach the conversation; let sops decrypt and pass secrets to other processes via `exec-env` or `exec-file` instead, and leave editing to the user. Use when a repository contains `.sops.yaml`, a `secrets/` directory, sops-encrypted YAML/JSON/dotenv files, or an `.envrc` that loads secrets via sops.npx claudepluginhub ncaq/konoka --plugin programming-tasuke