modscode EN

modscode / コード参考書 / プロンプトを書き換える

プロンプトを書き換える(prompt.submit)

prompt.submit は、ターンが始まる前に打った文(e.text)を受けます。書き換えるなら next({ ...e, text })、Claude だけが読む文を足すなら context に足して next、送らずに止めるなら { drop: '理由' } を返します。settings.json の UserPromptSubmit に当たります。

on('prompt.submit')next({ ...e, text })context{ drop: '…' }

最小の形

hooks/register.js
export function register(on) {
  on('prompt.submit', async ($, e, next) => {
    // rewrite what was typed
    const text = e.text.replace(/\bpls\b/g, 'please')
    // and add a line only Claude reads
    if (/\btest/i.test(text)) return next({ ...e, text, context: [...(e.context ?? []), 'Run the tests with: npm test'] })
    return next({ ...e, text })
  })
}

modscode が公式ドキュメントの API で書いた最小の例です。自由に使えます。

実際の Mod のコード(6 本)

GitHub の公開 Mod から、図鑑が読んだコミットの該当行をそのまま引いています。見出しから Mod のページ(何をするか・良いところ・画面・コードが触るもの)へ、ファイル名から GitHub の該当行へ移れます。

写す前・入れる前に、必ず自分でコードを確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode は中身の安全を保証しません。

pii-guard pii-guard-tw · フックだけ · ★ 247

De-identifies personal data before it reaches the model and restores it on the way back out, by asking the resident pii-guard hookd service on loopback. Tool results are redacted, writes and shell commands are restored, a prompt's @ refere…

on('prompt.submit', async ($, e, next) => {
  let text = e.text
  try {
    const reply = await ask($, settings, 'PromptSubmit', { prompt: e.text, cwd: await $.session.cwd() })
    if (typeof reply['text'] === 'string') text = reply['text']
  } catch {
    return { drop: DROP_OFFLINE }
  }
  // The session briefing rides the first prompt: session.start's own result
  // is echoed by core and cannot put anything in front of the model.
  const extra = briefed ? [] : briefing ? [briefing] : []
  briefed = true
  return next({ ...e, text, context: [...(e.context ?? []), ...extra] })
}).catch(() => ({ drop: DROP_OFFLINE }))

MIT ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面

ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 Dustin Yuchen Teng

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

lane-stack VKirill · ターミナル+デスクトップ · ★ 121

Solo PM conveyor for Claude Code: orchestrator agents, lane playbooks, onboard and resume commands.

on('prompt.submit', async ($, e, next) => {
  if (e.text.trim().length < 12) return next(e)
  const where = await whereami($)
  const res = await post($, `${base}/hook/user-prompt-submit`, {
    hook_event_name: 'UserPromptSubmit',
    source: 'function-hook',
    ...where,
    prompt: e.text,
  })
  if (typeof res?.output?.systemMessage === 'string') $.ui.toast(res.output.systemMessage)
  const extra = res?.output?.hookSpecificOutput?.additionalContext
  if (typeof extra !== 'string' || extra === '') return next(e)
  return next({ ...e, context: [...(e.context ?? []), extra] })
})

MIT ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面

ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 VKirill and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

homie-persona-cognition TheSmokeDev · フックだけ · ★ 26

Host-bound cognitive lifecycle events for The Homie.

on('prompt.submit', async ($, e, next) => {
  const result = await next(e)
  if (result.drop !== undefined) return result
  const python = await $.env.get('HOMIE_COGNITION_HOOK_PYTHON')
  const command = await $.env.get('HOMIE_COGNITION_HOOK_COMMAND')
  if (python && command) {
    const receipt = await $.process.run([python, command], { stdin: JSON.stringify({ event: 'prompt.submit', event_id: e.turnId ?? 'prompt' }), timeoutMs: 8000 })
    if (receipt.exitCode === 0) {
      const value = JSON.parse(receipt.stdout)
      if (typeof value.context === 'string' && value.context) return { ...result, context: [...(result.context ?? []), value.context] }
    }
  }
  return result
})

MIT ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面

ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 The Homie Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

winnow Ghaleb Dweikat · ターミナル+デスクトップ · ★ 102

A calibrated context sieve for Claude Code. Every large tool result is judged by a System One model before it enters context; irrelevant blocks are replaced with a summary and a recall key.

on('prompt.submit', async ($, e, next) => {
  if (e.text.trim().length < 12 || link.quiet()) return next(e)
  const res = await ask($, link, '/hook/user-prompt-submit', {
    hook_event_name: 'UserPromptSubmit',
    source: 'function-hook',
    ...(await whereami($)),
    prompt: e.text,
  })
  if (typeof res?.output?.systemMessage === 'string') $.ui.toast(res.output.systemMessage)
  const extra = res?.output?.hookSpecificOutput?.additionalContext
  if (typeof extra !== 'string' || extra === '') return next(e)
  return next({ ...e, context: [...(e.context ?? []), extra] })
})

MIT ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面

ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 Ghaleb Dweikat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

transcripted-live Transcripted · ターミナル+デスクトップ · ★ 74

The meeting Transcripted is recording, inside Claude Code: Claude gets the call as context, a live dashboard (now, asked of you, action items), prompt suggestions for questions aimed at you, and an after-call wrap-up that gains speaker nam…

on('prompt.submit', async ($, e, next) => {
  if (!s.isAutoContext || !CONTEXT_ORIGINS.has(e.origin.kind)) return next(e)
  await poll($, s)
  const block = newContext(s, Date.now())
  if (!block) return next(e)
  return next({ ...e, context: [...(e.context ?? []), block.text] }).then(result => {
    // Only count it as sent once the prompt actually entered.
    if (!('drop' in result && result.drop)) {
      block.commit()
      void $.state.set(SENT_REF, { ...s.sentUpTo }).catch(() => undefined)
      void $.state.set(SENT_KEYS_REF, { notes: s.sentNotesKey, wrap: s.sentWrapKey }).catch(() => undefined)
    }
    return result
  })
})

MIT ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面

ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 r3dbars

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

session-inbox petekp · ターミナル+デスクトップ · ★ 47

Collects what is waiting on you in a session: questions, Claude's notes and PR reviews

on('prompt.submit', async ($, e, next) => {
  if (!isOn) return next(e)
  const origin = e.origin
  // send() already recorded this mod's own prompts.
  if (origin.kind === 'plugin' && origin.name === 'session-inbox') return next(e)
  // The person's own words: typed, or sent as theirs by another plugin.
  const isPersonsWords = origin.kind === 'composer' || origin.kind === 'bridge' || (origin.kind === 'plugin' && origin.asUser === true)
  if (!isPersonsWords) {
    if (!e.turnId) trigger = origin.kind

    return next(e)
  }

  const notes = await notePrompt($, e.text, null)

  return notes.length === 0 ? next(e) : next({ ...e, context: [...(e.context ?? []), ...notes] })
})

MIT ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面

ライセンスの全文(MIT)
MIT License

Copyright (c) 2024 Pete Petrash

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

作り始める

フォルダーに .claude-plugin/plugin.json({"name": "my-mod"})と hooks/hooks.json({"modules": ["register.js"]})を置き、上のコードを hooks/register.js に保存して、claude --plugin-dir . で 1 セッションだけ読み込みます。claude plugin validate . で、フックするイベントと呼ぶ API の一覧が出ます。

ほかのパターン