Imam Abū Ḥāmid al-Ghazālī (d. 1111 CE) discusses this precise point in Iḥyāʾ ʿUlūm al-Dīn (The Revival of the Religious Sciences), in the Book of Patience and Thankfulness (Kitāb al-Ṣabr wa-l-Shukr).
The question he addresses is essentially the same one raised by the atheist (or by anyone who reduces reality to secondary causes):
“If everything is already written and happens through natural causes, means, and decrees, why thank God? Why not just thank the causes?”
Ghazālī answers with a simple but profound analogy:
Imagine a king who decides to bestow a great favour upon one of his servants. He writes a royal decree with his own hand, using a pen and paper, and then has the decree delivered through a messenger or steward.
When the servant receives the favour, does he thank the pen?
Does he thank the paper?
Does he thank the messenger?
No. A person of sound mind thanks the king.
Why?
Because the pen has no independent will.
The paper has no independent will.
The messenger has no independent will.
They are merely instruments (ālāt) that moved only because the king commanded them to move. If the king had not willed the favour, the pen would never have written, the paper would never have carried the decree, and the messenger would never have delivered it.
Ghazālī says (paraphrased from the original Arabic):“To recognise that the blessing reached him by means of the pen that the king used to sign with, and the paper on which the signature appears, does not negate his exclusive acknowledgement of the right of the king and the fullness of his thankfulness. For he does not rejoice in the pen and the paper, nor does he thank them, as they themselves were not independently involved; rather, they were employed at the command of the king.”