Date: 201809
Local time of day: 0601-1200
Location: ZZZ.Airport, US
Flight conditions: VMC
Aircraft: Medium Large Transport; Low Wing; 2 Turbojet Eng
Operator: Air Carrier
Operating under: Part 121
Flight plan: IFR
Flight phase: Climb
Airspace: Class B ZZZ
ATC / advisory: Tower ZZZ
Reporter organization: Air Carrier
Reporter function: Captain; Pilot Flying
Reporter qualification: Flight Crew Multiengine; Flight Crew Air Transport Pilot (ATP); Flight Crew Instrument
Human factors: Communication Breakdown
Second reporter function: Pilot Not Flying; First Officer
Anomaly: ATC Issue All Types; Deviation - Track / Heading All Types; Deviation / Discrepancy - Procedural Clearance; Deviation / Discrepancy - Procedural Published Material / Policy; Inflight Event / Encounter Weather / Turbulence
Detector: Person Air Traffic Control; Person Flight Crew
When detected: In-flight
Result: Air Traffic Control Issued New Clearance; Flight Crew Requested ATC Assistance / Clarification; Flight Crew Returned To Clearance
Contributing factors: Human Factors; Procedure; Weather
Primary problem: Human Factors

Narrative: On takeoff; plane in front of us asked for a right turn to a heading of 310 for weather 3 1/2 off the departure end. During initial climb; we asked for the same heading. Tower told us to turn. Then he realized that he had us confused with the airplane that had taken off in front of us and he wanted us on a heading of 210. It was impossible to turn to that heading by then because we would fly through the cell. The controller said that he had confused our flight with the other. He then asked us to stop the climb at 4;000 ft (instead of the usual 5;000 ft for the SID). He acknowledged that it was his mistake.From what I remembered; he was calling for moderate rain about 3 1/2 from the departure end; but our radar then showed extreme precipitation (and that is the reason for asking for the turn after airborne).Tower was handling 4 aircraft with similar callsigns. There was a little confusion on the ground with the tower as he was busy with the slow departure rate; spacing at different departure fixes and trying give taxi instructions for re-sequencing. Controller was busy dealing also with weather not only [on] departure end; but all around the departure corridor due to the remains of [a major storm] pushing through the area.We should have asked for more time on the ground asking for the deviation. The tower controller still handling the previous departure weather deviation; then he cleared us for takeoff and immediately cleared another plane into position on the runway at the same time. I should have asked the controller for a timeout; but us being time pressure to roll since the plane that was holding short had being given a position and hold clearance.I discussed with the FO (First Officer) later during the flight what had happened and I said to him that I should have not accepted the departure clearance since there was so much confusion on the radio and that I should have asked for a cancellation of the takeoff clearance until we could further discuss the weather at the end and what plan B was going to be. Since we were taxing opposite direction (parallel) to the takeoff runway; we had no clue that there was weather at the departure end until we received our line-up and wait and takeoff clearance.


Second narrative: We were number 1 for takeoff on RWY XXL and I was the PM (Pilot Monitoring). There was weather at the departure end of the runway and the previous aircraft requested and was approved for a heading of 300 to avoid the weather.We were cleared for takeoff and given a heading of 230 degrees. It was a normal takeoff and ATC gave instructions to the next aircraft to line up and wait. After we rotated through 4000 feet; the CA (Captain) told me to request a 300 heading for weather.I asked ATC; 'Can Aircraft X get a heading of 300 for weather as well?'ATC responded with 'That's fine; just maintain 4000 ft.'I was surprised he didn't say our callsign but I confirmed and said 'Ok; heading 300 and maintain 4000 feet for Aircraft X.'After we made the turn Tower came back and said 'Aircraft X; it's a heading of 230.'I responded with 'We asked for a 300 heading and you confirmed that we could fly that heading for weather.'Tower then responded and said 'Oh I thought I was talking to Aircraft Y behind you. Ok maintain 4000 and stay on that heading.' I don't think there was any loss of separation between any aircraft but it definitely surprised ATC that we made a 'wrong' turn. We got vectored back around the departure corridor and had an uneventful rest of the flight.There was a lot of traffic congestion; similar call signs and weather in the area. This caused a high workload for the controllers. We waited to request the heading until airborne when we should have requested it on the ground. This would have provided a clear and smooth request to ATC when we were the focal airplane on their screen. Waiting until shortly after takeoff proved to be too late. I also could have confirmed a second time that the 'that's fine...' comment was in fact for us since it was odd that Tower didn't use our callsign.Better planning on our part and anticipating a heading change after takeoff could have greatly reduced this issue. I should have been planning on weather avoidance right after takeoff and been listening into what other aircraft were doing on takeoff. This would have resulted in us requesting the heading prior to takeoff rather than after.Also; anytime there's a question as to who the clearance is for; you should always confirm with ATC. I used our full call sign in both the request and the confirmation of the heading and altitude but that still wasn't enough for ATC to catch the fact that they had given the clearance to the wrong airplane. Controllers are only human and mistakes happen so if it sounds like something may be wrong; it probably is.


Synopsis: Air Carrier flight crew reported a communication breakdown with ATC.