When to play h5 (or h4 with white) in fianchettoed position for black Imagine that we have this game
[FEN &quot; &quot;]
1.e4 c5 2. b4 cxb4 3. a3 bxa3 4. Bxa3 Nc6 5. Nf3 g6 6. d4 Bg7 7. h4 

Do you play with Black in this case h5 or not? In my opinion, I rarely like to play h5 because it gives up the g5 square and white can plant his knight there. On the other hand, I feel like I stopped a barbaric attack temporarily. I would like to get some feedback about in which cases you think playing h5 is good defensively, and when it's bad and a concession. Not necessarily for the opening that I have mentioned above. Just in general.
I generally don't like accepting gambits as black on principle, so the position on your diagram feels already rather uncomfortable to me, but in general, there are a few typical ways to deal with h4-h5 if you have played g6 and your opponent replied with h4.

just ignore it; might be ok if you haven't castle yet. There, you're not afraid of hg hg, Rxh8 Bxh8, but you have to consider the consequences of h5-h6 harassing your bishop. You don't  usually want to play Bf8, as well as Rg8 vacating the h8 square, so you probably have to prepare Bf6 (if you can). Of more or less recent games, I saw it here: https://www.chessgames.com/perl/chessgame?gid=1926269. There is another line in Gruenfeld where black is doing this, but sorry, can't recall it now. Check Peter Svidler games w/ black if you're interested.
Indeed play h5, as you mentioned; I'd say the main danger here is not the g5 square per se (although it is also important) but whether white can play g2-g4 later, opening the files. So it depends on how strong you grip on the g4 square is. Sometimes white has already committed to f2-f4, and then I'd consider h7-h5 more seriously. Black does play this in dragon sometimes, thanks to his control of g4 with N on f6 and B on c8/d7.
just put a knight on f6 and take the pawn on h5. Depends whether white can easily chase this knight with e4-e5, so in this particular variation it is probably not so great. Also in Gruenfeld, after smth like 1. d4 Nf6 2. c4 g6 3. h4 Bg7 4. Nc3 d5 5. h5 black plays Nxh5, there was a Grischuk-Nepo game also from 2019 I suppose.
Another rather robust structure arises after h4 Bg4, h5 gxh5. If white knight is already on f3, it might be not so easy for him to get rid of the g4 bishop. Not an option here obviously. Can't think of an example to this unfortunately. If I remember the game I'll update it.
A more conservative way is probably to play h6, and meet h5 with g5. I have seen this in closed sicilian (or english with 1. c4 e5 with colors reversed); can't think of a top-level game, but this should do https://www.chessgames.com/perl/chessgame?gid=1214057. The danger here lies in the f4 attack or piece sac on g5, yet the latter is probably harmless if you haven't castled yet. In this particular variation I'd consider this to be my main idea as black. The downside of playing h6 might be that if white has a battery on the diagonal, for example, Be3 and Qd2, you could have trouble castling unless you play Ng4, so it is again important to control the g4 square.

In any of those options, if you give white enough time, he will break through whatever you choose, so you probably should aim not at closing the king side and stopping white's attack there forever but rather buying yourself a bit of time to prepare the counterattack in the center.