How do I migrate a v3 hook to v4?

Hi there

I am in the middle of migrating a strapi v3 project to v4, but currently stuck at migrating a hook. I could not find any mention of v3-hooks in the migration guide and also the new Hook API does not help.

Anyone know how to accomplish this?

I’d like to have the same functionality in the v4 version, this is the current v3 state:

// hooks/strapi-hook-foo/index.js
module.exports = strapi => {
  const hook = {
    defaults: {},
    async initialize() {
      // await someAsyncCode()
      // const settings = {...this.defaults, ...strapi.config.hook.settings.**};
  return hook;

// config/hook.js
module.exports = {
  settings: {
    foo: {
      enabled: true,
      timeout: 3000,

Any help is appreciated.


hey @yes_nik

Did you finally solved this somehow?

I am trying to create a custom hook in strapi v4 and it does not get initialized, despite I am using the same structure as you.


Hi @yes_nik && @sauldeleon

I’m trying to migrate to v4 but there is not even a single word about hooks in the migration docs
did you finally solve it? Any tips on how to do it?


Hello all, sorry it took so long for us to see this one. You are correct in that hooks don’t have a direct replacement in Strapi v4 (largely because they weren’t used all often).

Generally speaking, hook packages should instead be converted into a plugin and the way you would interface with the hooks functions would be through strapi.plugin('plugin-name')...

So for example in the users-permissions plugin we can navigate down to the services here and call them from anywhere (I’m using the yarn strapi console here to explore the internal API


From the above we can see the various parts of the plugin, here what we care about is services, so we will list the services to see what exists:

And in my example I want to use the count function:


A similar example would be to build your plugin in such a way it registers getters, setters, functions, and other API methods on the global internal API such as in my own personal plugin for Redis support in Strapi:

In this plugin, I’m checking the plugin config and dynamically registering Redis clients per config option. I do this in the main bootstrap but it calls a local plugin service


The actual service that registers the Redis clients on the global API: